Documentation
¶
Index ¶
- func ConvertMessages(ctx context.Context, messages []chat.Message, modelID string) []openai.ChatCompletionMessageParamUnion
- func ConvertMultiContent(ctx context.Context, multiContent []chat.MessagePart, modelID string) []openai.ChatCompletionContentPartUnionParam
- func ErrorBodyMiddleware() option.Middleware
- func MergeConsecutiveMessages(openaiMessages []openai.ChatCompletionMessageParamUnion) []openai.ChatCompletionMessageParamUnion
- func WrapOpenAIError(err error) error
- type JSONSchema
- type StreamAdapter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertMessages ¶
func ConvertMessages(ctx context.Context, messages []chat.Message, modelID string) []openai.ChatCompletionMessageParamUnion
ConvertMessages converts chat.Message slices to OpenAI message params. ctx is forwarded to convertDocument for logging and cancellation support. modelID is forwarded to convertDocument for attachment capability lookups. This is the base conversion without any provider-specific post-processing.
func ConvertMultiContent ¶
func ConvertMultiContent(ctx context.Context, multiContent []chat.MessagePart, modelID string) []openai.ChatCompletionContentPartUnionParam
ConvertMultiContent converts chat.MessagePart slices to OpenAI content parts. ctx is forwarded to convertDocument for logging and future cancellation support. modelID is used for attachment capability lookups; pass an empty string to skip capability checks (all documents are attempted).
func ErrorBodyMiddleware ¶
func ErrorBodyMiddleware() option.Middleware
ErrorBodyMiddleware returns an OpenAI SDK middleware that preserves full error details in HTTP error responses.
The OpenAI SDK extracts only the "error" field from error response bodies (via gjson). When a provider returns a body without an "error" object (e.g. a string "error" field, plain text, or a different JSON structure), the details are silently lost. This middleware rewrites such responses into {"error": <original body>} so the SDK preserves the full content.
func MergeConsecutiveMessages ¶
func MergeConsecutiveMessages(openaiMessages []openai.ChatCompletionMessageParamUnion) []openai.ChatCompletionMessageParamUnion
MergeConsecutiveMessages merges consecutive system or user messages into single messages. This is needed by some local models (like those run by DMR) that don't handle consecutive same-role messages well.
func WrapOpenAIError ¶ added in v1.32.3
WrapOpenAIError wraps an OpenAI SDK error in a *modelerrors.StatusError to carry HTTP status code and Retry-After metadata for the retry loop. Non-OpenAI errors (e.g. io.EOF, network errors) pass through unchanged. Exported so openai/response_stream.go can reuse it without duplication.
Types ¶
type JSONSchema ¶
JSONSchema is a helper type that implements json.Marshaler for map[string]any. This allows us to pass schema maps to the OpenAI library which expects json.Marshaler.
func (JSONSchema) MarshalJSON ¶
func (j JSONSchema) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler for JSONSchema.
type StreamAdapter ¶
type StreamAdapter struct {
// contains filtered or unexported fields
}
StreamAdapter adapts the OpenAI stream to our interface
func NewStreamAdapter ¶
func NewStreamAdapter(stream *ssestream.Stream[openai.ChatCompletionChunk], trackUsage bool) *StreamAdapter
func (*StreamAdapter) Recv ¶
func (a *StreamAdapter) Recv() (chat.MessageStreamResponse, error)
Recv gets the next completion chunk