summaryrefslogtreecommitdiffstats
path: root/src/config/agent.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-11-06 11:38:11 +0800
committerGitHub <noreply@github.com>2024-11-06 11:38:11 +0800
commit0fac7fea5090642eb5155b2b24f041476b89c813 (patch)
treeb293bb3a4b672e2126564254dc910362b2dd10d2 /src/config/agent.rs
parentb9d2e7e0cfce139f83163d14a387576ac8d331dd (diff)
downloadaichat-0fac7fea5090642eb5155b2b24f041476b89c813.tar.gz
refactor: several improvements (#973)
Diffstat (limited to 'src/config/agent.rs')
-rw-r--r--src/config/agent.rs44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/config/agent.rs b/src/config/agent.rs
index 5d7278b..5589f0e 100644
--- a/src/config/agent.rs
+++ b/src/config/agent.rs
@@ -92,11 +92,13 @@ impl Agent {
None
};
+ let shared_variables = agent_config.variables.clone();
+
Ok(Self {
name: name.to_string(),
config: agent_config,
definition,
- shared_variables: Default::default(),
+ shared_variables,
session_variables: None,
functions,
rag,
@@ -113,6 +115,7 @@ impl Agent {
return Ok(output);
}
let mut printed = false;
+ let mut unset_variables = vec![];
for agent_variable in agent_variables {
let key = agent_variable.name.clone();
match variables.get(&key) {
@@ -126,25 +129,38 @@ impl Agent {
}
if *IS_STDOUT_TERMINAL {
if !printed {
- println!("🚀 Init agent variables...");
+ println!("âš™ Init agent variables...");
printed = true;
}
- let value = Text::new(&agent_variable.description)
- .with_validator(|input: &str| {
- if input.trim().is_empty() {
- Ok(Validation::Invalid("This field is required".into()))
- } else {
- Ok(Validation::Valid)
- }
- })
- .prompt()?;
+ let value = Text::new(&format!(
+ "{} ({}):",
+ agent_variable.name, agent_variable.description
+ ))
+ .with_validator(|input: &str| {
+ if input.trim().is_empty() {
+ Ok(Validation::Invalid("This field is required".into()))
+ } else {
+ Ok(Validation::Valid)
+ }
+ })
+ .prompt()?;
output.insert(key, value);
} else {
- bail!("Failed to init agent variables in non-interactive mode");
+ unset_variables.push(agent_variable)
}
}
}
}
+ if !unset_variables.is_empty() {
+ bail!(
+ "The following agent variables are required:\n{}",
+ unset_variables
+ .iter()
+ .map(|v| format!(" - {}: {}", v.name, v.description))
+ .collect::<Vec<_>>()
+ .join("\n")
+ )
+ }
Ok(output)
}
@@ -211,10 +227,6 @@ impl Agent {
}
}
- pub fn config_variables(&self) -> &IndexMap<String, String> {
- &self.config.variables
- }
-
pub fn shared_variables(&self) -> &IndexMap<String, String> {
&self.shared_variables
}