Documentation
¶
Overview ¶
Package openai adapts OpenAI-compatible APIs to sigma.
It includes providers for Chat Completions-compatible endpoints, OpenAI Responses, Azure OpenAI Responses, OpenAI Codex Responses, and OpenAI Images. Chat Completions-compatible registration is also the path for local endpoints and routers described with sigma.OpenAICompatibleModel.
Providers resolve credentials through sigma.Options.AuthResolver or explicit token-provider options instead of reading environment variables directly.
Index ¶
- Constants
- Variables
- func Register(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterAzureResponses(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterAzureResponsesDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterCodexResponses(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterCodexResponsesDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterImages(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterImagesDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterResponses(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
- func RegisterResponsesDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
- func WithAzureResponsesAPIVersion(provider sigma.ProviderID, apiVersion string) sigma.Option
- func WithAzureResponsesCredentialSource(provider sigma.ProviderID, source string) sigma.Option
- func WithAzureResponsesDeployment(provider sigma.ProviderID, deployment string) sigma.Option
- func WithAzureResponsesEndpoint(provider sigma.ProviderID, endpoint string) sigma.Option
- func WithAzureResponsesTokenCredential(provider sigma.ProviderID, credential AzureTokenCredential) sigma.Option
- func WithCodexResponsesOAuthTokenProvider(provider sigma.ProviderID, tokenProvider sigma.OAuthTokenProvider) sigma.Option
- type AzureAccessToken
- type AzureResponsesProvider
- type AzureTokenCredential
- type AzureTokenCredentialFunc
- type AzureTokenRequest
- type CodeInterpreterContainer
- type CodeInterpreterOption
- type CodexResponsesProvider
- type FileSearchComparisonFilter
- type FileSearchCompoundFilter
- type FileSearchFilter
- type FileSearchOption
- type FileSearchRanking
- type ImageGenerationMask
- type ImageGenerationOption
- func WithBackground(background string) ImageGenerationOption
- func WithImageModel(model string) ImageGenerationOption
- func WithImageQuality(quality string) ImageGenerationOption
- func WithImageSize(size string) ImageGenerationOption
- func WithInputFidelity(fidelity string) ImageGenerationOption
- func WithInputImageMask(mask ImageGenerationMask) ImageGenerationOption
- func WithModeration(moderation string) ImageGenerationOption
- func WithOutputCompression(compression int) ImageGenerationOption
- func WithOutputFormat(format string) ImageGenerationOption
- func WithPartialImages(images int) ImageGenerationOption
- type ImagesProvider
- type Provider
- type ProviderOption
- type ResponsesProvider
- type WebSearchFilters
- type WebSearchLocation
- type WebSearchOption
Constants ¶
const ( // AzureCredentialSourceAPIKey documents API-key authentication. AzureCredentialSourceAPIKey = "api-key" // AzureCredentialSourceToken documents Microsoft Entra token authentication. AzureCredentialSourceToken = "token" )
const DefaultBaseURL = "https://api.openai.com/v1"
Variables ¶
var Tools = struct { WebSearch func(opts ...WebSearchOption) sigma.Tool CodeInterpreter func(opts ...CodeInterpreterOption) sigma.Tool FileSearch func(opts ...FileSearchOption) sigma.Tool ImageGeneration func(opts ...ImageGenerationOption) sigma.Tool }{ WebSearch: webSearchTool, CodeInterpreter: codeInterpreterTool, FileSearch: fileSearchTool, ImageGeneration: imageGenerationTool, }
Tools provides factories for OpenAI Responses provider-defined tools.
Functions ¶
func Register ¶
func Register(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
Register adds a Chat Completions-compatible text provider to registry.
func RegisterAzureResponses ¶
func RegisterAzureResponses(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterAzureResponses adds an Azure OpenAI Responses text provider to registry.
func RegisterAzureResponsesDefault ¶
func RegisterAzureResponsesDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterAzureResponsesDefault adds an Azure OpenAI Responses text provider to sigma's default registry.
func RegisterCodexResponses ¶
func RegisterCodexResponses(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterCodexResponses adds an OpenAI Codex Responses text provider to registry.
func RegisterCodexResponsesDefault ¶
func RegisterCodexResponsesDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterCodexResponsesDefault adds an OpenAI Codex Responses text provider to sigma's default registry.
func RegisterDefault ¶
func RegisterDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterDefault adds a Chat Completions-compatible text provider to sigma's default registry.
func RegisterImages ¶ added in v0.2.0
func RegisterImages(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterImages adds an OpenAI Images API provider to registry.
func RegisterImagesDefault ¶ added in v0.2.0
func RegisterImagesDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterImagesDefault adds an OpenAI Images API provider to sigma's default registry.
func RegisterResponses ¶
func RegisterResponses(registry *sigma.Registry, providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterResponses adds an OpenAI Responses API text provider to registry.
func RegisterResponsesDefault ¶
func RegisterResponsesDefault(providerID sigma.ProviderID, opts ...ProviderOption) error
RegisterResponsesDefault adds an OpenAI Responses API text provider to sigma's default registry.
func WithAzureResponsesAPIVersion ¶
func WithAzureResponsesAPIVersion(provider sigma.ProviderID, apiVersion string) sigma.Option
WithAzureResponsesAPIVersion overrides the api-version query parameter for a request. Azure currently documents v1 as the default, but sigma requires an explicit value so configuration drift is visible in tests and diagnostics.
func WithAzureResponsesCredentialSource ¶
func WithAzureResponsesCredentialSource(provider sigma.ProviderID, source string) sigma.Option
WithAzureResponsesCredentialSource documents the expected auth path for a request. Supported values are AzureCredentialSourceAPIKey and AzureCredentialSourceToken.
func WithAzureResponsesDeployment ¶
func WithAzureResponsesDeployment(provider sigma.ProviderID, deployment string) sigma.Option
WithAzureResponsesDeployment overrides the Azure OpenAI deployment name sent as the Responses model for a request.
func WithAzureResponsesEndpoint ¶
func WithAzureResponsesEndpoint(provider sigma.ProviderID, endpoint string) sigma.Option
WithAzureResponsesEndpoint overrides the Azure OpenAI resource endpoint for a request. The provider appends /openai/v1/responses and api-version.
func WithAzureResponsesTokenCredential ¶
func WithAzureResponsesTokenCredential(provider sigma.ProviderID, credential AzureTokenCredential) sigma.Option
WithAzureResponsesTokenCredential supplies a request-scoped Microsoft Entra token source. API-key auth can use sigma.WithAPIKey, AZURE_OPENAI_API_KEY, or a normal sigma.AuthResolver.
func WithCodexResponsesOAuthTokenProvider ¶
func WithCodexResponsesOAuthTokenProvider(provider sigma.ProviderID, tokenProvider sigma.OAuthTokenProvider) sigma.Option
WithCodexResponsesOAuthTokenProvider supplies the OAuth bearer-token source used by the Codex Responses provider. Interactive OAuth login and device-flow handling are intentionally outside the core provider.
Types ¶
type AzureAccessToken ¶
AzureAccessToken is the minimal token shape needed by Azure Responses auth.
type AzureResponsesProvider ¶
type AzureResponsesProvider struct {
// contains filtered or unexported fields
}
AzureResponsesProvider adapts Azure OpenAI Responses to sigma.
func NewAzureResponsesProvider ¶
func NewAzureResponsesProvider(opts ...ProviderOption) *AzureResponsesProvider
NewAzureResponsesProvider constructs an Azure OpenAI Responses provider.
func (*AzureResponsesProvider) API ¶
func (p *AzureResponsesProvider) API() sigma.API
API reports the Azure OpenAI Responses API surface.
type AzureTokenCredential ¶
type AzureTokenCredential interface {
GetAzureToken(context.Context, AzureTokenRequest) (AzureAccessToken, error)
}
AzureTokenCredential is a narrow adapter interface for Microsoft Entra ID token sources. Azure SDK credentials can be wrapped to this interface without importing Azure SDK packages into sigma.
type AzureTokenCredentialFunc ¶
type AzureTokenCredentialFunc func(context.Context, AzureTokenRequest) (AzureAccessToken, error)
AzureTokenCredentialFunc adapts a function into AzureTokenCredential.
func (AzureTokenCredentialFunc) GetAzureToken ¶
func (f AzureTokenCredentialFunc) GetAzureToken(ctx context.Context, req AzureTokenRequest) (AzureAccessToken, error)
GetAzureToken calls f.
type AzureTokenRequest ¶
type AzureTokenRequest struct {
Scopes []string
}
AzureTokenRequest describes the token request made by AzureResponsesProvider.
type CodeInterpreterContainer ¶
type CodeInterpreterContainer struct {
FileIDs []string
}
CodeInterpreterContainer configures an auto-provisioned code interpreter container.
type CodeInterpreterOption ¶
type CodeInterpreterOption func(*codeInterpreterConfig)
CodeInterpreterOption configures OpenAI code interpreter.
func WithContainerFiles ¶
func WithContainerFiles(container *CodeInterpreterContainer) CodeInterpreterOption
func WithContainerID ¶
func WithContainerID(id string) CodeInterpreterOption
type CodexResponsesProvider ¶
type CodexResponsesProvider struct {
// contains filtered or unexported fields
}
CodexResponsesProvider adapts OpenAI Codex Responses to sigma. It reuses the OpenAI Responses payload and SSE parsing path, but requires an explicit OAuth token provider instead of reading credentials from environment or global state.
func NewCodexResponsesProvider ¶
func NewCodexResponsesProvider(opts ...ProviderOption) *CodexResponsesProvider
NewCodexResponsesProvider constructs an OpenAI Codex Responses provider.
func (*CodexResponsesProvider) API ¶
func (p *CodexResponsesProvider) API() sigma.API
API reports the OpenAI Codex Responses API surface.
type FileSearchCompoundFilter ¶
type FileSearchCompoundFilter struct {
Type string
Filters []FileSearchFilter
}
type FileSearchFilter ¶
type FileSearchFilter interface {
// contains filtered or unexported methods
}
type FileSearchOption ¶
type FileSearchOption func(*fileSearchConfig)
FileSearchOption configures OpenAI file search.
func WithFileSearchFilters ¶
func WithFileSearchFilters(filters FileSearchFilter) FileSearchOption
func WithMaxNumResults ¶
func WithMaxNumResults(results int) FileSearchOption
func WithRanking ¶
func WithRanking(ranking FileSearchRanking) FileSearchOption
func WithVectorStoreIDs ¶
func WithVectorStoreIDs(ids ...string) FileSearchOption
type FileSearchRanking ¶
type ImageGenerationMask ¶
type ImageGenerationOption ¶
type ImageGenerationOption func(*imageGenerationConfig)
ImageGenerationOption configures OpenAI image generation as a Responses tool.
func WithBackground ¶
func WithBackground(background string) ImageGenerationOption
func WithImageModel ¶
func WithImageModel(model string) ImageGenerationOption
func WithImageQuality ¶
func WithImageQuality(quality string) ImageGenerationOption
func WithImageSize ¶
func WithImageSize(size string) ImageGenerationOption
func WithInputFidelity ¶
func WithInputFidelity(fidelity string) ImageGenerationOption
func WithInputImageMask ¶
func WithInputImageMask(mask ImageGenerationMask) ImageGenerationOption
func WithModeration ¶
func WithModeration(moderation string) ImageGenerationOption
func WithOutputCompression ¶
func WithOutputCompression(compression int) ImageGenerationOption
func WithOutputFormat ¶
func WithOutputFormat(format string) ImageGenerationOption
func WithPartialImages ¶
func WithPartialImages(images int) ImageGenerationOption
type ImagesProvider ¶ added in v0.2.0
type ImagesProvider struct {
// contains filtered or unexported fields
}
ImagesProvider adapts OpenAI's image generation API to sigma.
func NewImagesProvider ¶ added in v0.2.0
func NewImagesProvider(opts ...ProviderOption) *ImagesProvider
NewImagesProvider constructs an OpenAI Images API provider.
func (*ImagesProvider) API ¶ added in v0.2.0
func (p *ImagesProvider) API() sigma.ImageAPI
API reports the OpenAI Images API surface.
func (*ImagesProvider) Generate ¶ added in v0.2.0
func (p *ImagesProvider) Generate(ctx context.Context, model sigma.ImageModel, req sigma.ImageRequest, opts sigma.Options) (sigma.AssistantImages, error)
Generate sends req to OpenAI's non-streaming image generation endpoint.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider adapts OpenAI Chat Completions-compatible HTTP APIs to sigma.
func NewProvider ¶
func NewProvider(opts ...ProviderOption) *Provider
NewProvider constructs an OpenAI Chat Completions-compatible provider.
type ProviderOption ¶
type ProviderOption func(*Provider)
ProviderOption configures a Provider.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ProviderOption
WithBaseURL configures the provider base URL, for example an httptest server URL ending in /v1 or a local OpenAI-compatible endpoint.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ProviderOption
WithHTTPClient configures the provider fallback HTTP client.
func WithHeader ¶
func WithHeader(key, value string) ProviderOption
WithHeader configures a provider default request header.
func WithHeaders ¶
func WithHeaders(headers map[string]string) ProviderOption
WithHeaders configures provider default request headers.
type ResponsesProvider ¶
type ResponsesProvider struct {
// contains filtered or unexported fields
}
ResponsesProvider adapts the OpenAI Responses API to sigma.
func NewResponsesProvider ¶
func NewResponsesProvider(opts ...ProviderOption) *ResponsesProvider
NewResponsesProvider constructs an OpenAI Responses API provider.
func (*ResponsesProvider) API ¶
func (p *ResponsesProvider) API() sigma.API
API reports the OpenAI Responses API surface.
type WebSearchFilters ¶
type WebSearchFilters struct {
AllowedDomains []string
}
WebSearchFilters configures search result filtering.
type WebSearchLocation ¶
WebSearchLocation configures approximate user location for search.
type WebSearchOption ¶
type WebSearchOption func(*webSearchConfig)
WebSearchOption configures OpenAI web search.
func WithExternalWebAccess ¶
func WithExternalWebAccess(enabled bool) WebSearchOption
func WithSearchContextSize ¶
func WithSearchContextSize(size string) WebSearchOption
func WithSearchFilters ¶
func WithSearchFilters(filters WebSearchFilters) WebSearchOption
func WithUserLocation ¶
func WithUserLocation(location WebSearchLocation) WebSearchOption