From 5635ca6a58fb4a590419335b098b7317285bfb82 Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 6 Jun 2024 06:23:54 +0800 Subject: refactor: warning model or client don't support function calling (#572) --- src/config/input.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/config') 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, -- cgit v1.2.3