mirror of
https://github.com/openai/codex.git
synced 2026-11-02 19:43:24 +00:00
codex: rebase custom model aliases onto main
This commit is contained in:
@@ -61,6 +61,7 @@ use opentelemetry::trace::TraceContextExt;
|
||||
use opentelemetry::trace::TraceId;
|
||||
use opentelemetry::trace::TracerProvider as _;
|
||||
use opentelemetry_sdk::trace::SdkTracerProvider;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
@@ -1898,6 +1899,7 @@ async fn session_new_fails_when_zsh_fork_enabled_without_zsh_path() {
|
||||
config.codex_home.clone(),
|
||||
auth_manager.clone(),
|
||||
None,
|
||||
HashMap::new(),
|
||||
CollaborationModesConfig::default(),
|
||||
));
|
||||
let model = ModelsManager::get_model_offline_for_tests(config.model.as_deref());
|
||||
@@ -1986,6 +1988,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
config.codex_home.clone(),
|
||||
auth_manager.clone(),
|
||||
None,
|
||||
HashMap::new(),
|
||||
CollaborationModesConfig::default(),
|
||||
));
|
||||
let agent_control = AgentControl::default();
|
||||
@@ -2393,6 +2396,7 @@ pub(crate) async fn make_session_and_context_with_dynamic_tools_and_rx(
|
||||
config.codex_home.clone(),
|
||||
auth_manager.clone(),
|
||||
None,
|
||||
HashMap::new(),
|
||||
CollaborationModesConfig::default(),
|
||||
));
|
||||
let agent_control = AgentControl::default();
|
||||
|
||||
@@ -3002,6 +3002,7 @@ fn test_precedence_fixture_with_o3_profile() -> std::io::Result<()> {
|
||||
review_model: None,
|
||||
model_context_window: None,
|
||||
model_auto_compact_token_limit: None,
|
||||
custom_models: HashMap::new(),
|
||||
service_tier: None,
|
||||
model_provider_id: "openai".to_string(),
|
||||
model_provider: fixture.openai_provider.clone(),
|
||||
@@ -3137,6 +3138,7 @@ fn test_precedence_fixture_with_gpt3_profile() -> std::io::Result<()> {
|
||||
review_model: None,
|
||||
model_context_window: None,
|
||||
model_auto_compact_token_limit: None,
|
||||
custom_models: HashMap::new(),
|
||||
service_tier: None,
|
||||
model_provider_id: "openai-custom".to_string(),
|
||||
model_provider: fixture.openai_custom_provider.clone(),
|
||||
@@ -3270,6 +3272,7 @@ fn test_precedence_fixture_with_zdr_profile() -> std::io::Result<()> {
|
||||
review_model: None,
|
||||
model_context_window: None,
|
||||
model_auto_compact_token_limit: None,
|
||||
custom_models: HashMap::new(),
|
||||
service_tier: None,
|
||||
model_provider_id: "openai".to_string(),
|
||||
model_provider: fixture.openai_provider.clone(),
|
||||
@@ -3389,6 +3392,7 @@ fn test_precedence_fixture_with_gpt5_profile() -> std::io::Result<()> {
|
||||
review_model: None,
|
||||
model_context_window: None,
|
||||
model_auto_compact_token_limit: None,
|
||||
custom_models: HashMap::new(),
|
||||
service_tier: None,
|
||||
model_provider_id: "openai".to_string(),
|
||||
model_provider: fixture.openai_provider.clone(),
|
||||
|
||||
@@ -159,6 +159,12 @@ pub(crate) fn test_config() -> Config {
|
||||
.expect("load default test config")
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub(crate) fn custom_model_alias(&self, alias: &str) -> Option<&CustomModelConfig> {
|
||||
self.custom_models.get(alias)
|
||||
}
|
||||
}
|
||||
|
||||
/// Application configuration loaded from disk and merged with overrides.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Permissions {
|
||||
@@ -358,6 +364,9 @@ pub struct Config {
|
||||
/// Combined provider map (defaults merged with user-defined overrides).
|
||||
pub model_providers: HashMap<String, ModelProviderInfo>,
|
||||
|
||||
/// User-defined model aliases shown in the picker.
|
||||
pub custom_models: HashMap<String, CustomModelConfig>,
|
||||
|
||||
/// Maximum number of bytes to include from an AGENTS.md project doc file.
|
||||
pub project_doc_max_bytes: usize,
|
||||
|
||||
@@ -1143,6 +1152,10 @@ pub struct ConfigToml {
|
||||
#[serde(default)]
|
||||
pub model_providers: HashMap<String, ModelProviderInfo>,
|
||||
|
||||
/// User-defined model aliases that can override model context settings.
|
||||
#[serde(default)]
|
||||
pub custom_models: Vec<CustomModelToml>,
|
||||
|
||||
/// Maximum number of bytes to include from an AGENTS.md project doc file.
|
||||
pub project_doc_max_bytes: Option<usize>,
|
||||
|
||||
@@ -1381,6 +1394,29 @@ pub struct RealtimeAudioToml {
|
||||
pub speaker: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct CustomModelConfig {
|
||||
/// Provider-facing model slug used on API requests.
|
||||
pub model: String,
|
||||
/// Optional context window override applied when this alias is selected.
|
||||
pub model_context_window: Option<i64>,
|
||||
/// Optional auto-compaction token limit override applied when this alias is selected.
|
||||
pub model_auto_compact_token_limit: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct CustomModelToml {
|
||||
/// User-facing alias shown in the model picker.
|
||||
pub name: String,
|
||||
/// Provider-facing model slug used on API requests.
|
||||
pub model: String,
|
||||
/// Optional context window override applied when this alias is selected.
|
||||
pub model_context_window: Option<i64>,
|
||||
/// Optional auto-compaction token limit override applied when this alias is selected.
|
||||
pub model_auto_compact_token_limit: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct ToolsToml {
|
||||
@@ -2046,6 +2082,24 @@ impl Config {
|
||||
for (key, provider) in cfg.model_providers.into_iter() {
|
||||
model_providers.entry(key).or_insert(provider);
|
||||
}
|
||||
let mut custom_models = HashMap::new();
|
||||
for custom in cfg.custom_models {
|
||||
let alias = custom.name;
|
||||
if custom_models.contains_key(&alias) {
|
||||
return Err(std::io::Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
format!("duplicate custom model alias: {alias}"),
|
||||
));
|
||||
}
|
||||
custom_models.insert(
|
||||
alias,
|
||||
CustomModelConfig {
|
||||
model: custom.model,
|
||||
model_context_window: custom.model_context_window,
|
||||
model_auto_compact_token_limit: custom.model_auto_compact_token_limit,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let model_provider_id = model_provider
|
||||
.or(config_profile.model_provider)
|
||||
@@ -2378,6 +2432,7 @@ impl Config {
|
||||
mcp_oauth_callback_port: cfg.mcp_oauth_callback_port,
|
||||
mcp_oauth_callback_url: cfg.mcp_oauth_callback_url.clone(),
|
||||
model_providers,
|
||||
custom_models,
|
||||
project_doc_max_bytes: cfg.project_doc_max_bytes.unwrap_or(PROJECT_DOC_MAX_BYTES),
|
||||
project_doc_fallback_filenames: cfg
|
||||
.project_doc_fallback_filenames
|
||||
|
||||
Reference in New Issue
Block a user