Fix OpenAI Provider with GitHub Models (#3875)

Signed-off-by: Rahul Zhade <rzhade3@users.noreply.github.com>
This commit is contained in:
Rahul Zhade
2025-08-06 05:45:08 -04:00
committed by GitHub
parent 46e883db6e
commit 7f877960d3
+10 -7
View File
@@ -48,7 +48,7 @@ struct StreamingChunk {
created: Option<i64>, created: Option<i64>,
id: Option<String>, id: Option<String>,
usage: Option<Value>, usage: Option<Value>,
model: String, model: Option<String>,
} }
/// Convert internal Message format to OpenAI's API message specification /// Convert internal Message format to OpenAI's API message specification
@@ -428,13 +428,14 @@ where
let chunk: StreamingChunk = serde_json::from_str(line let chunk: StreamingChunk = serde_json::from_str(line
.ok_or_else(|| anyhow!("unexpected stream format"))?) .ok_or_else(|| anyhow!("unexpected stream format"))?)
.map_err(|e| anyhow!("Failed to parse streaming chunk: {}: {:?}", e, &line))?; .map_err(|e| anyhow!("Failed to parse streaming chunk: {}: {:?}", e, &line))?;
let model = chunk.model.clone();
let usage = chunk.usage.as_ref().map(|u| { let usage = chunk.usage.as_ref().and_then(|u| {
ProviderUsage { chunk.model.as_ref().map(|model| {
usage: get_usage(u), ProviderUsage {
model, usage: get_usage(u),
} model: model.clone(),
}
})
}); });
if chunk.choices.is_empty() { if chunk.choices.is_empty() {
@@ -534,6 +535,8 @@ where
None None
}, },
) )
} else if usage.is_some() {
yield (None, usage)
} }
} }
} }