Skip to content

Commit 6ba7e14

Browse files
feat(config): add environment variable overrides for model and provider (#2003)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 4db8fde commit 6ba7e14

File tree

7 files changed

+337
-10
lines changed

7 files changed

+337
-10
lines changed

crates/forge_app/src/orch_spec/orch_setup.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ impl Default for TestContext {
8484
custom_history_path: None,
8585
max_conversations: 100,
8686
max_image_size: 262144,
87+
override_model: None,
88+
override_provider: None,
8789
},
8890
title: Some("test-conversation".into()),
8991
agent: Agent::new(

crates/forge_domain/src/env.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use derive_setters::Setters;
66
use serde::{Deserialize, Serialize};
77
use url::Url;
88

9-
use crate::{HttpConfig, RetryConfig};
9+
use crate::{HttpConfig, ModelId, ProviderId, RetryConfig};
1010

1111
const VERSION: &str = match option_env!("APP_VERSION") {
1212
Some(val) => val,
@@ -70,6 +70,15 @@ pub struct Environment {
7070
/// Maximum number of conversations to show in list.
7171
/// Controlled by FORGE_MAX_CONVERSATIONS environment variable.
7272
pub max_conversations: usize,
73+
/// Override model for all providers from FORGE_OVERRIDE_MODEL environment
74+
/// variable. If set, this model will be used instead of configured
75+
/// models.
76+
#[dummy(default)]
77+
pub override_model: Option<ModelId>,
78+
/// Override provider from FORGE_OVERRIDE_PROVIDER environment variable.
79+
/// If set, this provider will be used as default.
80+
#[dummy(default)]
81+
pub override_provider: Option<ProviderId>,
7382
}
7483

7584
impl Environment {
@@ -273,6 +282,8 @@ fn test_command_path() {
273282
custom_history_path: None,
274283
max_conversations: 100,
275284
max_image_size: 262144,
285+
override_model: None,
286+
override_provider: None,
276287
};
277288

278289
let actual = fixture.command_path();
@@ -307,6 +318,8 @@ fn test_command_cwd_path() {
307318
custom_history_path: None,
308319
max_conversations: 100,
309320
max_image_size: 262144,
321+
override_model: None,
322+
override_provider: None,
310323
};
311324

312325
let actual = fixture.command_cwd_path();
@@ -341,6 +354,8 @@ fn test_command_cwd_path_independent_from_command_path() {
341354
custom_history_path: None,
342355
max_conversations: 100,
343356
max_image_size: 262144,
357+
override_model: None,
358+
override_provider: None,
344359
};
345360

346361
let command_path = fixture.command_path();

crates/forge_infra/src/env.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
33
use std::str::FromStr;
44

55
use forge_app::EnvironmentInfra;
6-
use forge_domain::{Environment, RetryConfig, TlsBackend, TlsVersion};
6+
use forge_domain::{Environment, ModelId, ProviderId, RetryConfig, TlsBackend, TlsVersion};
77
use reqwest::Url;
88

99
#[derive(Clone)]
@@ -55,6 +55,10 @@ impl ForgeEnvironmentInfra {
5555
// Parse custom history file path from environment variable
5656
let custom_history_path = parse_env::<String>("FORGE_HISTORY_FILE").map(PathBuf::from);
5757

58+
let override_model = parse_env::<String>("FORGE_OVERRIDE_MODEL").map(ModelId::new);
59+
let override_provider = parse_env::<String>("FORGE_OVERRIDE_PROVIDER")
60+
.and_then(|s| ProviderId::from_str(&s).ok());
61+
5862
Environment {
5963
os: std::env::consts::OS.to_string(),
6064
pid: std::process::id(),
@@ -82,6 +86,8 @@ impl ForgeEnvironmentInfra {
8286
forge_api_url,
8387
custom_history_path,
8488
max_conversations: parse_env::<usize>("FORGE_MAX_CONVERSATIONS").unwrap_or(100),
89+
override_model,
90+
override_provider,
8591
}
8692
}
8793

0 commit comments

Comments
 (0)