summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-07-02 19:06:18 +0800
committerGitHub <noreply@github.com>2024-07-02 19:06:18 +0800
commit3de95f04d8ec682c811c079914e77d5ffb0db2d0 (patch)
tree4cd58f49d1f737ead2be723e0b4fbefca8f0314f
parent3b6cf3cd1b4278551feb174c875e8785c9cb8828 (diff)
downloadaichat-3de95f04d8ec682c811c079914e77d5ffb0db2d0.tar.gz
refactor: smart `function_calling` config value (#677)
-rw-r--r--src/config/mod.rs21
-rw-r--r--src/function.rs2
2 files changed, 18 insertions, 5 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index db58b3d..6725c93 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -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() {
diff --git a/src/function.rs b/src/function.rs
index e99d2c6..a8c193a 100644
--- a/src/function.rs
+++ b/src/function.rs
@@ -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()
)
};