Skip to main content

zai_rs/knowledge/
retrieve.rs

1use super::types::KnowledgeGetResponse;
2use crate::client::ZaiClient;
3
4/// Knowledge detail request (GET /llm-application/open/knowledge/{id})
5///
6/// Credentials and transport live on the [`ZaiClient`], passed to
7/// [`send_via`](Self::send_via).
8pub struct KnowledgeGetRequest {
9    id: String,
10}
11
12impl KnowledgeGetRequest {
13    /// Build a retrieve request with id.
14    pub fn new(id: impl Into<String>) -> Self {
15        Self { id: id.into() }
16    }
17
18    /// Send via a [`ZaiClient`] and parse the typed response.
19    pub async fn send_via(&self, client: &ZaiClient) -> crate::ZaiResult<KnowledgeGetResponse> {
20        crate::client::validation::require_non_blank(&self.id, "knowledge_id")?;
21        let route = crate::client::routes::KNOWLEDGE_GET;
22        let url = client.endpoints().resolve_route(route, &[&self.id])?;
23        client
24            .send_empty::<KnowledgeGetResponse>(route.method(), url)
25            .await
26    }
27}