From da3c541b681b140feb52b4297167ca233535fa90 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 1 Nov 2023 15:01:50 +0800 Subject: refactor: add/use openai_compatible_client macro --- src/client/localai.rs | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'src/client/localai.rs') diff --git a/src/client/localai.rs b/src/client/localai.rs index 131d92b..291fc96 100644 --- a/src/client/localai.rs +++ b/src/client/localai.rs @@ -1,14 +1,10 @@ -use super::openai::{openai_build_body, openai_send_message, openai_send_message_streaming}; -use super::{Client, ExtraConfig, LocalAIClient, ModelInfo, PromptKind, PromptType, SendData}; - -use crate::config::SharedConfig; -use crate::repl::ReplyStreamHandler; +use super::openai::openai_build_body; +use super::{ExtraConfig, LocalAIClient, ModelInfo, PromptKind, PromptType, SendData}; use anyhow::Result; use async_trait::async_trait; use reqwest::{Client as ReqwestClient, RequestBuilder}; use serde::Deserialize; -use std::env; #[derive(Debug, Clone, Deserialize)] pub struct LocalAIConfig { @@ -26,27 +22,7 @@ pub struct LocalAIModel { max_tokens: Option, } -#[async_trait] -impl Client for LocalAIClient { - fn config(&self) -> (&SharedConfig, &Option) { - (&self.global_config, &self.config.extra) - } - - async fn send_message_inner(&self, client: &ReqwestClient, data: SendData) -> Result { - let builder = self.request_builder(client, data)?; - openai_send_message(builder).await - } - - async fn send_message_streaming_inner( - &self, - client: &ReqwestClient, - handler: &mut ReplyStreamHandler, - data: SendData, - ) -> Result<()> { - let builder = self.request_builder(client, data)?; - openai_send_message_streaming(builder, handler).await - } -} +openai_compatible_client!(LocalAIClient); impl LocalAIClient { config_get_fn!(api_key, get_api_key); -- cgit v1.2.3