openai

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatCompletion

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

ChatCompletion implements model.LLM using the OpenAI Chat Completions API.

func New

func New(apiKey, baseURL, modelName string, retryCfg ...retry.Config) *ChatCompletion

New creates a new ChatCompletion instance. apiKey is required. baseURL is optional; when non-empty it overrides the default OpenAI endpoint, which allows using any OpenAI-compatible provider. retryCfg is optional; when provided it enables automatic retry with exponential backoff on transient errors (rate limits, 5xx, network issues).

func NewWithOptions added in v0.0.7

func NewWithOptions(apiKey, baseURL, modelName string, opts ...Option) *ChatCompletion

NewWithOptions creates a new ChatCompletion instance with explicit provider compatibility, retry, and generation options.

func (*ChatCompletion) GenerateContent

func (c *ChatCompletion) GenerateContent(ctx context.Context, req *model.LLMRequest, cfg *model.GenerateConfig, stream bool) iter.Seq2[*model.LLMResponse, error]

GenerateContent sends the request to the OpenAI Chat Completions API. When stream is false, exactly one complete *model.LLMResponse is yielded. When stream is true, partial text chunks are yielded (Partial=true) followed by the assembled complete response (Partial=false, TurnComplete=true). Transient errors are automatically retried according to the retry.Config provided at construction time.

func (*ChatCompletion) Name

func (c *ChatCompletion) Name() string

Name returns the model identifier.

type Option added in v0.0.7

type Option func(*ChatCompletion)

Option configures a ChatCompletion instance.

func WithDeepSeekCompatibility added in v0.0.7

func WithDeepSeekCompatibility() Option

WithDeepSeekCompatibility configures ChatCompletion for DeepSeek's OpenAI-compatible Chat Completions API.

func WithReasoningEffort added in v0.0.7

func WithReasoningEffort(effort ReasoningEffort) Option

WithReasoningEffort sets OpenAI-compatible reasoning effort for every call.

func WithRetryConfig added in v0.0.7

func WithRetryConfig(cfg retry.Config) Option

WithRetryConfig sets the retry behavior for transient API errors.

func WithServiceTier added in v0.0.7

func WithServiceTier(tier ServiceTier) Option

WithServiceTier sets the OpenAI-compatible service tier for every call.

func WithThinkingEnabled added in v0.0.7

func WithThinkingEnabled(enabled bool) Option

WithThinkingEnabled explicitly enables or disables provider-specific thinking controls for every call. A disabled value maps to reasoning_effort "none" for providers that do not expose a separate thinking toggle.

type ReasoningEffort added in v0.0.7

type ReasoningEffort string

ReasoningEffort controls OpenAI-compatible reasoning effort.

const (
	// ReasoningEffortNone disables reasoning effort when supported by the provider.
	ReasoningEffortNone ReasoningEffort = "none"
	// ReasoningEffortMinimal requests minimal reasoning effort.
	ReasoningEffortMinimal ReasoningEffort = "minimal"
	// ReasoningEffortLow requests low reasoning effort.
	ReasoningEffortLow ReasoningEffort = "low"
	// ReasoningEffortMedium requests medium reasoning effort.
	ReasoningEffortMedium ReasoningEffort = "medium"
	// ReasoningEffortHigh requests high reasoning effort.
	ReasoningEffortHigh ReasoningEffort = "high"
	// ReasoningEffortXhigh requests extra-high reasoning effort on compatible providers.
	ReasoningEffortXhigh ReasoningEffort = "xhigh"
)

type Responses added in v0.0.9

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

Responses implements model.LLM using the OpenAI Responses API.

By default it sends the full ADK-provided history on every request with store=false, preserving ADK's own session ledger as the source of truth.

func NewResponses added in v0.0.9

func NewResponses(apiKey, baseURL, modelName string, retryCfg ...retry.Config) *Responses

NewResponses creates a new Responses instance. apiKey is required. baseURL is optional; when non-empty it overrides the default OpenAI endpoint. retryCfg is optional; when provided it enables automatic retry with exponential backoff on transient errors.

func NewResponsesWithOptions added in v0.0.9

func NewResponsesWithOptions(apiKey, baseURL, modelName string, opts ...ResponsesOption) *Responses

NewResponsesWithOptions creates a new Responses instance with explicit retry and generation options.

func (*Responses) GenerateContent added in v0.0.9

func (r *Responses) GenerateContent(ctx context.Context, req *model.LLMRequest, cfg *model.GenerateConfig, stream bool) iter.Seq2[*model.LLMResponse, error]

GenerateContent sends the request to the OpenAI Responses API. When stream is false, exactly one complete *model.LLMResponse is yielded. When stream is true, partial text chunks are yielded (Partial=true) followed by the assembled complete response (Partial=false, TurnComplete=true). Transient errors are automatically retried according to the retry.Config provided at construction time.

func (*Responses) Name added in v0.0.9

func (r *Responses) Name() string

Name returns the model identifier.

type ResponsesOption added in v0.0.9

type ResponsesOption func(*Responses)

ResponsesOption configures a Responses instance.

func WithResponsesReasoningEffort added in v0.0.9

func WithResponsesReasoningEffort(effort ReasoningEffort) ResponsesOption

WithResponsesReasoningEffort sets OpenAI Responses reasoning effort for every call.

func WithResponsesRetryConfig added in v0.0.9

func WithResponsesRetryConfig(cfg retry.Config) ResponsesOption

WithResponsesRetryConfig sets the retry behavior for transient API errors.

func WithResponsesServiceTier added in v0.0.9

func WithResponsesServiceTier(tier ServiceTier) ResponsesOption

WithResponsesServiceTier sets the OpenAI Responses service tier for every call.

func WithResponsesStore added in v0.0.9

func WithResponsesStore(store bool) ResponsesOption

WithResponsesStore controls whether OpenAI stores generated responses for later retrieval. The default is false so ADK remains the state owner.

func WithResponsesThinkingEnabled added in v0.0.9

func WithResponsesThinkingEnabled(enabled bool) ResponsesOption

WithResponsesThinkingEnabled controls OpenAI Responses reasoning for every call. Disabling maps to reasoning effort "none"; enabling leaves the effort level to the provider unless WithResponsesReasoningEffort is also set.

type ServiceTier added in v0.0.7

type ServiceTier string

ServiceTier specifies the OpenAI-compatible service tier for a request.

const (
	// ServiceTierAuto lets the provider choose the service tier.
	ServiceTierAuto ServiceTier = "auto"
	// ServiceTierDefault uses the provider default service tier.
	ServiceTierDefault ServiceTier = "default"
	// ServiceTierFlex uses the flex service tier.
	ServiceTierFlex ServiceTier = "flex"
	// ServiceTierScale uses the scale service tier.
	ServiceTierScale ServiceTier = "scale"
	// ServiceTierPriority uses the priority service tier.
	ServiceTierPriority ServiceTier = "priority"
)

Jump to

Keyboard shortcuts

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