Documentation
¶
Overview ¶
Package common provides shared utilities used by multiple LLM provider implementations (openai_compat, azure, etc.).
Index ¶
- Constants
- func AsFloat(v any) (float64, bool)
- func AsInt(v any) (int, bool)
- func DecodeToolCallArguments(raw json.RawMessage, name string) map[string]any
- func HandleErrorResponse(resp *http.Response, apiBase string) error
- func LooksLikeHTML(body []byte, contentType string) bool
- func NewHTTPClient(proxy string) *http.Client
- func ResponsePreview(body []byte, maxLen int) string
- func SerializeMessages(messages []Message) []any
- func WrapHTMLResponseError(statusCode int, body []byte, contentType, apiBase string) error
- type ExtraContent
- type FunctionCall
- type GoogleExtra
- type LLMResponse
- type Message
- type ReasoningDetail
- type ToolCall
- type ToolDefinition
- type ToolFunctionDefinition
- type UsageInfo
Constants ¶
const DefaultRequestTimeout = 120 * time.Second
Variables ¶
This section is empty.
Functions ¶
func DecodeToolCallArguments ¶
func DecodeToolCallArguments(raw json.RawMessage, name string) map[string]any
DecodeToolCallArguments decodes a tool call's arguments from raw JSON.
func HandleErrorResponse ¶
HandleErrorResponse reads a non-200 response body and returns an appropriate error.
func LooksLikeHTML ¶
LooksLikeHTML checks if the response body appears to be HTML.
func NewHTTPClient ¶
NewHTTPClient creates an *http.Client with an optional proxy and the default timeout.
func ResponsePreview ¶
ResponsePreview returns a truncated preview of response body for error messages.
func SerializeMessages ¶
SerializeMessages converts internal Message structs to the OpenAI wire format.
- Strips SystemParts (unknown to third-party endpoints)
- Converts messages with Media to multipart content format (text + image_url parts)
- Preserves ToolCallID, ToolCalls, and ReasoningContent for all messages
Types ¶
type ExtraContent ¶
type ExtraContent = protocoltypes.ExtraContent
Re-export protocol types used across providers.
type FunctionCall ¶
type FunctionCall = protocoltypes.FunctionCall
Re-export protocol types used across providers.
type GoogleExtra ¶
type GoogleExtra = protocoltypes.GoogleExtra
Re-export protocol types used across providers.
type LLMResponse ¶
type LLMResponse = protocoltypes.LLMResponse
Re-export protocol types used across providers.
func ParseResponse ¶
func ParseResponse(body io.Reader) (*LLMResponse, error)
ParseResponse parses a JSON chat completion response body into an LLMResponse.
func ReadAndParseResponse ¶
func ReadAndParseResponse(resp *http.Response, apiBase string) (*LLMResponse, error)
ReadAndParseResponse peeks at the response body to detect HTML errors, then parses the JSON response into an LLMResponse.
type ReasoningDetail ¶
type ReasoningDetail = protocoltypes.ReasoningDetail
Re-export protocol types used across providers.
type ToolCall ¶
type ToolCall = protocoltypes.ToolCall
Re-export protocol types used across providers.
type ToolDefinition ¶
type ToolDefinition = protocoltypes.ToolDefinition
Re-export protocol types used across providers.
type ToolFunctionDefinition ¶
type ToolFunctionDefinition = protocoltypes.ToolFunctionDefinition
Re-export protocol types used across providers.
type UsageInfo ¶
type UsageInfo = protocoltypes.UsageInfo
Re-export protocol types used across providers.