oaistream

package
v1.30.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertMessages

func ConvertMessages(messages []chat.Message) []openai.ChatCompletionMessageParamUnion

ConvertMessages converts chat.Message slices to OpenAI message params. This is the base conversion without any provider-specific post-processing.

func ConvertMultiContent

func ConvertMultiContent(multiContent []chat.MessagePart) []openai.ChatCompletionContentPartUnionParam

ConvertMultiContent converts chat.MessagePart slices to OpenAI content parts.

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.

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