mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Unify static model manager construction
This commit is contained in:
@@ -1455,6 +1455,7 @@ async fn guardian_request_model_for_auto_review(
|
||||
ModelsResponse {
|
||||
models: vec![parent_model],
|
||||
},
|
||||
/*unsupported_model_fallback*/ None,
|
||||
);
|
||||
Arc::get_mut(&mut session)
|
||||
.expect("session should be unique")
|
||||
|
||||
@@ -166,10 +166,10 @@ impl ModelProvider for AmazonBedrockModelProvider {
|
||||
_codex_home: PathBuf,
|
||||
config_model_catalog: Option<ModelsResponse>,
|
||||
) -> SharedModelsManager {
|
||||
Arc::new(StaticModelsManager::new_with_unsupported_model_fallback(
|
||||
Arc::new(StaticModelsManager::new(
|
||||
/*auth_manager*/ None,
|
||||
config_model_catalog.map_or_else(static_model_catalog, with_default_only_service_tier),
|
||||
AMAZON_BEDROCK_GPT_5_4_MODEL_ID,
|
||||
/*unsupported_model_fallback*/ Some(AMAZON_BEDROCK_GPT_5_4_MODEL_ID.to_string()),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,6 +290,7 @@ impl ModelProvider for ConfiguredModelProvider {
|
||||
Some(model_catalog) => Arc::new(StaticModelsManager::new(
|
||||
self.auth_manager.clone(),
|
||||
model_catalog,
|
||||
/*unsupported_model_fallback*/ None,
|
||||
)),
|
||||
None => {
|
||||
let endpoint = Arc::new(OpenAiModelsEndpoint::new(
|
||||
|
||||
@@ -233,24 +233,18 @@ impl OpenAiModelsManager {
|
||||
|
||||
impl StaticModelsManager {
|
||||
/// Construct a static model manager from an authoritative catalog.
|
||||
pub fn new(auth_manager: Option<Arc<AuthManager>>, model_catalog: ModelsResponse) -> Self {
|
||||
Self {
|
||||
remote_models: model_catalog.models,
|
||||
auth_manager,
|
||||
unsupported_model_fallback: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a static model manager that replaces unsupported requested models.
|
||||
pub fn new_with_unsupported_model_fallback(
|
||||
///
|
||||
/// When configured, `unsupported_model_fallback` replaces explicit model names that are not
|
||||
/// present in the catalog.
|
||||
pub fn new(
|
||||
auth_manager: Option<Arc<AuthManager>>,
|
||||
model_catalog: ModelsResponse,
|
||||
fallback_model: impl Into<String>,
|
||||
unsupported_model_fallback: Option<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
remote_models: model_catalog.models,
|
||||
auth_manager,
|
||||
unsupported_model_fallback: Some(fallback_model.into()),
|
||||
unsupported_model_fallback,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,17 +197,21 @@ fn openai_manager_for_tests_with_auth(
|
||||
}
|
||||
|
||||
fn static_manager_for_tests(model_catalog: ModelsResponse) -> StaticModelsManager {
|
||||
StaticModelsManager::new(/*auth_manager*/ None, model_catalog)
|
||||
StaticModelsManager::new(
|
||||
/*auth_manager*/ None,
|
||||
model_catalog,
|
||||
/*unsupported_model_fallback*/ None,
|
||||
)
|
||||
}
|
||||
|
||||
fn static_manager_with_fallback_for_tests(
|
||||
model_catalog: ModelsResponse,
|
||||
fallback_model: &str,
|
||||
) -> StaticModelsManager {
|
||||
StaticModelsManager::new_with_unsupported_model_fallback(
|
||||
StaticModelsManager::new(
|
||||
/*auth_manager*/ None,
|
||||
model_catalog,
|
||||
fallback_model,
|
||||
/*unsupported_model_fallback*/ Some(fallback_model.to_string()),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -991,6 +995,7 @@ async fn static_manager_reads_latest_auth_mode() {
|
||||
ModelsResponse {
|
||||
models: vec![chatgpt_only_model, api_model],
|
||||
},
|
||||
/*unsupported_model_fallback*/ None,
|
||||
);
|
||||
|
||||
let chatgpt_models = manager.list_models(RefreshStrategy::Online).await;
|
||||
|
||||
Reference in New Issue
Block a user