oaistream

package
v1.58.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertMessagesFromStore added in v1.58.0

func ConvertMessagesFromStore(ctx context.Context, messages []chat.Message, modelID string, store *modelsdev.Store) []openai.ChatCompletionMessageParamUnion

ConvertMessagesFromStore converts chat.Message slices to OpenAI message params using the provided modelsdev.Store for capability lookups.

func ConvertMultiContentFromStore added in v1.58.0

func ConvertMultiContentFromStore(ctx context.Context, multiContent []chat.MessagePart, modelID string, store *modelsdev.Store) []openai.ChatCompletionContentPartUnionParam

ConvertMultiContentFromStore converts chat.MessagePart slices to OpenAI content parts using the provided modelsdev.Store for capability lookups.

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

func WrapOpenAIError(err error) error

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

type JSONSchema map[string]any

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) Close

func (a *StreamAdapter) Close()

Close closes the stream

func (*StreamAdapter) Recv

Recv gets the next completion chunk

Jump to

Keyboard shortcuts

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