fix: fix initial model configuration in cli when using toolshim (#1720)

This commit is contained in:
Alice Hau
2025-03-18 11:12:53 -06:00
committed by GitHub
parent 188dd5bce9
commit ca3dfd72ca

View File

@@ -298,36 +298,42 @@ pub async fn configure_provider_dialog() -> Result<bool, Box<dyn Error>> {
spin.start("Checking your configuration..."); spin.start("Checking your configuration...");
// Create model config with env var settings // Create model config with env var settings
let toolshim_enabled = std::env::var("GOOSE_TOOLSHIM")
.map(|val| val == "1" || val.to_lowercase() == "true")
.unwrap_or(false);
let model_config = goose::model::ModelConfig::new(model.clone()) let model_config = goose::model::ModelConfig::new(model.clone())
.with_max_tokens(Some(50)) .with_max_tokens(Some(50))
.with_toolshim( .with_toolshim(toolshim_enabled)
std::env::var("GOOSE_TOOLSHIM")
.map(|val| val == "1" || val.to_lowercase() == "true")
.unwrap_or(false),
)
.with_toolshim_model(std::env::var("GOOSE_TOOLSHIM_OLLAMA_MODEL").ok()); .with_toolshim_model(std::env::var("GOOSE_TOOLSHIM_OLLAMA_MODEL").ok());
let provider = create(provider_name, model_config)?; let provider = create(provider_name, model_config)?;
let messages = let messages =
vec![Message::user().with_text("What is the weather like in San Francisco today?")]; vec![Message::user().with_text("What is the weather like in San Francisco today?")];
let sample_tool = Tool::new( // Only add the sample tool if toolshim is not enabled
"get_weather".to_string(), let tools = if !toolshim_enabled {
"Get current temperature for a given location.".to_string(), let sample_tool = Tool::new(
json!({ "get_weather".to_string(),
"type": "object", "Get current temperature for a given location.".to_string(),
"required": ["location"], json!({
"properties": { "type": "object",
"location": {"type": "string"} "required": ["location"],
} "properties": {
}), "location": {"type": "string"}
); }
}),
);
vec![sample_tool]
} else {
vec![]
};
let result = provider let result = provider
.complete( .complete(
"You are an AI agent called Goose. You use tools of connected extensions to solve problems.", "You are an AI agent called Goose. You use tools of connected extensions to solve problems.",
&messages, &messages,
&[sample_tool] &tools
) )
.await; .await;