zai_rs/model/async_chat_get/
data.rs

1use super::super::traits::*;
2use crate::client::http::HttpClient;
3use std::marker::PhantomData;
4pub struct AsyncChatGetRequest<N>
5where
6    N: ModelName + AsyncChat,
7{
8    pub key: String,
9    url: String,
10    // Empty body placeholder to satisfy HttpClient::Body
11    _body: (),
12    // Phantom placeholder to carry generic N for compile-time constraints
13    _marker: PhantomData<N>,
14}
15
16impl<N> AsyncChatGetRequest<N>
17where
18    N: ModelName + AsyncChat,
19{
20    pub fn new(_model: N, task_id: String, key: String) -> Self {
21        let url = format!(
22            "https://open.bigmodel.cn/api/paas/v4/async-result/{}",
23            task_id
24        );
25        Self {
26            key,
27            url,
28            _body: (),
29            _marker: PhantomData,
30        }
31    }
32
33    pub fn validate(&self) -> anyhow::Result<()> {
34        if self.url.trim().is_empty() {
35            return Err(anyhow::anyhow!("empty URL"));
36        }
37        Ok(())
38    }
39
40    pub async fn send(
41        &self,
42    ) -> anyhow::Result<crate::model::chat_base_response::ChatCompletionResponse> {
43        self.validate()?;
44        let resp = self.get().await?;
45        let parsed = resp
46            .json::<crate::model::chat_base_response::ChatCompletionResponse>()
47            .await?;
48        Ok(parsed)
49    }
50}
51
52impl<N> HttpClient for AsyncChatGetRequest<N>
53where
54    N: ModelName + AsyncChat,
55{
56    type Body = ();
57    type ApiUrl = String;
58    type ApiKey = String;
59
60    fn api_url(&self) -> &Self::ApiUrl {
61        &self.url
62    }
63
64    fn api_key(&self) -> &Self::ApiKey {
65        &self.key
66    }
67
68    fn body(&self) -> &Self::Body {
69        &self._body
70    }
71}