Documentation
¶
Index ¶
- Constants
- Variables
- func BuildOpenAIResponsesParams(model Model[API], modelContext ModelContext, options *OpenAIResponseOptions) (responses.ResponseNewParams, error)
- func CleanupSessionResources(sessionID *string) error
- func ClearApiProviders()
- func ConvertResponsesMessages(model Model[API], modelContext ModelContext, providers map[Provider]struct{}, ...) (responses.ResponseInputParam, error)
- func ConvertResponsesTools(tools []*Tool, options *ConvertResponsesToolsOptions) ([]responses.ToolUnionParam, error)
- func CreateOpenAIResponsesClient(model Model[API], modelContext ModelContext, apiKey *string, ...) (openai.Client, error)
- func EncodeTextSignatureV1(id string, phase *TextSignaturePhase) string
- func GetPromptCacheRetention(compat ResolvedOpenAIResponsesCompat, cacheRetention CacheRetention) responses.ResponseNewParamsPromptCacheRetention
- func ModelsAreEqual[TApi API](a *Model[TApi], b *Model[TApi]) bool
- func RegisterApiProvider[TApi API](provider ApiProvider[TApi, StreamOptions], sourceID *string)
- func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()
- func UnregisterApiProvider(sourceID string)
- func ValidateToolArguments(tool Tool, toolCall ToolCall) (any, error)
- func ValidateToolCall(tools []*Tool, toolCall ToolCall) (any, error)
- type API
- type ApiProvider
- type ApiProviderInternal
- type ApiStreamFunction
- type ApiStreamSimpleFunction
- type AssistantContent
- type AssistantMessage
- type AssistantMessageDiagnostic
- type AssistantMessageEvent
- type AssistantMessageEventStream
- func NewAssistantMessageEventStream(buffer int) *AssistantMessageEventStream
- func Stream(model Model[API], modelContext ModelContext, options *StreamOptions) (*AssistantMessageEventStream, error)
- func StreamOpenAIResponse(ctx context.Context, model Model[API], modelContext ModelContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimple(model Model[API], modelContext ModelContext, options *SimpleStreamOptions) (*AssistantMessageEventStream, error)
- func StreamSimpleOpenAIResponses(model Model[API], modelContext ModelContext, options *SimpleStreamOptions) (*AssistantMessageEventStream, error)
- type AssistantMessageEventType
- type CacheRetention
- type ContentType
- type ConvertResponseMessagesOptions
- type ConvertResponsesToolsOptions
- type Cost
- type DiagnosticErrorInfo
- type DoneEvent
- type ErrorEvent
- type EventStream
- type ImageContent
- type Message
- type Model
- type ModelContext
- type ModelThinkingLevel
- type OpenAIResponseOptions
- type OpenAIResponsesCompat
- type ParsedTextSignature
- type Provider
- type ProviderResponse
- type RegisteredApiProvider
- type ResolvedOpenAIResponsesCompat
- type Role
- type SessionResourceCleanup
- type SimpleStreamOptions
- type StartEvent
- type StopReason
- type StreamFunction
- type StreamOptions
- type TextContent
- type TextDeltaEvent
- type TextEndEvent
- type TextSignaturePhase
- type TextStartEvent
- type ThinkingBudgets
- type ThinkingContent
- type ThinkingDeltaEvent
- type ThinkingEndEvent
- type ThinkingLevelMap
- type ThinkingStartEvent
- type Tool
- type ToolCall
- type ToolCallDeltaEvent
- type ToolCallEndEvent
- type ToolCallStartEvent
- type ToolResultContent
- type ToolResultMessage
- type Transport
- type Usage
- type UserContent
- type UserMessage
Constants ¶
View Source
const NonVisionToolImagePlaceholder = "(tool image omitted: model does not support images)"
View Source
const NonVisionUserImagePlaceholder = "(image omitted: model does not support images)"
Variables ¶
View Source
var Models = map[Provider]map[string]Model[API]{ ProviderOpenAI: { "gpt-4": { ID: "gpt-4", Name: "GPT-4", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text"}, Cost: Cost{ Input: decimal.MustParse("30"), Output: decimal.MustParse("60"), CacheRead: decimal.MustParse("0"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 8192, MaxTokens: 8192, }, "gpt-4-turbo": { ID: "gpt-4-turbo", Name: "GPT-4 Turbo", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("10"), Output: decimal.MustParse("30"), CacheRead: decimal.MustParse("0"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 4096, }, "gpt-4.1": { ID: "gpt-4.1", Name: "GPT-4.1", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("2"), Output: decimal.MustParse("8"), CacheRead: decimal.MustParse("0.5"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 1047576, MaxTokens: 32768, }, "gpt-4.1-mini": { ID: "gpt-4.1-mini", Name: "GPT-4.1 mini", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("0.4"), Output: decimal.MustParse("1.6"), CacheRead: decimal.MustParse("0.1"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 1047576, MaxTokens: 32768, }, "gpt-4.1-nano": { ID: "gpt-4.1-nano", Name: "GPT-4.1 nano", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("0.1"), Output: decimal.MustParse("0.4"), CacheRead: decimal.MustParse("0.03"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 1047576, MaxTokens: 32768, }, "gpt-4o": { ID: "gpt-4o", Name: "GPT-4o", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("2.5"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("1.25"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 16384, }, "gpt-4o-2024-05-13": { ID: "gpt-4o-2024-05-13", Name: "GPT-4o (2024-05-13)", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("5"), Output: decimal.MustParse("15"), CacheRead: decimal.MustParse("0"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 4096, }, "gpt-4o-2024-08-06": { ID: "gpt-4o-2024-08-06", Name: "GPT-4o (2024-08-06)", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("2.5"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("1.25"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 16384, }, "gpt-4o-2024-11-20": { ID: "gpt-4o-2024-11-20", Name: "GPT-4o (2024-11-20)", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("2.5"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("1.25"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 16384, }, "gpt-4o-mini": { ID: "gpt-4o-mini", Name: "GPT-4o mini", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("0.15"), Output: decimal.MustParse("0.6"), CacheRead: decimal.MustParse("0.08"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 16384, }, "gpt-5": { ID: "gpt-5", Name: "GPT-5", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.25"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("0.125"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5-chat-latest": { ID: "gpt-5-chat-latest", Name: "GPT-5 Chat Latest", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.25"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("0.125"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 16384, }, "gpt-5-codex": { ID: "gpt-5-codex", Name: "GPT-5-Codex", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.25"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("0.125"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5-mini": { ID: "gpt-5-mini", Name: "GPT-5 Mini", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("0.25"), Output: decimal.MustParse("2"), CacheRead: decimal.MustParse("0.025"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5-nano": { ID: "gpt-5-nano", Name: "GPT-5 Nano", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("0.05"), Output: decimal.MustParse("0.4"), CacheRead: decimal.MustParse("0.005"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5-pro": { ID: "gpt-5-pro", Name: "GPT-5 Pro", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("15"), Output: decimal.MustParse("120"), CacheRead: decimal.MustParse("0"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 272000, }, "gpt-5.1": { ID: "gpt-5.1", Name: "GPT-5.1", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.25"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("0.13"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.1-chat-latest": { ID: "gpt-5.1-chat-latest", Name: "GPT-5.1 Chat", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.25"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("0.125"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 16384, }, "gpt-5.1-codex": { ID: "gpt-5.1-codex", Name: "GPT-5.1 Codex", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.25"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("0.125"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.1-codex-max": { ID: "gpt-5.1-codex-max", Name: "GPT-5.1 Codex Max", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.25"), Output: decimal.MustParse("10"), CacheRead: decimal.MustParse("0.125"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.1-codex-mini": { ID: "gpt-5.1-codex-mini", Name: "GPT-5.1 Codex mini", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("0.25"), Output: decimal.MustParse("2"), CacheRead: decimal.MustParse("0.025"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.2": { ID: "gpt-5.2", Name: "GPT-5.2", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.75"), Output: decimal.MustParse("14"), CacheRead: decimal.MustParse("0.175"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.2-chat-latest": { ID: "gpt-5.2-chat-latest", Name: "GPT-5.2 Chat", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.75"), Output: decimal.MustParse("14"), CacheRead: decimal.MustParse("0.175"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 16384, }, "gpt-5.2-codex": { ID: "gpt-5.2-codex", Name: "GPT-5.2 Codex", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.75"), Output: decimal.MustParse("14"), CacheRead: decimal.MustParse("0.175"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.2-pro": { ID: "gpt-5.2-pro", Name: "GPT-5.2 Pro", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("21"), Output: decimal.MustParse("168"), CacheRead: decimal.MustParse("0"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.3-chat-latest": { ID: "gpt-5.3-chat-latest", Name: "GPT-5.3 Chat (latest)", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: false, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.75"), Output: decimal.MustParse("14"), CacheRead: decimal.MustParse("0.175"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 16384, }, "gpt-5.3-codex": { ID: "gpt-5.3-codex", Name: "GPT-5.3 Codex", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.75"), Output: decimal.MustParse("14"), CacheRead: decimal.MustParse("0.175"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.3-codex-spark": { ID: "gpt-5.3-codex-spark", Name: "GPT-5.3 Codex Spark", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.75"), Output: decimal.MustParse("14"), CacheRead: decimal.MustParse("0.175"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 128000, MaxTokens: 32000, }, "gpt-5.4": { ID: "gpt-5.4", Name: "GPT-5.4", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("2.5"), Output: decimal.MustParse("15"), CacheRead: decimal.MustParse("0.25"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 272000, MaxTokens: 128000, }, "gpt-5.4-mini": { ID: "gpt-5.4-mini", Name: "GPT-5.4 mini", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("0.75"), Output: decimal.MustParse("4.5"), CacheRead: decimal.MustParse("0.075"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.4-nano": { ID: "gpt-5.4-nano", Name: "GPT-5.4 nano", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("0.2"), Output: decimal.MustParse("1.25"), CacheRead: decimal.MustParse("0.02"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 400000, MaxTokens: 128000, }, "gpt-5.4-pro": { ID: "gpt-5.4-pro", Name: "GPT-5.4 Pro", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("30"), Output: decimal.MustParse("180"), CacheRead: decimal.MustParse("0"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 1050000, MaxTokens: 128000, }, "gpt-5.5": { ID: "gpt-5.5", Name: "GPT-5.5", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("5"), Output: decimal.MustParse("30"), CacheRead: decimal.MustParse("0.5"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 272000, MaxTokens: 128000, }, "gpt-5.5-pro": { ID: "gpt-5.5-pro", Name: "GPT-5.5 Pro", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, ThinkingLevelMap: ThinkingLevelMap{ ThinkingLevelOff: nil, ThinkingLevelXHigh: modelThinkingLevel("xhigh"), }, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("30"), Output: decimal.MustParse("180"), CacheRead: decimal.MustParse("0"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 1050000, MaxTokens: 128000, }, "o1": { ID: "o1", Name: "o1", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("15"), Output: decimal.MustParse("60"), CacheRead: decimal.MustParse("7.5"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 200000, MaxTokens: 100000, }, "o1-pro": { ID: "o1-pro", Name: "o1-pro", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("150"), Output: decimal.MustParse("600"), CacheRead: decimal.MustParse("0"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 200000, MaxTokens: 100000, }, "o3": { ID: "o3", Name: "o3", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("2"), Output: decimal.MustParse("8"), CacheRead: decimal.MustParse("0.5"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 200000, MaxTokens: 100000, }, "o3-deep-research": { ID: "o3-deep-research", Name: "o3-deep-research", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("10"), Output: decimal.MustParse("40"), CacheRead: decimal.MustParse("2.5"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 200000, MaxTokens: 100000, }, "o3-mini": { ID: "o3-mini", Name: "o3-mini", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, Input: []string{"text"}, Cost: Cost{ Input: decimal.MustParse("1.1"), Output: decimal.MustParse("4.4"), CacheRead: decimal.MustParse("0.55"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 200000, MaxTokens: 100000, }, "o3-pro": { ID: "o3-pro", Name: "o3-pro", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("20"), Output: decimal.MustParse("80"), CacheRead: decimal.MustParse("0"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 200000, MaxTokens: 100000, }, "o4-mini": { ID: "o4-mini", Name: "o4-mini", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("1.1"), Output: decimal.MustParse("4.4"), CacheRead: decimal.MustParse("0.28"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 200000, MaxTokens: 100000, }, "o4-mini-deep-research": { ID: "o4-mini-deep-research", Name: "o4-mini-deep-research", API: APIOpenAIResponses, Provider: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", Reasoning: true, Input: []string{"text", "image"}, Cost: Cost{ Input: decimal.MustParse("2"), Output: decimal.MustParse("8"), CacheRead: decimal.MustParse("0.5"), CacheWrite: decimal.MustParse("0"), }, ContextWindow: 200000, MaxTokens: 100000, }, }, }
View Source
var OpenAIToolCallProviders = map[Provider]struct{}{
ProviderOpenAI: {},
}
Functions ¶
func BuildOpenAIResponsesParams ¶
func BuildOpenAIResponsesParams( model Model[API], modelContext ModelContext, options *OpenAIResponseOptions, ) (responses.ResponseNewParams, error)
func CleanupSessionResources ¶
func ClearApiProviders ¶
func ClearApiProviders()
func ConvertResponsesMessages ¶
func ConvertResponsesMessages(model Model[API], modelContext ModelContext, providers map[Provider]struct{}, options ConvertResponseMessagesOptions) (responses.ResponseInputParam, error)
func ConvertResponsesTools ¶
func ConvertResponsesTools( tools []*Tool, options *ConvertResponsesToolsOptions, ) ([]responses.ToolUnionParam, error)
func EncodeTextSignatureV1 ¶
func EncodeTextSignatureV1(id string, phase *TextSignaturePhase) string
func GetPromptCacheRetention ¶
func GetPromptCacheRetention( compat ResolvedOpenAIResponsesCompat, cacheRetention CacheRetention, ) responses.ResponseNewParamsPromptCacheRetention
func RegisterApiProvider ¶
func RegisterApiProvider[TApi API](provider ApiProvider[TApi, StreamOptions], sourceID *string)
func RegisterSessionResourceCleanup ¶
func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()
func UnregisterApiProvider ¶
func UnregisterApiProvider(sourceID string)
func ValidateToolArguments ¶
ValidateToolArguments validates tool call arguments against the tool's JSON schema.
Types ¶
type ApiProvider ¶
type ApiProvider[TApi API, TOptions any] struct { Api TApi Stream StreamFunction[TApi, TOptions] StreamSimple StreamFunction[TApi, SimpleStreamOptions] }
type ApiProviderInternal ¶
type ApiProviderInternal struct {
Api API
Stream ApiStreamFunction
StreamSimple ApiStreamSimpleFunction
}
func GetApiProvider ¶
func GetApiProvider(api API) (ApiProviderInternal, bool)
func GetApiProviders ¶
func GetApiProviders() []ApiProviderInternal
func ResolveAPIProvider ¶
func ResolveAPIProvider(api API) (ApiProviderInternal, error)
type ApiStreamFunction ¶
type ApiStreamFunction func( Model Model[API], ModelContext ModelContext, Options *StreamOptions, ) (*AssistantMessageEventStream, error)
type ApiStreamSimpleFunction ¶
type ApiStreamSimpleFunction func( model Model[API], ModelContext ModelContext, options *SimpleStreamOptions, ) (*AssistantMessageEventStream, error)
type AssistantContent ¶
type AssistantContent interface {
// contains filtered or unexported methods
}
type AssistantMessage ¶
type AssistantMessage struct {
Role Role `json:"role"`
Content []AssistantContent `json:"content"`
Api API `json:"api"`
Provider Provider `json:"provider"`
Model string `json:"model"`
ResponseModel *string `json:"responseModel,omitempty"`
ResponseID *string `json:"responseId,omitempty"`
Diagnostics []AssistantMessageDiagnostic `json:"diagnostics,omitempty"`
Usage Usage `json:"usage"`
StopReason StopReason `json:"stopReason"`
ErrorMessage string `json:"errorMessage,omitempty"`
Timestamp int64 `json:"timestamp"` // Unix timestamp in milliseconds
}
func Complete ¶
func Complete(model Model[API], modelContext ModelContext, options *StreamOptions) (AssistantMessage, error)
func CompleteSimple ¶
func CompleteSimple(model Model[API], modelContext ModelContext, options *SimpleStreamOptions) (AssistantMessage, error)
func (AssistantMessage) AgentMessageType ¶
func (AssistantMessage) AgentMessageType() string
type AssistantMessageDiagnostic ¶
type AssistantMessageDiagnostic struct {
Type string `json:"type"`
Timestamp int64 `json:"timestamp"`
Error *DiagnosticErrorInfo `json:"error,omitempty"`
Details any `json:"details,omitempty"`
}
type AssistantMessageEvent ¶
type AssistantMessageEvent interface {
EventType() string
}
type AssistantMessageEventStream ¶
type AssistantMessageEventStream struct {
// contains filtered or unexported fields
}
func NewAssistantMessageEventStream ¶
func NewAssistantMessageEventStream(buffer int) *AssistantMessageEventStream
func Stream ¶
func Stream(model Model[API], modelContext ModelContext, options *StreamOptions) (*AssistantMessageEventStream, error)
func StreamOpenAIResponse ¶
func StreamOpenAIResponse(ctx context.Context, model Model[API], modelContext ModelContext, options *OpenAIResponseOptions) (*AssistantMessageEventStream, error)
func StreamSimple ¶
func StreamSimple(model Model[API], modelContext ModelContext, options *SimpleStreamOptions) (*AssistantMessageEventStream, error)
func StreamSimpleOpenAIResponses ¶
func StreamSimpleOpenAIResponses(model Model[API], modelContext ModelContext, options *SimpleStreamOptions) (*AssistantMessageEventStream, error)
func (*AssistantMessageEventStream) End ¶
func (s *AssistantMessageEventStream) End(err error)
func (*AssistantMessageEventStream) Events ¶
func (s *AssistantMessageEventStream) Events() <-chan AssistantMessageEvent
func (*AssistantMessageEventStream) Push ¶
func (s *AssistantMessageEventStream) Push(event AssistantMessageEvent)
func (*AssistantMessageEventStream) Result ¶
func (s *AssistantMessageEventStream) Result() (AssistantMessage, error)
type AssistantMessageEventType ¶
type AssistantMessageEventType string
const ( AssistantMessageEventText AssistantMessageEventType = "text" AssistantMessageEventDone AssistantMessageEventType = "done" AssistantMessageEventError AssistantMessageEventType = "error" )
type CacheRetention ¶
type CacheRetention string
const ( CacheRetentionNone CacheRetention = "none" CacheRetentionShort CacheRetention = "short" CacheRetentionLong CacheRetention = "long" )
func ResolveCacheRetention ¶
func ResolveCacheRetention(cacheRetention CacheRetention) CacheRetention
type ContentType ¶
type ContentType string
const ( ContentTypeText ContentType = "text" ContentTypeThinking ContentType = "thinking" ContentTypeImage ContentType = "image" ContentTypeToolCall ContentType = "toolCall" )
type ConvertResponseMessagesOptions ¶
type ConvertResponseMessagesOptions struct {
IncludeSystemPrompt *bool `json:"includeSystemPrompt,omitempty"`
}
type ConvertResponsesToolsOptions ¶
type ConvertResponsesToolsOptions struct {
Strict *bool
}
type DiagnosticErrorInfo ¶
type DoneEvent ¶
type DoneEvent struct {
Type string `json:"type"`
Reason StopReason `json:"reason"`
Message AssistantMessage `json:"message"`
}
type ErrorEvent ¶
type ErrorEvent struct {
Type string `json:"type"`
Reason StopReason `json:"reason"`
Message AssistantMessage `json:"message"`
}
func (ErrorEvent) EventType ¶
func (ErrorEvent) EventType() string
type EventStream ¶
func NewEventStream ¶
func NewEventStream[T any, R any]( buffer int, isComplete func(T) bool, extractResult func(T) R, ) *EventStream[T, R]
func (*EventStream[T, R]) End ¶
func (s *EventStream[T, R]) End(result R)
func (*EventStream[T, R]) Events ¶
func (s *EventStream[T, R]) Events() <-chan T
func (*EventStream[T, R]) Push ¶
func (s *EventStream[T, R]) Push(event T)
func (*EventStream[T, R]) Result ¶
func (s *EventStream[T, R]) Result() R
type ImageContent ¶
type ImageContent struct {
Type ContentType `json:"type"`
Image string `json:"image"`
MimeType string `json:"mimeType"`
}
type Model ¶
type Model[tApi API] struct { ID string `json:"id"` Name string `json:"name"` API tApi `json:"api"` Provider Provider `json:"provider"` BaseURL string `json:"baseUrl"` Reasoning bool `json:"reasoning"` ThinkingLevelMap ThinkingLevelMap `json:"thinkingLevelMap"` Input []string `json:"input"` Cost Cost `json:"cost"` // $/million tokens ContextWindow int `json:"contextWindow"` MaxTokens int `json:"maxTokens"` Headers *map[string]string `json:"headers"` Compat *OpenAIResponsesCompat `json:"compat"` }
type ModelContext ¶
type ModelThinkingLevel ¶
type ModelThinkingLevel string
const ( ThinkingLevelOff ModelThinkingLevel = "off" ThinkingLevelMinimal ModelThinkingLevel = "minimal" ThinkingLevelLow ModelThinkingLevel = "low" ThinkingLevelMedium ModelThinkingLevel = "medium" ThinkingLevelHigh ModelThinkingLevel = "high" ThinkingLevelXHigh ModelThinkingLevel = "xhigh" )
func ClampThinkingLevel ¶
func ClampThinkingLevel[TApi API](model Model[TApi], level ModelThinkingLevel) ModelThinkingLevel
func GetSupportedThinkingLevels ¶
func GetSupportedThinkingLevels[TApi API](model Model[TApi]) []ModelThinkingLevel
type OpenAIResponseOptions ¶
type OpenAIResponseOptions struct {
StreamOptions
ReasoningEffort *string `json:"reasoningEffort,omitempty"`
ReasoningSummary *string `json:"reasoningSummary,omitempty"`
ServiceTier *string `json:"serviceTier,omitempty"`
}
type OpenAIResponsesCompat ¶
type ParsedTextSignature ¶
type ParsedTextSignature struct {
ID string
Phase *TextSignaturePhase
}
func ParseTextSignature ¶
func ParseTextSignature(signature *string) *ParsedTextSignature
type Provider ¶
type Provider string
const (
ProviderOpenAI Provider = "openai"
)
func GetProviders ¶
func GetProviders() []Provider
type ProviderResponse ¶
type RegisteredApiProvider ¶
type RegisteredApiProvider struct {
Provider ApiProviderInternal
SourceID *string
}
type SessionResourceCleanup ¶
type SimpleStreamOptions ¶
type SimpleStreamOptions struct {
StreamOptions
Reasoning *ModelThinkingLevel
ThinkingBudgets *ThinkingBudgets
}
type StartEvent ¶
type StartEvent struct {
Type string `json:"type"`
Partial AssistantMessage `json:"partial"`
}
func (StartEvent) EventType ¶
func (StartEvent) EventType() string
type StopReason ¶
type StopReason string
const ( StopReasonStop StopReason = "stop" StopReasonLength StopReason = "length" StopReasonToolUse StopReason = "toolUse" StopReasonError StopReason = "error" StopReasonAborted StopReason = "aborted" )
func MapOpenAIResponseStopReason ¶
func MapOpenAIResponseStopReason(status responses.ResponseStatus) (StopReason, error)
type StreamFunction ¶
type StreamFunction[TApi API, TOptions any] func( model Model[TApi], ModelContext ModelContext, options *TOptions, ) (*AssistantMessageEventStream, error)
type StreamOptions ¶
type StreamOptions struct {
Temperature *decimal.Decimal `json:"temperature,omitempty"`
MaxTokens *int64 `json:"max_tokens,omitempty"`
Signal context.Context `json:"signal,omitempty"`
ApiKey *string `json:"api_key,omitempty"`
Transport *Transport `json:"transport,omitempty"`
Cache *CacheRetention `json:"cache,omitempty"`
SessionId *string `json:"session_id,omitempty"`
OnPayload func(payload any, model Model[API]) (any, error) `json:"on_payload,omitempty"`
OnResponse func(response ProviderResponse, model Model[API]) error `json:"on_response,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
TimeoutMs *int64 `json:"timeout_ms,omitempty"`
MaxRetries *int64 `json:"max_retries,omitempty"`
MaxRetriesDelayMs *int64 `json:"max_retries_delay_ms,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
type TextContent ¶
type TextContent struct {
Type ContentType `json:"type"`
Text string `json:"text"`
TextSignature *string `json:"textSignature,omitempty"`
}
type TextDeltaEvent ¶
type TextDeltaEvent struct {
Type string `json:"type"`
ContentIndex int64 `json:"contentIndex"`
Delta string `json:"delta"`
Partial AssistantMessage `json:"partial"`
}
func (TextDeltaEvent) EventType ¶
func (TextDeltaEvent) EventType() string
type TextEndEvent ¶
type TextEndEvent struct {
Type string `json:"type"`
ContentIndex int64 `json:"contentIndex"`
Content string `json:"content"`
Partial AssistantMessage `json:"partial"`
}
func (TextEndEvent) EventType ¶
func (TextEndEvent) EventType() string
type TextSignaturePhase ¶
type TextSignaturePhase string
const ( PhaseCommentary TextSignaturePhase = "commentary" PhaseFinalAnswer TextSignaturePhase = "final_answer" )
type TextStartEvent ¶
type TextStartEvent struct {
Type string `json:"type"`
ContentIndex int64 `json:"contentIndex"`
Partial AssistantMessage `json:"partial"`
}
func (TextStartEvent) EventType ¶
func (TextStartEvent) EventType() string
type ThinkingBudgets ¶
type ThinkingContent ¶
type ThinkingContent struct {
Type ContentType `json:"type"`
Thinking string `json:"thinking"`
ThinkingSignature *string `json:"thinkingSignature,omitempty"`
Redacted *bool `json:"redacted,omitempty"`
}
type ThinkingDeltaEvent ¶
type ThinkingDeltaEvent struct {
Type string `json:"type"`
ContentIndex int64 `json:"contentIndex"`
Delta string `json:"delta"`
Partial AssistantMessage `json:"partial"`
}
func (ThinkingDeltaEvent) EventType ¶
func (ThinkingDeltaEvent) EventType() string
type ThinkingEndEvent ¶
type ThinkingEndEvent struct {
Type string `json:"type"`
ContentIndex int64 `json:"contentIndex"`
Content string `json:"content"`
Partial AssistantMessage `json:"partial"`
}
func (ThinkingEndEvent) EventType ¶
func (ThinkingEndEvent) EventType() string
type ThinkingLevelMap ¶
type ThinkingLevelMap map[ModelThinkingLevel]*string
type ThinkingStartEvent ¶
type ThinkingStartEvent struct {
Type string `json:"type"`
ContentIndex int64 `json:"contentIndex"`
Partial AssistantMessage `json:"partial"`
}
func (ThinkingStartEvent) EventType ¶
func (ThinkingStartEvent) EventType() string
type ToolCallDeltaEvent ¶
type ToolCallDeltaEvent struct {
Type string `json:"type"`
ContentIndex int64 `json:"contentIndex"`
Delta string `json:"delta"`
Partial AssistantMessage `json:"partial"`
}
func (ToolCallDeltaEvent) EventType ¶
func (ToolCallDeltaEvent) EventType() string
type ToolCallEndEvent ¶
type ToolCallEndEvent struct {
Type string `json:"type"`
ContentIndex int64 `json:"contentIndex"`
ToolCall ToolCall `json:"toolCall"`
Partial AssistantMessage `json:"partial"`
}
func (ToolCallEndEvent) EventType ¶
func (ToolCallEndEvent) EventType() string
type ToolCallStartEvent ¶
type ToolCallStartEvent struct {
Type string `json:"type"`
ContentIndex int64 `json:"contentIndex"`
Partial AssistantMessage `json:"partial"`
}
func (ToolCallStartEvent) EventType ¶
func (ToolCallStartEvent) EventType() string
type ToolResultContent ¶
type ToolResultContent interface {
// contains filtered or unexported methods
}
func ReplaceToolResultImagesWithPlaceholder ¶
func ReplaceToolResultImagesWithPlaceholder(content []ToolResultContent, placeholder string) []ToolResultContent
type ToolResultMessage ¶
type ToolResultMessage struct {
Role Role `json:"role"`
ToolCallID string `json:"toolCallId"`
ToolName string `json:"toolName"`
Content []ToolResultContent `json:"content"`
Details any `json:"details,omitempty"`
IsError bool `json:"isError"`
Timestamp int64 `json:"timestamp"` // Unix timestamp in milliseconds
}
func (ToolResultMessage) AgentMessageType ¶
func (ToolResultMessage) AgentMessageType() string
type Usage ¶
type UserContent ¶
type UserContent interface {
// contains filtered or unexported methods
}
func ReplaceUserImagesWithPlaceholder ¶
func ReplaceUserImagesWithPlaceholder(content []UserContent, placeholder string) []UserContent
type UserMessage ¶
type UserMessage struct {
Role Role `json:"role"`
Content []UserContent `json:"content"`
Timestamp int64 `json:"timestamp"` // Unix timestamp in milliseconds
}
func (UserMessage) AgentMessageType ¶
func (UserMessage) AgentMessageType() string
AgentMessageType returns the message type as a string for use in the agent loop.
Click to show internal directories.
Click to hide internal directories.