summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config/input.rs14
-rw-r--r--src/function.rs3
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