fix: Do not inject tools when models don't support them; detect this conflict before API calls happen
This commit is contained in:
@@ -177,6 +177,10 @@ impl Model {
|
|||||||
self.data.max_output_tokens
|
self.data.max_output_tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn supports_function_calling(&self) -> bool {
|
||||||
|
self.data.supports_function_calling
|
||||||
|
}
|
||||||
|
|
||||||
pub fn no_stream(&self) -> bool {
|
pub fn no_stream(&self) -> bool {
|
||||||
self.data.no_stream
|
self.data.no_stream
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-5
@@ -239,12 +239,17 @@ impl Input {
|
|||||||
patch_messages(&mut messages, model);
|
patch_messages(&mut messages, model);
|
||||||
model.guard_max_input_tokens(&messages)?;
|
model.guard_max_input_tokens(&messages)?;
|
||||||
let (temperature, top_p) = (self.role().temperature(), self.role().top_p());
|
let (temperature, top_p) = (self.role().temperature(), self.role().top_p());
|
||||||
let functions = self.config.read().select_functions(self.role());
|
let functions = if model.supports_function_calling() {
|
||||||
if let Some(vec) = &functions {
|
let fns = self.config.read().select_functions(self.role());
|
||||||
for def in vec {
|
if let Some(vec) = &fns {
|
||||||
debug!("Function definition: {:?}", def.name);
|
for def in vec {
|
||||||
|
debug!("Function definition: {:?}", def.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
fns
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
Ok(ChatCompletionsData {
|
Ok(ChatCompletionsData {
|
||||||
messages,
|
messages,
|
||||||
temperature,
|
temperature,
|
||||||
|
|||||||
@@ -1842,6 +1842,12 @@ impl Config {
|
|||||||
bail!("Already in an agent, please run '.exit agent' first to exit the current agent.");
|
bail!("Already in an agent, please run '.exit agent' first to exit the current agent.");
|
||||||
}
|
}
|
||||||
let agent = Agent::init(config, agent_name, abort_signal.clone()).await?;
|
let agent = Agent::init(config, agent_name, abort_signal.clone()).await?;
|
||||||
|
if !agent.model().supports_function_calling() {
|
||||||
|
eprintln!(
|
||||||
|
"Warning: The model '{}' does not support function calling. Agent tools (including todo, spawning, and user interaction) will not be available.",
|
||||||
|
agent.model().id()
|
||||||
|
);
|
||||||
|
}
|
||||||
let session = session_name.map(|v| v.to_string()).or_else(|| {
|
let session = session_name.map(|v| v.to_string()).or_else(|| {
|
||||||
if config.read().macro_flag {
|
if config.read().macro_flag {
|
||||||
None
|
None
|
||||||
|
|||||||
Reference in New Issue
Block a user