diff options
| author | sigoden <sigoden@gmail.com> | 2024-04-26 07:43:35 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-26 07:43:35 +0800 |
| commit | 740ca2413a1992d151c0a9ea62c12e69321c0973 (patch) | |
| tree | ccacd2fd5789064c091b212f26f3c46561f71f69 /src/client/qianwen.rs | |
| parent | a21e1213ccdd11d76f6338436c431e459ab8e574 (diff) | |
| download | aichat-740ca2413a1992d151c0a9ea62c12e69321c0973.tar.gz | |
refactor: simplify impl client trait (#445)
Diffstat (limited to 'src/client/qianwen.rs')
| -rw-r--r-- | src/client/qianwen.rs | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/client/qianwen.rs b/src/client/qianwen.rs index 68e3666..386716f 100644 --- a/src/client/qianwen.rs +++ b/src/client/qianwen.rs @@ -33,34 +33,6 @@ pub struct QianwenConfig { pub extra: Option<ExtraConfig>, } -#[async_trait] -impl Client for QianwenClient { - client_common_fns!(); - - async fn send_message_inner( - &self, - client: &ReqwestClient, - mut data: SendData, - ) -> Result<String> { - let api_key = self.get_api_key()?; - patch_messages(&self.model.name, &api_key, &mut data.messages).await?; - let builder = self.request_builder(client, data)?; - send_message(builder, self.is_vl()).await - } - - async fn send_message_streaming_inner( - &self, - client: &ReqwestClient, - handler: &mut ReplyHandler, - mut data: SendData, - ) -> Result<()> { - let api_key = self.get_api_key()?; - patch_messages(&self.model.name, &api_key, &mut data.messages).await?; - let builder = self.request_builder(client, data)?; - send_message_streaming(builder, handler, self.is_vl()).await - } -} - impl QianwenClient { list_models_fn!( QianwenConfig, @@ -324,3 +296,31 @@ async fn upload(model: &str, api_key: &str, url: &str) -> Result<String> { } Ok(format!("oss://{key}")) } + +#[async_trait] +impl Client for QianwenClient { + client_common_fns!(); + + async fn send_message_inner( + &self, + client: &ReqwestClient, + mut data: SendData, + ) -> Result<String> { + let api_key = self.get_api_key()?; + patch_messages(&self.model.name, &api_key, &mut data.messages).await?; + let builder = self.request_builder(client, data)?; + send_message(builder, self.is_vl()).await + } + + async fn send_message_streaming_inner( + &self, + client: &ReqwestClient, + handler: &mut ReplyHandler, + mut data: SendData, + ) -> Result<()> { + let api_key = self.get_api_key()?; + patch_messages(&self.model.name, &api_key, &mut data.messages).await?; + let builder = self.request_builder(client, data)?; + send_message_streaming(builder, handler, self.is_vl()).await + } +} |
