mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
refactor(ai): use typed choice.usage in openai-chat parser (#57596)
This commit is contained in:
committed by
GitHub
Unverified
parent
4b50f5cc6c
commit
8c60f940bc
@@ -1028,10 +1028,9 @@ const step = (state: ParserState, event: OpenAIChatEvent) =>
|
||||
const choice = event.choices?.[0]
|
||||
// Moonshot (and a few other OpenAI-compatible providers) attach usage to
|
||||
// `choice.usage` instead of the top-level `usage` field.
|
||||
const choiceUsage = (choice as unknown as { usage?: OpenAIChatEvent["usage"] })?.usage
|
||||
const usage =
|
||||
mapUsage(event.usage, state.providerMetadataKey) ??
|
||||
(choiceUsage ? mapUsage(choiceUsage, state.providerMetadataKey) : undefined) ??
|
||||
mapUsage(choice?.usage, state.providerMetadataKey) ??
|
||||
state.usage
|
||||
const rawFinishReason = choice?.finish_reason
|
||||
const finishReason = rawFinishReason
|
||||
|
||||
Reference in New Issue
Block a user