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/common.rs | |
| parent | a21e1213ccdd11d76f6338436c431e459ab8e574 (diff) | |
| download | aichat-740ca2413a1992d151c0a9ea62c12e69321c0973.tar.gz | |
refactor: simplify impl client trait (#445)
Diffstat (limited to 'src/client/common.rs')
| -rw-r--r-- | src/client/common.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/client/common.rs b/src/client/common.rs index 55e7b62..4509805 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -139,7 +139,6 @@ macro_rules! openai_compatible_module { use $crate::utils::PromptKind; use anyhow::Result; - use async_trait::async_trait; use reqwest::{Client as ReqwestClient, RequestBuilder}; use serde::Deserialize; @@ -154,7 +153,12 @@ macro_rules! openai_compatible_module { pub extra: Option<ExtraConfig>, } - openai_compatible_client!($client); + impl_client_trait!( + $client, + $crate::client::openai::openai_send_message, + $crate::client::openai::openai_send_message_streaming + ); + impl $client { list_models_fn!( @@ -218,9 +222,9 @@ macro_rules! client_common_fns { } #[macro_export] -macro_rules! openai_compatible_client { - ($client:ident) => { - #[async_trait] +macro_rules! impl_client_trait { + ($client:ident, $send_message:path, $send_message_streaming:path) => { + #[async_trait::async_trait] impl $crate::client::Client for $crate::client::$client { client_common_fns!(); @@ -230,7 +234,7 @@ macro_rules! openai_compatible_client { data: $crate::client::SendData, ) -> anyhow::Result<String> { let builder = self.request_builder(client, data)?; - $crate::client::openai::openai_send_message(builder).await + $send_message(builder).await } async fn send_message_streaming_inner( @@ -240,7 +244,7 @@ macro_rules! openai_compatible_client { data: $crate::client::SendData, ) -> Result<()> { let builder = self.request_builder(client, data)?; - $crate::client::openai::openai_send_message_streaming(builder, handler).await + $send_message_streaming(builder, handler).await } } }; |
