From 93c87933443832b84268ad8410d611cfb0a76deb Mon Sep 17 00:00:00 2001 From: neo <1100909+neowu@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:37:36 +0800 Subject: [PATCH] tweak complete --- src/azure/chatgpt.rs | 2 +- src/command/chat.rs | 3 +-- src/command/complete.rs | 18 ++++++++++++++---- src/gcloud/gemini.rs | 3 +++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/azure/chatgpt.rs b/src/azure/chatgpt.rs index 716638c..936383a 100644 --- a/src/azure/chatgpt.rs +++ b/src/azure/chatgpt.rs @@ -168,7 +168,7 @@ impl ChatGPT { // stream_options: Some(StreamOptions { include_usage: true }), stream_options: None, stop: None, - max_tokens: 800, + max_tokens: 4096, presence_penalty: 0.0, frequency_penalty: 0.0, tool_choice: self.tools.is_some().then_some("auto".to_string()), diff --git a/src/command/chat.rs b/src/command/chat.rs index 630b9f9..5ca9e9b 100644 --- a/src/command/chat.rs +++ b/src/command/chat.rs @@ -1,4 +1,3 @@ -use std::io; use std::io::Write; use std::mem; use std::path::PathBuf; @@ -74,6 +73,6 @@ impl Chat { fn print_flush(message: &str) -> Result<(), Exception> { print!("{message}"); - io::stdout().flush()?; + std::io::stdout().flush()?; Ok(()) } diff --git a/src/command/complete.rs b/src/command/complete.rs index 849a65f..52eba4a 100644 --- a/src/command/complete.rs +++ b/src/command/complete.rs @@ -70,15 +70,25 @@ impl Complete { return Err(Exception::ValidationError("system message must be at first".to_string())); } on_system_message = true; - } else if line.starts_with("---") || line.starts_with("# file: ") { + } else if line.starts_with("# prompt") { if on_system_message { info!("system message: {}", message); model.system_message(message); message = String::new(); on_system_message = false; } - if line.starts_with("# file: ") { - let file = PathBuf::from(line.strip_prefix("# file: ").unwrap().to_string()); + } else if line.starts_with("# anwser") { + break; + } else if line.starts_with("> file: ") { + let file = self.prompt.with_file_name(line.strip_prefix("> file: ").unwrap()); + let extension = file + .extension() + .ok_or_else(|| Exception::ValidationError(format!("file must have extension, path={}", file.to_string_lossy())))? + .to_str() + .unwrap(); + if extension == "txt" { + message.push_str(&fs::read_to_string(file).await?) + } else { info!("file: {}", file.to_string_lossy()); files.push(file); } @@ -93,7 +103,7 @@ impl Complete { let message = model.chat(message, files).await?; let mut prompt = fs::OpenOptions::new().append(true).open(&self.prompt).await?; - prompt.write_all(b"\n---\n\n").await?; + prompt.write_all(format!("\n# anwser ({})\n\n", self.name).as_bytes()).await?; prompt.write_all(message.as_bytes()).await?; Ok(()) diff --git a/src/gcloud/gemini.rs b/src/gcloud/gemini.rs index 547fb22..5389844 100644 --- a/src/gcloud/gemini.rs +++ b/src/gcloud/gemini.rs @@ -61,6 +61,9 @@ impl Gemini { pub async fn chat(&mut self, message: String, files: Option>) -> Result { let data = inline_datas(files).await?; + if data.is_some() { + self.tools = None; // function call is not supported with inline data + } self.add_message(Content::new_user_text(message, data)); let mut result = self.process().await?;