openai

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleModels

func HandleModels(registry *ModelRegistry) http.HandlerFunc

HandleModels returns an http.HandlerFunc that lists all models. The response follows OpenAI's /v1/models format.

func HandleModelsFromConfig

func HandleModelsFromConfig(cfg *config.Config) http.HandlerFunc

HandleModelsFromConfig returns a handler that rebuilds the model list from config on each request, enabling hot-reload of model groups.

Types

type ChatMessage

type ChatMessage struct {
	Role       string          `json:"role"`
	Content    any             `json:"content"`
	ToolCalls  []flow.ToolCall `json:"tool_calls,omitempty"`
	Name       string          `json:"name,omitempty"`
	ToolCallID string          `json:"tool_call_id,omitempty"`
}

ChatMessage represents a single message in the conversation.

type ChatRequest

type ChatRequest struct {
	Model             string        `json:"model"`
	Messages          []ChatMessage `json:"messages"`
	Stream            *bool         `json:"stream,omitempty"`
	Temperature       *float64      `json:"temperature,omitempty"`
	TopP              *float64      `json:"top_p,omitempty"`
	MaxTokens         *int          `json:"max_tokens,omitempty"`
	Stop              []string      `json:"stop,omitempty"`
	PresencePenalty   *float64      `json:"presence_penalty,omitempty"`
	FrequencyPenalty  *float64      `json:"frequency_penalty,omitempty"`
	ReasoningEffort   string        `json:"reasoning_effort,omitempty"`
	Tools             []flow.Tool   `json:"tools,omitempty"`
	ToolChoice        any           `json:"tool_choice,omitempty"`
	ParallelToolCalls *bool         `json:"parallel_tool_calls,omitempty"`
	ImageConfig       *ImageConfig  `json:"image_config,omitempty"`
	VideoConfig       *VideoConfig  `json:"video_config,omitempty"`
}

ChatRequest represents an OpenAI-compatible chat completion request.

type Handler

type Handler struct {
	ChatFlow  *flow.ChatFlow
	VideoFlow *flow.VideoFlow
	ImageFlow *flow.ImageFlow
	Cfg       *config.Config
}

Handler holds dependencies for OpenAI-compatible API endpoints.

func (*Handler) SetupRoutes

func (h *Handler) SetupRoutes(r chi.Router)

SetupRoutes registers OpenAI-compatible API endpoints on the given router.

type ImageConfig

type ImageConfig struct {
	N              int    `json:"n,omitempty"`
	Size           string `json:"size,omitempty"`
	ResponseFormat string `json:"response_format,omitempty"`
	EnableNSFW     *bool  `json:"enable_nsfw,omitempty"`
}

ImageConfig controls image generation in chat multimodal mode.

type ModelEntry

type ModelEntry struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	OwnedBy string `json:"owned_by"`
}

ModelEntry represents a single model in the OpenAI models list.

type ModelInfo

type ModelInfo struct {
	ID      string
	Object  string
	Created int64
	OwnedBy string
}

ModelInfo holds model metadata.

type ModelRegistry

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

ModelRegistry holds available models.

func NewModelRegistry

func NewModelRegistry() *ModelRegistry

NewModelRegistry creates an empty model registry.

func NewModelRegistryFromConfig

func NewModelRegistryFromConfig(cfg *config.TokenConfig) *ModelRegistry

NewModelRegistryFromConfig builds a model registry from config. Model entries with "#N" cost suffixes are stripped to expose clean model IDs.

func (*ModelRegistry) Add

func (r *ModelRegistry) Add(info ModelInfo)

Add adds a model to the registry.

func (*ModelRegistry) All

func (r *ModelRegistry) All() []ModelInfo

All returns all models in the registry.

type ModelsResponse

type ModelsResponse struct {
	Object string       `json:"object"`
	Data   []ModelEntry `json:"data"`
}

ModelsResponse is the OpenAI models list response.

type VideoConfig

type VideoConfig struct {
	AspectRatio    string `json:"aspect_ratio,omitempty"`
	VideoLength    int    `json:"video_length,omitempty"`
	ResolutionName string `json:"resolution_name,omitempty"`
	Preset         string `json:"preset,omitempty"`
}

VideoConfig controls video generation in chat mode.

Jump to

Keyboard shortcuts

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