feat: add temperature env var (#2083)

This commit is contained in:
Tyler
2025-04-11 13:45:57 -04:00
committed by GitHub
parent 9bd27cebcb
commit 54f794bc32
3 changed files with 30 additions and 1 deletions

1
Cargo.lock generated
View File

@@ -2361,6 +2361,7 @@ dependencies = [
"serde_yaml", "serde_yaml",
"serial_test", "serial_test",
"sha2", "sha2",
"temp-env",
"tempfile", "tempfile",
"thiserror 1.0.69", "thiserror 1.0.69",
"tokenizers", "tokenizers",

View File

@@ -83,6 +83,7 @@ serial_test = "3.2.0"
mockall = "0.13.1" mockall = "0.13.1"
wiremock = "0.6.0" wiremock = "0.6.0"
tokio = { version = "1.43", features = ["full"] } tokio = { version = "1.43", features = ["full"] }
temp-env = "0.3.6"
[[example]] [[example]]
name = "agent" name = "agent"

View File

@@ -44,11 +44,15 @@ impl ModelConfig {
let toolshim_model = std::env::var("GOOSE_TOOLSHIM_OLLAMA_MODEL").ok(); let toolshim_model = std::env::var("GOOSE_TOOLSHIM_OLLAMA_MODEL").ok();
let temperature = std::env::var("GOOSE_TEMPERATURE")
.ok()
.and_then(|val| val.parse::<f32>().ok());
Self { Self {
model_name, model_name,
tokenizer_name: tokenizer_name.to_string(), tokenizer_name: tokenizer_name.to_string(),
context_limit, context_limit,
temperature: None, temperature,
max_tokens: None, max_tokens: None,
toolshim, toolshim,
toolshim_model, toolshim_model,
@@ -182,4 +186,27 @@ mod tests {
.with_toolshim_model(Some("mistral-nemo".to_string())); .with_toolshim_model(Some("mistral-nemo".to_string()));
assert_eq!(config.toolshim_model, Some("mistral-nemo".to_string())); assert_eq!(config.toolshim_model, Some("mistral-nemo".to_string()));
} }
#[test]
fn test_model_config_temp_env_var() {
use temp_env::with_var;
with_var("GOOSE_TEMPERATURE", Some("0.128"), || {
let config = ModelConfig::new("test-model".to_string());
assert_eq!(config.temperature, Some(0.128));
});
with_var("GOOSE_TEMPERATURE", Some("notanum"), || {
let config = ModelConfig::new("test-model".to_string());
assert_eq!(config.temperature, None);
});
with_var("GOOSE_TEMPERATURE", Some(""), || {
let config = ModelConfig::new("test-model".to_string());
assert_eq!(config.temperature, None);
});
let config = ModelConfig::new("test-model".to_string());
assert_eq!(config.temperature, None);
}
} }