Documentation
¶
Overview ¶
Package dialect encodes/decodes client wire formats against chat IR.
Index ¶
- func EncodeGeminiRequest(req ir.ChatRequest) ([]byte, error)
- func ParseAnthropicSSE(r io.Reader) <-chan ir.StreamEvent
- func ParseErrorBody(body []byte) (message, typ string)
- func ParseOpenAISSE(r io.Reader) <-chan ir.StreamEvent
- func WriteError(w http.ResponseWriter, d ir.Dialect, status int, message, typ string)
- func WriteUpstreamError(w http.ResponseWriter, d ir.Dialect, status int, body []byte)
- type Anthropic
- type Codec
- type Gemini
- type OpenAI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeGeminiRequest ¶
func EncodeGeminiRequest(req ir.ChatRequest) ([]byte, error)
EncodeGeminiRequest marshals chat IR to a Gemini generateContent request. Provider adapters use the same mapping as the client dialect.
func ParseAnthropicSSE ¶
func ParseAnthropicSSE(r io.Reader) <-chan ir.StreamEvent
ParseAnthropicSSE reads Anthropic messages SSE into IR stream events.
func ParseErrorBody ¶
ParseErrorBody extracts a human message and machine type from common upstream error JSON shapes (OpenAI, Anthropic, Gemini, Bedrock). Unknown bodies fall back to the trimmed raw string when it looks like plain text.
func ParseOpenAISSE ¶
func ParseOpenAISSE(r io.Reader) <-chan ir.StreamEvent
ParseOpenAISSE reads OpenAI chat.completion.chunk SSE into IR stream events.
func WriteError ¶
WriteError writes a dialect-shaped JSON error.
func WriteUpstreamError ¶
WriteUpstreamError remaps an upstream HTTP error body into the client dialect and writes it. Status is preserved; Content-Type is always application/json.
Types ¶
type Anthropic ¶
type Anthropic struct{}
Anthropic is the Anthropic messages dialect codec.
func (Anthropic) DecodeRequest ¶
func (Anthropic) DecodeRequest(body []byte) (ir.ChatRequest, error)
func (Anthropic) EncodeResponse ¶
func (Anthropic) EncodeResponse(resp ir.ChatResponse) ([]byte, error)
func (Anthropic) WriteStream ¶
type Codec ¶
type Codec interface {
Name() ir.Dialect
DecodeRequest(body []byte) (ir.ChatRequest, error)
EncodeResponse(resp ir.ChatResponse) ([]byte, error)
WriteStream(w io.Writer, events <-chan ir.StreamEvent) (prompt, completion int64, err error)
}
Codec converts between a client dialect and chat IR.
type Gemini ¶
type Gemini struct{}
Gemini is the Google Gemini generateContent client dialect codec.
func (Gemini) DecodeRequest ¶
func (Gemini) DecodeRequest(body []byte) (ir.ChatRequest, error)
func (Gemini) EncodeResponse ¶
func (Gemini) EncodeResponse(resp ir.ChatResponse) ([]byte, error)
func (Gemini) WriteStream ¶
type OpenAI ¶
type OpenAI struct{}
OpenAI is the OpenAI chat.completions dialect codec.
func (OpenAI) DecodeRequest ¶
func (OpenAI) DecodeRequest(body []byte) (ir.ChatRequest, error)
func (OpenAI) EncodeResponse ¶
func (OpenAI) EncodeResponse(resp ir.ChatResponse) ([]byte, error)