openai

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatResponse

type ChatResponse struct {
	Message   string
	Reasoning string // Reasoning/thinking content
	ToolCalls []FunctionCallData
}

ChatResponse represents the response from a chat completion

type Client

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

Client is a custom OpenAI/OpenRouter client

func NewClient

func NewClient() (*Client, error)

NewClient creates a new client from environment variables

func NewClientWithConfig

func NewClientWithConfig(apiKey, model, baseURL string) (*Client, error)

NewClientWithConfig creates a new client with explicit configuration

func (*Client) Chat

func (c *Client) Chat(messages []Message, tools []Tool) (*ChatResponse, *TokenUsage, error)

Chat sends a non-streaming chat request

func (*Client) ChatStream

func (c *Client) ChatStream(messages []Message, tools []Tool, thinkingEnabled bool, callback StreamCallback) (*ChatResponse, *TokenUsage, error)

ChatStream sends a streaming chat request

type FunctionCallData

type FunctionCallData struct {
	ID   string
	Name string
	Args map[string]interface{}
}

FunctionCallData represents a function/tool call

type FunctionResponseData

type FunctionResponseData struct {
	ID       string // tool_call_id from the original tool call block
	Name     string
	Response map[string]interface{}
}

FunctionResponseData represents a function/tool response

type Message

type Message struct {
	Role             string
	Content          string
	FunctionResponse *FunctionResponseData
	FunctionCalls    []FunctionCallData
}

Message represents a chat message

type OpenAIProvider

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

OpenAIProvider implements common.Provider for OpenAI/OpenRouter

func NewOpenAIProvider

func NewOpenAIProvider(config common.ProviderConfig) (*OpenAIProvider, error)

NewOpenAIProvider creates a new OpenAI/OpenRouter provider

func (*OpenAIProvider) Chat

func (p *OpenAIProvider) Chat(messages []common.Message, tools []common.Tool, thinkingEnabled bool) (*common.ChatResponse, error)

Chat sends a non-streaming chat request

func (*OpenAIProvider) ChatStream

func (p *OpenAIProvider) ChatStream(messages []common.Message, tools []common.Tool, thinkingEnabled bool, callback common.StreamCallback) (*common.ChatResponse, error)

ChatStream sends a streaming chat request

func (*OpenAIProvider) Close

func (p *OpenAIProvider) Close() error

Close closes any resources

type StreamCallback

type StreamCallback func(chunk string, isThought bool)

StreamCallback is called for each chunk as it's streamed isThought indicates if this chunk is reasoning/thinking (true) or regular content (false)

type TokenUsage

type TokenUsage struct {
	InputTokens  int64
	OutputTokens int64
}

TokenUsage represents token usage information

type Tool

type Tool struct {
	Name        string
	Description string
	InputSchema map[string]interface{}
}

Tool represents a tool/function definition

Jump to

Keyboard shortcuts

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