From 740ca2413a1992d151c0a9ea62c12e69321c0973 Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 26 Apr 2024 07:43:35 +0800 Subject: refactor: simplify impl client trait (#445) --- src/client/qianwen.rs | 56 +++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src/client/qianwen.rs') 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, } -#[async_trait] -impl Client for QianwenClient { - client_common_fns!(); - - async fn send_message_inner( - &self, - client: &ReqwestClient, - 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(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 { } 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 { + 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 + } +} -- cgit v1.2.3