mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-23 16:00:40 +00:00
fix(xai): tolerate unknown reasoning effort values in the catalog
Add a serde(other) variant to GrokCatalogReasoningEffort and drop unrecognized efforts from the capability projection, mirroring the api_backend handling: a novel effort value in one model previously failed the whole snapshot parse and collapsed /v1/models to the default model once the cache expired. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -600,6 +600,9 @@ pub enum GrokCatalogReasoningEffort {
|
||||
High,
|
||||
Xhigh,
|
||||
Max,
|
||||
/// 上游新增、当前 adapter 尚未识别的 effort;不进入能力投影。
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl GrokCatalogReasoningEffort {
|
||||
@@ -614,6 +617,7 @@ impl GrokCatalogReasoningEffort {
|
||||
Self::High => "high",
|
||||
Self::Xhigh => "xhigh",
|
||||
Self::Max => "max",
|
||||
Self::Unknown => "unknown",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -990,19 +994,24 @@ fn normalize_model(wire: GrokModelWire) -> Result<GrokCatalogModel, GrokModelCat
|
||||
.filter(|backend| *backend != GrokCatalogApiBackend::Unknown);
|
||||
let responses_api = responses_evidence(wire.supported_in_api, api_backend);
|
||||
let mut menu_default = None;
|
||||
// 未识别的 effort 值不进入能力投影,也不作为默认值候选。
|
||||
let reasoning_efforts = wire
|
||||
.reasoning_efforts
|
||||
.into_iter()
|
||||
.map(|option| {
|
||||
.filter_map(|option| {
|
||||
let (effort, is_default) = option.into_parts();
|
||||
if effort == GrokCatalogReasoningEffort::Unknown {
|
||||
return None;
|
||||
}
|
||||
if is_default && menu_default.is_none() {
|
||||
menu_default = Some(effort);
|
||||
}
|
||||
effort
|
||||
Some(effort)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let default_reasoning_effort = wire
|
||||
.reasoning_effort
|
||||
.filter(|effort| *effort != GrokCatalogReasoningEffort::Unknown)
|
||||
.or(menu_default)
|
||||
.or_else(|| reasoning_efforts.first().copied());
|
||||
let reasoning_effort = if reasoning_efforts.is_empty() {
|
||||
|
||||
@@ -376,6 +376,30 @@ fn reasoning_effort_menu_should_be_capability_evidence_without_legacy_flag() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_reasoning_effort_values_should_not_fail_the_snapshot() {
|
||||
let snapshot = parse_grok_model_catalog(
|
||||
br#"{"object":"list","data":[{"id":"grok-reasoning","reasoningEffort":"ultra","reasoningEfforts":[{"value":"ultra","default":true},"low","hyper"]}]}"#,
|
||||
None,
|
||||
)
|
||||
.expect("unknown effort values must not break catalog parsing");
|
||||
let capabilities = snapshot.models()[0].capabilities();
|
||||
|
||||
assert_eq!(
|
||||
(
|
||||
capabilities
|
||||
.reasoning_efforts()
|
||||
.iter()
|
||||
.map(|effort| effort.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
capabilities
|
||||
.default_reasoning_effort()
|
||||
.map(|effort| effort.as_str()),
|
||||
),
|
||||
(vec!["low"], Some("low"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn model_id_should_take_priority_over_catalog_id() {
|
||||
let snapshot = parse_grok_model_catalog(
|
||||
|
||||
Reference in New Issue
Block a user