diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-06 06:23:54 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-06 06:23:54 +0800 |
| commit | 5635ca6a58fb4a590419335b098b7317285bfb82 (patch) | |
| tree | 84277c5f08ca25bb6111db13aa3be81e38b73be2 /src | |
| parent | 93ef6da6298f3a98127ed572659b6c24a3f5295e (diff) | |
| download | aichat-5635ca6a58fb4a590419335b098b7317285bfb82.tar.gz | |
refactor: warning model or client don't support function calling (#572)
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/input.rs | 14 | ||||
| -rw-r--r-- | src/function.rs | 3 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/config/input.rs b/src/config/input.rs index 4d0ed7f..6403640 100644 --- a/src/config/input.rs +++ b/src/config/input.rs @@ -5,7 +5,7 @@ use crate::client::{ MessageContentPart, MessageRole, Model, }; use crate::function::{ToolCallResult, ToolResults}; -use crate::utils::{base64_encode, sha256, AbortSignal}; +use crate::utils::{base64_encode, sha256, warning_text, AbortSignal, IS_STDOUT_TERMINAL}; use anyhow::{bail, Context, Result}; use fancy_regex::Regex; @@ -200,7 +200,7 @@ impl Input { (config.temperature, config.top_p) }; let mut functions = None; - if self.config.read().function_calling && model.supports_function_calling() { + if self.config.read().function_calling { let config = self.config.read(); let function_matcher = if let Some(session) = self.session(&config.session) { session.function_matcher() @@ -209,7 +209,15 @@ impl Input { } else { None }; - functions = config.function.select(function_matcher); + if let Some(function_matcher) = function_matcher { + functions = config.function.select(function_matcher); + if !model.supports_function_calling() { + functions = None; + if *IS_STDOUT_TERMINAL { + eprintln!("{}", warning_text("WARNING: the role or session includes functions, but the model or client does not support function calling.")); + } + } + } }; Ok(ChatCompletionsData { messages, diff --git a/src/function.rs b/src/function.rs index 9cb098a..29bb2c3 100644 --- a/src/function.rs +++ b/src/function.rs @@ -125,8 +125,7 @@ impl Function { }) } - pub fn select(&self, matcher: Option<&str>) -> Option<Vec<FunctionDeclaration>> { - let matcher = matcher?; + pub fn select(&self, matcher: &str) -> Option<Vec<FunctionDeclaration>> { let regex = Regex::new(&format!("^({matcher})$")).ok()?; let output: Vec<FunctionDeclaration> = self .declarations |
