common

package
v0.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package common provides shared utilities used by multiple LLM provider implementations (openai_compat, azure, etc.).

Index

Constants

View Source
const DefaultRequestTimeout = 120 * time.Second

Variables

This section is empty.

Functions

func AsFloat

func AsFloat(v any) (float64, bool)

AsFloat converts various numeric types to float64.

func AsInt

func AsInt(v any) (int, bool)

AsInt converts various numeric types to int.

func DecodeToolCallArguments

func DecodeToolCallArguments(raw json.RawMessage, name string) map[string]any

DecodeToolCallArguments decodes a tool call's arguments from raw JSON.

func HandleErrorResponse

func HandleErrorResponse(resp *http.Response, apiBase string) error

HandleErrorResponse reads a non-200 response body and returns an appropriate error.

func LooksLikeHTML

func LooksLikeHTML(body []byte, contentType string) bool

LooksLikeHTML checks if the response body appears to be HTML.

func NewHTTPClient

func NewHTTPClient(proxy string) *http.Client

NewHTTPClient creates an *http.Client with an optional proxy and the default timeout.

func ResponsePreview

func ResponsePreview(body []byte, maxLen int) string

ResponsePreview returns a truncated preview of response body for error messages.

func SerializeMessages

func SerializeMessages(messages []Message) []any

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

func WrapHTMLResponseError

func WrapHTMLResponseError(statusCode int, body []byte, contentType, apiBase string) error

WrapHTMLResponseError creates a descriptive error for HTML responses.

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 Message

type Message = protocoltypes.Message

Re-export protocol types used across providers.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL