openai

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package openai constructs native ADK models for OpenAI-compatible endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, cfg Config) (model.LLM, error)

New constructs a native ADK model from explicit OpenAI configuration.

func RawChatToolResult added in v0.1.2

func RawChatToolResult(value any) (map[string]any, error)

RawChatToolResult marks a JSON-compatible value for direct Chat Completions conversion or a bounded one-shot run. Responses and durable session persistence are unsupported and fail serialization closed.

Types

type ChatError

type ChatError struct {
	Kind ChatErrorKind
}

ChatError reports a Chat Completions compatibility failure without wire data.

func (*ChatError) Error

func (err *ChatError) Error() string

func (*ChatError) Is

func (err *ChatError) Is(target error) bool

Is matches Chat errors by kind.

type ChatErrorKind

type ChatErrorKind string

ChatErrorKind identifies a stable Chat Completions compatibility failure.

const (
	ChatErrorDuplicateToolCallID  ChatErrorKind = "duplicate_tool_call_id"
	ChatErrorEmptyChoices         ChatErrorKind = "empty_choices"
	ChatErrorInvalidToolResult    ChatErrorKind = "invalid_tool_result"
	ChatErrorMalformedArguments   ChatErrorKind = "malformed_arguments"
	ChatErrorMissingFunctionName  ChatErrorKind = "missing_function_name"
	ChatErrorMultipleChoices      ChatErrorKind = "multiple_choices"
	ChatErrorNilRequest           ChatErrorKind = "nil_request"
	ChatErrorUnsupportedContent   ChatErrorKind = "unsupported_content"
	ChatErrorUnsupportedStreaming ChatErrorKind = "unsupported_streaming"
	ChatErrorUnsupportedToolCall  ChatErrorKind = "unsupported_tool_call"
)

type ChatTokenLimitDialect

type ChatTokenLimitDialect string

ChatTokenLimitDialect selects the Chat Completions output-token field.

const (
	// ChatTokenLimitMaxTokens sends ADK MaxOutputTokens as max_tokens.
	ChatTokenLimitMaxTokens ChatTokenLimitDialect = "max_tokens"
	// ChatTokenLimitMaxCompletionTokens sends ADK MaxOutputTokens as max_completion_tokens.
	ChatTokenLimitMaxCompletionTokens ChatTokenLimitDialect = "max_completion_tokens"
)

type Config

type Config struct {
	Protocol         Protocol
	Model            string
	BaseURL          string
	APIKey           string
	HTTPClient       *http.Client
	MaxResponseBytes int64
	MaxRetries       int
	ChatTokenLimit   ChatTokenLimitDialect
}

Config contains the complete OpenAI model construction contract.

type Protocol

type Protocol string

Protocol selects the fixed OpenAI wire protocol used by a model.

const (
	// ProtocolResponses selects the OpenAI Responses API.
	ProtocolResponses Protocol = "responses"
	// ProtocolChatCompletions selects the OpenAI Chat Completions API.
	ProtocolChatCompletions Protocol = "chat_completions"
)

type ProtocolUnavailableError

type ProtocolUnavailableError struct {
	Protocol Protocol
}

ProtocolUnavailableError reports a recognized protocol whose implementation is not present.

func (*ProtocolUnavailableError) Error

func (err *ProtocolUnavailableError) Error() string

type RequestError

type RequestError struct {
	Failure    RequestFailure
	StatusCode int
	// contains filtered or unexported fields
}

RequestError reports a request failure without exposing provider, endpoint, or body text.

func (*RequestError) Error

func (err *RequestError) Error() string

func (*RequestError) Is

func (err *RequestError) Is(target error) bool

Is preserves matching for caller-owned transport and redirect-policy sentinels.

type RequestFailure

type RequestFailure string

RequestFailure classifies a redacted model request error.

const (
	// RequestFailureTransport identifies a caller HTTP policy or transport failure.
	RequestFailureTransport RequestFailure = "transport"
	// RequestFailureProvider identifies an HTTP error response from the provider.
	RequestFailureProvider RequestFailure = "provider"
	// RequestFailureResponse identifies an invalid or unreadable provider response.
	RequestFailureResponse RequestFailure = "response"
)

type ResponseTooLargeError

type ResponseTooLargeError struct {
	Limit int64
}

ResponseTooLargeError reports a decompressed response that crossed its configured limit.

func (*ResponseTooLargeError) Error

func (err *ResponseTooLargeError) Error() string

func (*ResponseTooLargeError) Is

func (err *ResponseTooLargeError) Is(target error) bool

Is allows errors.Is to classify all oversized OpenAI responses.

type ValidationError

type ValidationError struct {
	Field string
}

ValidationError reports one invalid construction field without including its value.

func (*ValidationError) Error

func (err *ValidationError) Error() string

Jump to

Keyboard shortcuts

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