refactor: warning model or client don't support function calling (#572)

pull/581/head
sigoden 4 months ago committed by GitHub
parent 93ef6da629
commit 5635ca6a58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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,

@ -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

Loading…
Cancel
Save