MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / handleStreamResponse

Method handleStreamResponse

src/api/providers/openai.ts:435–461  ·  view source on GitHub ↗
(stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>)

Source from the content-addressed store, hash-verified

433 }
434
435 private async *handleStreamResponse(stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>): ApiStream {
436 const activeToolCallIds = new Set<string>()
437
438 for await (const chunk of stream) {
439 const delta = chunk.choices?.[0]?.delta
440 const finishReason = chunk.choices?.[0]?.finish_reason
441
442 if (delta) {
443 if (delta.content) {
444 yield {
445 type: "text",
446 text: delta.content,
447 }
448 }
449
450 yield* this.processToolCalls(delta, finishReason, activeToolCallIds)
451 }
452
453 if (chunk.usage) {
454 yield {
455 type: "usage",
456 inputTokens: chunk.usage.prompt_tokens || 0,
457 outputTokens: chunk.usage.completion_tokens || 0,
458 }
459 }
460 }
461 }
462
463 /**
464 * Helper generator to process tool calls from a stream chunk.

Callers 1

handleO3FamilyMessageMethod · 0.95

Calls 1

processToolCallsMethod · 0.95

Tested by

no test coverage detected