openai

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheControl

type CacheControl struct {
	Type string `json:"type"`
}

type ChatCompletionChoice

type ChatCompletionChoice struct {
	Message ChatCompletionMessage `json:"message"`
}

type ChatCompletionMessage

type ChatCompletionMessage struct {
	Role             string          `json:"role"`
	Content          any             `json:"content,omitempty"`
	Reasoning        *string         `json:"reasoning,omitempty"`         // OpenRouter
	ReasoningContent *string         `json:"reasoning_content,omitempty"` // Deepseek, llama-server
	ReasoningDetails json.RawMessage `json:"reasoning_details,omitempty"` // OpenRouter preserved thinking
	ToolCalls        []ToolCall      `json:"tool_calls,omitempty"`
	ToolCallID       string          `json:"tool_call_id,omitempty"`
}

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model               string                  `json:"model"`
	MaxTokens           int                     `json:"max_tokens,omitempty"`
	MaxCompletionTokens int                     `json:"max_completion_tokens,omitempty"`
	Temperature         float32                 `json:"temperature,omitempty"`
	Messages            []ChatCompletionMessage `json:"messages"`
	N                   int                     `json:"n"`
	Tools               []Tool                  `json:"tools,omitempty"`
	ToolChoice          string                  `json:"tool_choice,omitempty"`
	Stream              bool                    `json:"stream,omitempty"`
	// Reasoning config. TBD: handle for mulitple providers using the same field
	Reasoning *OpenRouterReasoning `json:"reasoning,omitempty"`
	// CacheControl for OpenRouter
	CacheControl *CacheControl `json:"cache_control,omitempty"`
	// Thinking config for ZAI
	Thinking *ZAIThinking `json:"thinking,omitempty"`
}

type ChatCompletionResponse

type ChatCompletionResponse struct {
	Choices []ChatCompletionChoice `json:"choices"`
}

type ChatCompletionStreamChoice

type ChatCompletionStreamChoice struct {
	Delta ChatCompletionMessage `json:"delta"`
}

type ChatCompletionStreamResponse

type ChatCompletionStreamResponse struct {
	Choices []ChatCompletionStreamChoice `json:"choices"`
}

type FunctionDefinition

type FunctionDefinition struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Parameters  ToolParameters `json:"parameters"`
	Arguments   string         `json:"arguments,omitempty"`
}

type Items

type Items struct {
	Type string `json:"type"`
}

type OpenAIClient

type OpenAIClient struct {
	APIKey  string
	BaseURL string
	Headers map[string]string
	Style   string
}

func (*OpenAIClient) CreateChatCompletion

func (c *OpenAIClient) CreateChatCompletion(
	ctx context.Context,
	params api.RequestParameters,
	messages []api.Message,
) (*api.Message, error)

func (*OpenAIClient) CreateChatCompletionStream

func (c *OpenAIClient) CreateChatCompletionStream(
	ctx context.Context,
	params api.RequestParameters,
	messages []api.Message,
	output func(api.Chunk),
) (*api.Message, error)

type OpenRouterReasoning

type OpenRouterReasoning struct {
	Effort  api.ReasoningEffort `json:"effort,omitempty"` // "xhigh", "high", "medium", "low", "minimal", "none"
	Summary ReasoningDetail     `json:"summary,omitempty"`
}

type ProviderStyle

type ProviderStyle string

ProviderStyle distinguishes OpenAI-compatible API variants.

const (
	StyleOpenAI     ProviderStyle = "openai"
	StyleOpenRouter ProviderStyle = "openrouter"
	StyleZAI        ProviderStyle = "zai"
)

type ReasoningDetail

type ReasoningDetail string
const (
	Auto     ReasoningDetail = "auto"
	Concise  ReasoningDetail = "concise"
	Detailed ReasoningDetail = "detailed"
)

type Tool

type Tool struct {
	Type     string             `json:"type"`
	Function FunctionDefinition `json:"function"`
}

type ToolCall

type ToolCall struct {
	Type     string             `json:"type"`
	ID       string             `json:"id"`
	Index    *int               `json:"index,omitempty"`
	Function FunctionDefinition `json:"function"`
}

type ToolParameter

type ToolParameter struct {
	Type        string   `json:"type"`
	Description string   `json:"description"`
	Enum        []string `json:"enum,omitempty"`
	Items       *Items   `json:"items,omitempty"`
}

type ToolParameters

type ToolParameters struct {
	Type       string                   `json:"type"`
	Properties map[string]ToolParameter `json:"properties,omitempty"`
	Required   []string                 `json:"required,omitempty"`
}

type ZAIThinking

type ZAIThinking struct {
	ClearThinking bool `json:"clear_thinking"`
}

Jump to

Keyboard shortcuts

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