Documentation
¶
Index ¶
- func ParseSSEStream(reader io.Reader) <-chan StreamChunk
- func ResponseFromWire(resp *ChatCompletionResponse) *core.Response
- func StreamChunkToEvent(chunk StreamChunk) core.StreamEvent
- type ChatCompletionRequest
- type ChatCompletionResponse
- type Choice
- type ContentPart
- type Delta
- type ErrorDetail
- type ErrorResponse
- type Function
- type ImageURL
- type Message
- type StreamChoice
- type StreamChunk
- type Tool
- type ToolCall
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSSEStream ¶
func ParseSSEStream(reader io.Reader) <-chan StreamChunk
ParseSSEStream parses Server-Sent Events stream and returns a channel of StreamChunks
func ResponseFromWire ¶
func ResponseFromWire(resp *ChatCompletionResponse) *core.Response
ResponseFromWire converts OpenAI wire response to core.Response
func StreamChunkToEvent ¶
func StreamChunkToEvent(chunk StreamChunk) core.StreamEvent
StreamChunkToEvent converts a StreamChunk to core.StreamEvent
Types ¶
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Temperature float64 `json:"temperature,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
TopP float64 `json:"top_p,omitempty"`
Stop []string `json:"stop,omitempty"`
Stream bool `json:"stream,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"` // for OpenAI o1/o3
EnableSearch bool `json:"enable_search,omitempty"`
Tools []Tool `json:"tools,omitempty"`
}
ChatCompletionRequest represents the OpenAI-compatible chat completion request
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []Choice `json:"choices"`
Usage Usage `json:"usage"`
}
ChatCompletionResponse represents the OpenAI-compatible chat completion response
type Choice ¶
type Choice struct {
Index int `json:"index"`
Message Message `json:"message"`
FinishReason string `json:"finish_reason"`
}
Choice represents a choice in the response
type ContentPart ¶
type ContentPart struct {
Type string `json:"type"` // "text" or "image_url"
Text string `json:"text,omitempty"`
ImageURL *ImageURL `json:"image_url,omitempty"`
}
ContentPart represents a part of multimodal content
type Delta ¶
type Delta struct {
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
ReasoningContent string `json:"reasoning_content,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
Delta represents incremental content in streaming
type ErrorDetail ¶
type ErrorDetail struct {
Message string `json:"message"`
Type string `json:"type"`
Code string `json:"code,omitempty"`
}
ErrorDetail represents error details
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetail `json:"error"`
}
ErrorResponse represents an error response
type Function ¶
type Function struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters json.RawMessage `json:"parameters"`
}
Function represents a function definition
type ImageURL ¶
type ImageURL struct {
URL string `json:"url"` // Can be URL or data:image/png;base64,...
}
ImageURL represents an image URL or data
type Message ¶
type Message struct {
Role string `json:"role"`
Content interface{} `json:"content"` // string or []ContentPart
ReasoningContent string `json:"reasoning_content,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
}
Message represents a message in the OpenAI wire format
type StreamChoice ¶
type StreamChoice struct {
Index int `json:"index"`
Delta *Delta `json:"delta,omitempty"`
FinishReason string `json:"finish_reason,omitempty"`
}
StreamChoice represents a choice in the streaming response
type StreamChunk ¶
type StreamChunk struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []StreamChoice `json:"choices"`
}
StreamChunk represents a chunk in the streaming response
type Tool ¶
Tool represents a tool definition
func ToolsToWire ¶
ToolsToWire converts core.Tool slice to OpenAI wire format