openai

package
v1.7.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	MaxFunctionCalls   = 10
	OpenAIMaxImageSize = 20 * 1024 * 1024 // 20 MB
)

Variables

View Source
var ErrStreamingTimeout = errors.New("timeout streaming")

Functions

func FetchModels added in v1.7.0

func FetchModels(apiKey string, apiURL string, orgID string, httpClient *http.Client) ([]llm.ModelInfo, error)

FetchModels retrieves the list of available models from the OpenAI API

Types

type Config

type Config struct {
	APIKey               string        `json:"apiKey"`
	APIURL               string        `json:"apiURL"`
	OrgID                string        `json:"orgID"`
	DefaultModel         string        `json:"defaultModel"`
	InputTokenLimit      int           `json:"inputTokenLimit"`
	OutputTokenLimit     int           `json:"outputTokenLimit"`
	StreamingTimeout     time.Duration `json:"streamingTimeout"`
	SendUserID           bool          `json:"sendUserID"`
	EmbeddingModel       string        `json:"embeddingModel"`
	EmbeddingDimensions  int           `json:"embeddingDimensions"`
	UseResponsesAPI      bool          `json:"useResponsesAPI"`
	EnabledNativeTools   []string      `json:"enabledNativeTools"`
	ReasoningEnabled     bool          `json:"reasoningEnabled"`
	ReasoningEffort      string        `json:"reasoningEffort"`
	DisableStreamOptions bool          `json:"disableStreamOptions"` // For OpenAI-compatible APIs that don't support stream_options
	UseMaxTokens         bool          `json:"useMaxTokens"`         // Use max_tokens instead of max_completion_tokens for compatible APIs
}

type OpenAI

type OpenAI struct {
	// contains filtered or unexported fields
}

func New

func New(config Config, httpClient *http.Client) *OpenAI

func NewAzure

func NewAzure(config Config, httpClient *http.Client) *OpenAI

func NewCompatible

func NewCompatible(config Config, httpClient *http.Client) *OpenAI

func NewCompatibleEmbeddings

func NewCompatibleEmbeddings(config Config, httpClient *http.Client) *OpenAI

NewCompatibleEmbeddings creates a new OpenAI client configured only for embeddings functionality

func NewEmbeddings

func NewEmbeddings(config Config, httpClient *http.Client) *OpenAI

NewEmbeddings creates a new OpenAI client configured only for embeddings functionality

func (*OpenAI) BatchCreateEmbeddings

func (s *OpenAI) BatchCreateEmbeddings(ctx context.Context, texts []string) ([][]float32, error)

BatchCreateEmbeddings generates embeddings for multiple texts in a single API call

func (*OpenAI) ChatCompletion

func (s *OpenAI) ChatCompletion(request llm.CompletionRequest, opts ...llm.LanguageModelOption) (*llm.TextStreamResult, error)

func (*OpenAI) ChatCompletionNoStream

func (s *OpenAI) ChatCompletionNoStream(request llm.CompletionRequest, opts ...llm.LanguageModelOption) (string, error)

func (*OpenAI) CountTokens

func (s *OpenAI) CountTokens(text string) int

func (*OpenAI) CreateEmbedding

func (s *OpenAI) CreateEmbedding(ctx context.Context, text string) ([]float32, error)

func (*OpenAI) Dimensions

func (s *OpenAI) Dimensions() int

func (*OpenAI) GenerateImage

func (s *OpenAI) GenerateImage(prompt string) (image.Image, error)

func (*OpenAI) GetDefaultConfig

func (s *OpenAI) GetDefaultConfig() llm.LanguageModelConfig

func (*OpenAI) InputTokenLimit

func (s *OpenAI) InputTokenLimit() int

func (*OpenAI) Transcribe

func (s *OpenAI) Transcribe(file io.Reader) (*subtitles.Subtitles, error)

type ToolBufferElement

type ToolBufferElement struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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