fix: use TOML parser instead of regex for Codex model extraction (#2222) (#2227)

* fix(codex): use TOML parser instead of regex for model extraction

Regex only matched model=... on first line, TOML parser handles
multiline TOML correctly.

Fixes #2222

* fix(stream_check): drop unused regex::Regex import

The previous commit replaced the only Regex usage in stream_check.rs
with toml::Table parsing, leaving `use regex::Regex;` orphaned.
Without this removal, `cargo clippy -- -D warnings` (run in CI)
fails with `unused import: regex::Regex`.

---------

Co-authored-by: Jason <farion1231@gmail.com>
This commit is contained in:
nmsn
2026-04-23 10:38:08 +08:00
committed by GitHub
parent 29e87487a1
commit 3ad7d0b1cc
+5 -5
View File
@@ -3,7 +3,6 @@
//! 使用流式 API 进行快速健康检查,只需接收首个 chunk 即判定成功。
use futures::StreamExt;
use regex::Regex;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_json::json;
@@ -1412,10 +1411,11 @@ impl StreamCheckService {
return None;
}
let re = Regex::new(r#"^model\s*=\s*["']([^"']+)["']"#).ok()?;
re.captures(config_text)
.and_then(|caps| caps.get(1))
.map(|m| m.as_str().trim().to_string())
let table = toml::from_str::<toml::Table>(config_text).ok()?;
table
.get("model")
.and_then(|v| v.as_str())
.map(|s| s.trim().to_string())
.filter(|value| !value.is_empty())
}