From 0ebc7955da67b488877cab7929019d40688fb3ed Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 25 Mar 2024 11:13:54 +0800 Subject: refactor: improve creating config for openai-compatible client (#374) --- src/client/common.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/client/common.rs') diff --git a/src/client/common.rs b/src/client/common.rs index c35ba1b..4acc707 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -104,7 +104,7 @@ macro_rules! register_client { vec![$($client::NAME,)+] } - pub fn create_client_config(client: &str) -> anyhow::Result { + pub fn create_client_config(client: &str) -> anyhow::Result<(String, serde_json::Value)> { $( if client == $client::NAME { return create_config(&$client::PROMPTS, $client::NAME) @@ -310,15 +310,19 @@ pub struct SendData { pub type PromptType<'a> = (&'a str, &'a str, bool, PromptKind); -pub fn create_config(list: &[PromptType], client: &str) -> Result { +pub fn create_config(list: &[PromptType], client: &str) -> Result<(String, Value)> { let mut config = json!({ "type": client, }); + let mut model = client.to_string(); for (path, desc, required, kind) in list { match kind { PromptKind::String => { let value = prompt_input_string(desc, *required)?; set_config_value(&mut config, path, kind, &value); + if *path == "name" { + model = value; + } } PromptKind::Integer => { let value = prompt_input_integer(desc, *required)?; @@ -328,7 +332,7 @@ pub fn create_config(list: &[PromptType], client: &str) -> Result { } let clients = json!(vec![config]); - Ok(clients) + Ok((model, clients)) } #[allow(unused)] -- cgit v1.2.3