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

View File

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

View File

@@ -44,11 +44,15 @@ impl ModelConfig {
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 {
model_name,
tokenizer_name: tokenizer_name.to_string(),
context_limit,
temperature: None,
temperature,
max_tokens: None,
toolshim,
toolshim_model,
@@ -182,4 +186,27 @@ mod tests {
.with_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);
}
}