mirror of
https://github.com/openai/codex.git
synced 2026-04-28 18:32:04 +03:00
108 lines
3.4 KiB
Markdown
108 lines
3.4 KiB
Markdown
# PR #2418: Fix #2257 by allowing users to configure oss provider in config.toml
|
|
|
|
- URL: https://github.com/openai/codex/pull/2418
|
|
- Author: seratch
|
|
- Created: 2025-08-18 10:26:28 UTC
|
|
- Updated: 2025-08-25 01:31:32 UTC
|
|
- Changes: +53/-1, Files changed: 2, Commits: 5
|
|
|
|
## Description
|
|
|
|
This pull request resolves #2257
|
|
|
|
## Full Diff
|
|
|
|
```diff
|
|
diff --git a/codex-rs/core/src/config.rs b/codex-rs/core/src/config.rs
|
|
index 9c0c3c1cbe..2ff9e48bd0 100644
|
|
--- a/codex-rs/core/src/config.rs
|
|
+++ b/codex-rs/core/src/config.rs
|
|
@@ -535,7 +535,8 @@ impl Config {
|
|
let mut model_providers = built_in_model_providers();
|
|
// Merge user-defined providers into the built-in list.
|
|
for (key, provider) in cfg.model_providers.into_iter() {
|
|
- model_providers.entry(key).or_insert(provider);
|
|
+ // Override the built-in provider if the same key is present in config.toml
|
|
+ model_providers.insert(key, provider);
|
|
}
|
|
|
|
let model_provider_id = model_provider
|
|
diff --git a/codex-rs/core/tests/model_provider_override.rs b/codex-rs/core/tests/model_provider_override.rs
|
|
new file mode 100644
|
|
index 0000000000..d9e2483f9e
|
|
--- /dev/null
|
|
+++ b/codex-rs/core/tests/model_provider_override.rs
|
|
@@ -0,0 +1,51 @@
|
|
+use std::collections::HashMap;
|
|
+
|
|
+use codex_core::ModelProviderInfo;
|
|
+use codex_core::WireApi;
|
|
+use codex_core::config::Config;
|
|
+use codex_core::config::ConfigOverrides;
|
|
+use codex_core::config::ConfigToml;
|
|
+use tempfile::TempDir;
|
|
+
|
|
+#[test]
|
|
+fn user_defined_provider_overrides_builtin() {
|
|
+ let tmp = TempDir::new().unwrap();
|
|
+
|
|
+ let mut providers = HashMap::new();
|
|
+ providers.insert(
|
|
+ "oss".to_string(),
|
|
+ ModelProviderInfo {
|
|
+ name: "Custom".into(),
|
|
+ base_url: Some("https://example.com/v1".into()),
|
|
+ env_key: None,
|
|
+ env_key_instructions: None,
|
|
+ wire_api: WireApi::Chat,
|
|
+ query_params: None,
|
|
+ http_headers: None,
|
|
+ env_http_headers: None,
|
|
+ request_max_retries: None,
|
|
+ stream_max_retries: None,
|
|
+ stream_idle_timeout_ms: None,
|
|
+ requires_openai_auth: false,
|
|
+ },
|
|
+ );
|
|
+ let cfg = ConfigToml {
|
|
+ model_provider: Some("oss".to_string()),
|
|
+ model: Some("gpt-oss:20b".to_string()),
|
|
+ model_providers: providers,
|
|
+ ..Default::default()
|
|
+ };
|
|
+
|
|
+ let config = Config::load_from_base_config_with_overrides(
|
|
+ cfg,
|
|
+ ConfigOverrides::default(),
|
|
+ tmp.path().to_path_buf(),
|
|
+ )
|
|
+ .unwrap();
|
|
+
|
|
+ assert_eq!(config.model_provider.name, "Custom");
|
|
+ assert_eq!(
|
|
+ config.model_provider.base_url.as_deref(),
|
|
+ Some("https://example.com/v1")
|
|
+ );
|
|
+}
|
|
```
|
|
|
|
## Review Comments
|
|
|
|
### codex-rs/core/src/config.rs
|
|
|
|
- Created: 2025-08-18 22:48:43 UTC | Link: https://github.com/openai/codex/pull/2418#discussion_r2283658230
|
|
|
|
```diff
|
|
@@ -535,7 +535,8 @@ impl Config {
|
|
let mut model_providers = built_in_model_providers();
|
|
// Merge user-defined providers into the built-in list.
|
|
for (key, provider) in cfg.model_providers.into_iter() {
|
|
- model_providers.entry(key).or_insert(provider);
|
|
+ // Override the built-in provider if the same key is present ib config.toml
|
|
```
|
|
|
|
> spelling
|
|
>
|
|
> ```suggestion
|
|
> // Override the built-in provider if the same key is present in config.toml
|
|
> ``` |