MCPcopy Create free account
hub / github.com/codehamr/codehamr / streamChunk

Struct streamChunk

internal/llm/llm.go:93–109  ·  view source on GitHub ↗

streamChunk is one OpenAI SSE frame. finish_reason is deliberately not decoded: readSSE dispatches accumulated tool calls at stream end, not on finish_reason=="tool_calls", staying provider agnostic since Ollama's /v1 shim sometimes closes with "stop" even after streaming tool_calls.

Source from the content-addressed store, hash-verified

91// ROUTED on (readSSE dispatches accumulated tool calls at stream end, not on
92// finish_reason=="tool_calls", staying provider agnostic since Ollama's /v1 shim
93// sometimes closes with "stop" even after streaming tool_calls); it is decoded
94// only as one of the end-of-stream completion signals, where any non-empty
95// value - right or wrong - means the server finished on purpose.
96type streamChunk struct {
97 Choices []struct {
98 Delta streamDelta `json:"delta"`
99 FinishReason string `json:"finish_reason"`
100 } `json:"choices"`
101 Usage *struct {
102 CompletionTokens int `json:"completion_tokens"`
103 PromptTokens int `json:"prompt_tokens"`
104 } `json:"usage,omitempty"`
105 // Error is the mid-stream failure frame OpenAI-compatible backends (and
106 // OpenRouter-style proxies) emit when the provider dies after 200 OK:
107 // `data: {"error":{...}}`, then the connection closes with no [DONE].
108 // Without decoding it, the frame parses to zero choices, the close reads
109 // as clean EOF, and a mid-sentence-truncated turn finalizes as a success.
110 Error *struct {
111 Message string `json:"message"`
112 } `json:"error,omitempty"`

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected