openai

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package openai provides an OpenAI LLM implementation using the Responses API.

This implementation is strictly aligned with ADK-Go's model architecture:

  • Uses OpenAI's new Responses API (/v1/responses)
  • Unified GenerateContent method with stream boolean
  • Returns iter.Seq2[*Response, error]
  • Uses StreamingAggregator for streaming with Partial flag
  • Proper handling of reasoning/thinking for o1/o3/o4/gpt-5 models

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is an OpenAI LLM implementation using the Responses API. Implements model.LLM interface aligned with ADK-Go.

func New

func New(cfg Config) (*Client, error)

New creates a new OpenAI client.

func (*Client) Close

func (c *Client) Close() error

Close releases resources.

func (*Client) GenerateContent

func (c *Client) GenerateContent(ctx context.Context, req *model.Request, stream bool) iter.Seq2[*model.Response, error]

GenerateContent produces responses for the given request. This is the ADK-Go aligned interface.

When stream=false:

  • Yields exactly one Response with complete content, Partial=false

When stream=true:

  • Yields multiple partial Responses (Partial=true) for real-time UI updates
  • Finally yields aggregated Response (Partial=false) for session persistence

func (*Client) Name

func (c *Client) Name() string

Name returns the model identifier.

func (*Client) Provider

func (c *Client) Provider() model.Provider

Provider returns the provider type.

type Config

type Config struct {
	APIKey              string
	Model               string
	MaxTokens           int
	Temperature         *float64
	BaseURL             string
	Timeout             time.Duration
	MaxRetries          int
	MaxToolOutputLength int
	EnableReasoning     bool
	ReasoningBudget     int // Maps to reasoning.effort: low/medium/high
}

Config configures the OpenAI client.

type Option

type Option func(*Config)

Option configures the OpenAI client.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL sets a custom base URL.

func WithMaxTokens

func WithMaxTokens(maxTokens int) Option

WithMaxTokens sets the maximum output tokens.

func WithModel

func WithModel(model string) Option

WithModel sets the model name.

func WithReasoning

func WithReasoning(budget int) Option

WithReasoning enables reasoning with the given budget.

func WithTemperature

func WithTemperature(temp float64) Option

WithTemperature sets the temperature.

Jump to

Keyboard shortcuts

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