From 4d1c53384b751e39e8f5c9d3c512adedca552fdf Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 29 Apr 2024 19:28:54 +0800 Subject: refactor: prompts for generating config file (#463) --- src/client/openai_compatible.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/client/openai_compatible.rs') diff --git a/src/client/openai_compatible.rs b/src/client/openai_compatible.rs index 304e748..ba3a751 100644 --- a/src/client/openai_compatible.rs +++ b/src/client/openai_compatible.rs @@ -10,7 +10,7 @@ use serde::Deserialize; #[derive(Debug, Clone, Deserialize)] pub struct OpenAICompatibleConfig { pub name: Option, - pub api_base: String, + pub api_base: Option, pub api_key: Option, pub chat_endpoint: Option, pub models: Vec, @@ -18,6 +18,7 @@ pub struct OpenAICompatibleConfig { } impl OpenAICompatibleClient { + config_get_fn!(api_base, get_api_base); config_get_fn!(api_key, get_api_key); pub const PROMPTS: [PromptType<'static>; 5] = [ @@ -34,6 +35,7 @@ impl OpenAICompatibleClient { ]; fn request_builder(&self, client: &ReqwestClient, data: SendData) -> Result { + let api_base = self.get_api_base()?; let api_key = self.get_api_key().ok(); let mut body = openai_build_body(data, &self.model); @@ -45,7 +47,7 @@ impl OpenAICompatibleClient { .as_deref() .unwrap_or("/chat/completions"); - let url = format!("{}{chat_endpoint}", self.config.api_base); + let url = format!("{api_base}{chat_endpoint}"); debug!("OpenAICompatible Request: {url} {body}"); -- cgit v1.2.3