zai_rs/knowledge/
document_reembedding.rs1use std::collections::BTreeMap;
2
3use crate::client::http::HttpClient;
4use serde::{Deserialize, Serialize};
5use validator::Validate;
6
7#[derive(Debug, Clone, Serialize, Deserialize, Validate, Default)]
9pub struct DocumentReembeddingBody {
10 #[serde(skip_serializing_if = "Option::is_none")]
12 #[validate(url)]
13 pub callback_url: Option<String>,
14 #[serde(skip_serializing_if = "Option::is_none")]
16 pub callback_header: Option<BTreeMap<String, String>>,
17}
18
19pub struct DocumentReembeddingRequest {
21 pub key: String,
23 url: String,
24 body: DocumentReembeddingBody,
25}
26
27impl DocumentReembeddingRequest {
28 pub fn new(key: String, document_id: impl AsRef<str>) -> Self {
30 let url = format!(
31 "https://open.bigmodel.cn/api/llm-application/open/document/embedding/{}",
32 document_id.as_ref()
33 );
34 Self {
35 key,
36 url,
37 body: DocumentReembeddingBody::default(),
38 }
39 }
40
41 pub fn with_callback_url(mut self, url: impl Into<String>) -> Self {
43 self.body.callback_url = Some(url.into());
44 self
45 }
46
47 pub fn with_callback_header(mut self, hdr: BTreeMap<String, String>) -> Self {
49 self.body.callback_header = Some(hdr);
50 self
51 }
52
53 pub async fn send(&self) -> anyhow::Result<DocumentReembeddingResponse> {
55 self.body.validate()?;
57 let resp = self.post().await?;
58 let parsed = resp.json::<DocumentReembeddingResponse>().await?;
59 Ok(parsed)
60 }
61}
62
63impl HttpClient for DocumentReembeddingRequest {
64 type Body = DocumentReembeddingBody;
65 type ApiUrl = String;
66 type ApiKey = String;
67
68 fn api_url(&self) -> &Self::ApiUrl {
69 &self.url
70 }
71 fn api_key(&self) -> &Self::ApiKey {
72 &self.key
73 }
74 fn body(&self) -> &Self::Body {
75 &self.body
76 }
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
81pub struct DocumentReembeddingResponse {
82 #[serde(skip_serializing_if = "Option::is_none")]
83 pub code: Option<i64>,
84 #[serde(skip_serializing_if = "Option::is_none")]
85 pub message: Option<String>,
86 #[serde(skip_serializing_if = "Option::is_none")]
87 pub timestamp: Option<u64>,
88}