Skip to content

Commit

Permalink
refactor: don't init agent RAG/variables when using --info (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Nov 13, 2024
1 parent 777fc02 commit 0aa93fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/config/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Agent {

let rag = if rag_path.exists() {
Some(Arc::new(Rag::load(config, DEFAULT_AGENT_NAME, &rag_path)?))
} else if !definition.documents.is_empty() {
} else if !definition.documents.is_empty() && !config.read().print_info_only {
let mut ans = false;
if *IS_STDOUT_TERMINAL {
ans = Confirm::new("The agent has the documents, init RAG?")
Expand Down Expand Up @@ -109,6 +109,7 @@ impl Agent {
pub fn init_agent_variables(
agent_variables: &[AgentVariable],
variables: &IndexMap<String, String>,
no_interaction: bool,
) -> Result<IndexMap<String, String>> {
let mut output = IndexMap::new();
if agent_variables.is_empty() {
Expand All @@ -127,6 +128,9 @@ impl Agent {
output.insert(key, value);
continue;
}
if no_interaction {
continue;
}
if *IS_STDOUT_TERMINAL {
if !printed {
println!("⚙ Init agent variables...");
Expand Down
16 changes: 13 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ pub struct Config {
#[serde(skip)]
pub working_mode: WorkingMode,
#[serde(skip)]
pub print_info_only: bool,
#[serde(skip)]
pub last_message: Option<(Input, String)>,
}

Expand Down Expand Up @@ -212,6 +214,7 @@ impl Default for Config {
model: Default::default(),
functions: Default::default(),
working_mode: WorkingMode::Cmd,
print_info_only: false,
last_message: None,
}
}
Expand Down Expand Up @@ -1860,8 +1863,11 @@ impl Config {
Some(v) => v,
None => return Ok(()),
};
let new_variables =
Agent::init_agent_variables(agent.defined_variables(), agent.config_variables())?;
let new_variables = Agent::init_agent_variables(
agent.defined_variables(),
agent.config_variables(),
self.print_info_only,
)?;
agent.set_shared_variables(new_variables);
Ok(())
}
Expand All @@ -1878,7 +1884,11 @@ impl Config {
shared_variables.clone()
};
all_variables.extend(session.agent_variables().clone());
let new_variables = Agent::init_agent_variables(agent.defined_variables(), &all_variables)?;
let new_variables = Agent::init_agent_variables(
agent.defined_variables(),
&all_variables,
self.print_info_only,
)?;
if shared_variables.is_empty() {
agent.set_shared_variables(new_variables.clone());
}
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ async fn run(config: GlobalConfig, cli: Cli, text: Option<String>) -> Result<()>
if let Some(addr) = cli.serve {
return serve::run(config, addr).await;
}
if cli.info {
config.write().print_info_only = true;
}

if cli.list_models {
for model in list_chat_models(&config.read()) {
println!("{}", model.id());
Expand Down

0 comments on commit 0aa93fa

Please sign in to comment.