refactor: smart `function_calling` config value (#677)

pull/680/head
sigoden 4 months ago committed by GitHub
parent 3b6cf3cd1b
commit 3de95f04d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -162,7 +162,7 @@ impl Default for Config {
repl_prelude: None,
agent_prelude: None,
function_calling: false,
function_calling: true,
dangerously_functions_filter: None,
agents: vec![],
@ -222,9 +222,9 @@ impl Config {
config.set_wrap(&wrap)?;
}
config.functions = Functions::init(&Self::functions_file()?)?;
config.working_mode = working_mode;
config.load_functions()?;
config.load_roles()?;
config.setup_model()?;
@ -531,6 +531,11 @@ impl Config {
}
"function_calling" => {
let value = value.parse().with_context(|| "Invalid value")?;
if value && self.functions.is_empty() {
bail!(
"Cannot enable function_calling because there are no functions installed."
)
}
self.function_calling = value;
}
"compress_threshold" => {
@ -949,7 +954,7 @@ impl Config {
abort_signal: AbortSignal,
) -> Result<()> {
if !config.read().function_calling {
bail!("Before using the agent, please configure function calling first.");
bail!("Please enable function calling before using the agent.");
}
if config.read().agent.is_some() {
bail!("Already in a agent, please run '.exit agent' first to exit the current agent.");
@ -1385,6 +1390,14 @@ impl Config {
Ok(config)
}
fn load_functions(&mut self) -> Result<()> {
self.functions = Functions::init(&Self::functions_file()?)?;
if self.functions.is_empty() {
self.function_calling = false;
}
Ok(())
}
fn load_roles(&mut self) -> Result<()> {
let path = Self::roles_file()?;
self.roles = if !path.exists() {

@ -62,7 +62,7 @@ impl Functions {
let declarations: Vec<FunctionDeclaration> = if declarations_path.exists() {
let ctx = || {
format!(
"Failed to load function declarations at {}",
"Failed to load functions at {}",
declarations_path.display()
)
};

Loading…
Cancel
Save