Documentation
¶
Index ¶
- func ParseSSEDataPayload(line string) (payload string, ok bool)
- func ReadSSELines(r io.Reader) (lines []string, raw []byte)
- func WriteSSEResponse(w http.ResponseWriter, events []string)
- type ParsedResult
- func AssembleAnthropicStream(events []string) *ParsedResult
- func AssembleGoogleStream(events []string) *ParsedResult
- func AssembleOpenAIChatStream(events []string) *ParsedResult
- func AssembleOpenAIResponsesStream(events []string) *ParsedResult
- func AssembleOpenAIStream(events []string) *ParsedResult
- func ParseAnthropicResult(m map[string]interface{}) *ParsedResult
- func ParseGoogleResult(m map[string]interface{}) *ParsedResult
- func ParseOpenAIChatResult(m map[string]interface{}) *ParsedResult
- func ParseOpenAIResponsesResult(m map[string]interface{}) *ParsedResult
- type ParsedTokenUsage
- type ParsedToolCall
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSSEDataPayload ¶
ParseSSEDataPayload checks if a line is an SSE data line and extracts the payload. Handles both Gin-style ("data:{json}") and standard SSE ("data: {json}") formats.
func ReadSSELines ¶
ReadSSELines reads an SSE response body and returns each non-empty line as a string. Blank lines (SSE message separators) are skipped. The raw bytes of all non-empty lines (with newlines) are also returned for inspection.
func WriteSSEResponse ¶
func WriteSSEResponse(w http.ResponseWriter, events []string)
WriteSSEResponse writes pre-built SSE event strings to an HTTP response. Events that start with "event:" are grouped with the following "data:" line into a single SSE message (separated by a blank line), matching the SSE spec. A 5 ms flush interval is applied between messages.
Types ¶
type ParsedResult ¶
type ParsedResult struct {
Role string
Content string
Model string
FinishReason string
ThinkingContent string
ToolCalls []ParsedToolCall
Usage *ParsedTokenUsage
}
ParsedResult is a protocol-agnostic view of an AI response, extracted from raw JSON (non-streaming) or SSE event lines (streaming). Used by test infrastructure and virtual model servers to inspect gateway responses without importing SDK types.
func AssembleAnthropicStream ¶
func AssembleAnthropicStream(events []string) *ParsedResult
AssembleAnthropicStream assembles a ParsedResult from Anthropic SSE event lines.
func AssembleGoogleStream ¶
func AssembleGoogleStream(events []string) *ParsedResult
AssembleGoogleStream assembles a ParsedResult from Google GenerateContent SSE event lines.
func AssembleOpenAIChatStream ¶
func AssembleOpenAIChatStream(events []string) *ParsedResult
AssembleOpenAIChatStream assembles a ParsedResult from OpenAI Chat SSE event lines.
func AssembleOpenAIResponsesStream ¶
func AssembleOpenAIResponsesStream(events []string) *ParsedResult
AssembleOpenAIResponsesStream assembles a ParsedResult from OpenAI Responses API SSE event lines.
func AssembleOpenAIStream ¶
func AssembleOpenAIStream(events []string) *ParsedResult
AssembleOpenAIStream auto-detects whether events are Responses API or Chat format and delegates accordingly.
func ParseAnthropicResult ¶
func ParseAnthropicResult(m map[string]interface{}) *ParsedResult
ParseAnthropicResult extracts fields from an Anthropic Messages API response.
func ParseGoogleResult ¶
func ParseGoogleResult(m map[string]interface{}) *ParsedResult
ParseGoogleResult extracts fields from a Google GenerateContent response.
func ParseOpenAIChatResult ¶
func ParseOpenAIChatResult(m map[string]interface{}) *ParsedResult
ParseOpenAIChatResult extracts fields from an OpenAI Chat Completion response (map[string]interface{} already JSON-decoded).
func ParseOpenAIResponsesResult ¶
func ParseOpenAIResponsesResult(m map[string]interface{}) *ParsedResult
ParseOpenAIResponsesResult extracts fields from an OpenAI Responses API response.
type ParsedTokenUsage ¶
ParsedTokenUsage holds token counts extracted from a parsed response.
type ParsedToolCall ¶
ParsedToolCall holds a single tool/function call extracted from a response.