Documentation
¶
Overview ¶
Package base provides shared utilities for AI provider implementations.
Index ¶
- Constants
- func BuildToolParameterSchema(toolParams []tools.Parameter) (properties map[string]interface{}, required []string)
- func FormatMessagesAsPrompt(messages []types.Message) string
- func GetProviderConfig(atmosConfig *schema.AtmosConfiguration, providerName string) *schema.AIProviderConfig
- func PrependSystemMessages(systemPrompt, atmosMemory string, messages []types.Message) []types.Message
- func ResolveToolchainPATH(atmosConfig *schema.AtmosConfiguration) string
- func UsageFromAnthropic(inputTokens, outputTokens, cacheReadTokens, cacheCreationTokens int64) *types.Usage
- func ValidateProviderBaseURL(baseURL string, hasAPIKey bool) error
- type Config
- type ProviderDefaults
- type ToolInfo
- type ToolParameterSchema
- type ToolPropertySchema
Constants ¶
const DefaultRequestTimeout = 60 * time.Second
DefaultRequestTimeout is the default HTTP request timeout for AI provider API calls.
Variables ¶
This section is empty.
Functions ¶
func BuildToolParameterSchema ¶
func BuildToolParameterSchema(toolParams []tools.Parameter) (properties map[string]interface{}, required []string)
BuildToolParameterSchema builds a JSON Schema from tool parameters. This is the common logic used by all providers for tool parameter conversion.
func FormatMessagesAsPrompt ¶ added in v1.214.0
FormatMessagesAsPrompt concatenates conversation messages into a single prompt string. User messages are included as-is; assistant messages are prefixed with "Assistant: ". Used by CLI providers that pass the entire conversation as a single text prompt.
func GetProviderConfig ¶
func GetProviderConfig(atmosConfig *schema.AtmosConfiguration, providerName string) *schema.AIProviderConfig
GetProviderConfig returns the provider-specific configuration from AtmosConfiguration. Returns nil if no provider configuration is found.
func PrependSystemMessages ¶
func PrependSystemMessages(systemPrompt, atmosMemory string, messages []types.Message) []types.Message
PrependSystemMessages prepends system prompt and atmos memory to conversation history. This is the common pattern used by all providers in SendMessageWithSystemPromptAndTools.
func ResolveToolchainPATH ¶ added in v1.214.0
func ResolveToolchainPATH(atmosConfig *schema.AtmosConfiguration) string
ResolveToolchainPATH extracts the toolchain bin PATH for MCP server subprocesses. Returns the PATH string from the toolchain environment, or empty if no toolchain is configured.
func UsageFromAnthropic ¶
func UsageFromAnthropic(inputTokens, outputTokens, cacheReadTokens, cacheCreationTokens int64) *types.Usage
UsageFromAnthropic converts token counts in the Anthropic Messages API format into types.Usage.
The Anthropic API, and Claude on Amazon Bedrock, report prompt cache reads and writes outside input_tokens: the full prompt is input_tokens + cache_read_input_tokens + cache_creation_input_tokens. The OpenAI-compatible and Gemini APIs already count cached tokens in their prompt total, so this adds the cache counts to InputTokens. InputTokens is then the full prompt size for every provider, and CacheReadTokens and CacheCreationTokens are the parts of it read from and written to the cache.
Returns nil when the response reports no tokens.
func ValidateProviderBaseURL ¶ added in v1.230.0
ValidateProviderBaseURL rejects an http:// base URL when an API key will be sent with the request, because the bearer token would travel in cleartext (CWE-319). Loopback hosts (localhost, 127.0.0.1, ::1) are allowed so local proxies and test servers keep working, and empty or https URLs always pass. This is a pure validation helper shared by credentialed OpenAI-compatible providers; unauthenticated local providers (e.g. Ollama) never call it.
Types ¶
type Config ¶
type Config struct {
Enabled bool
Model string
APIKey string //nolint:gosec // G117: not a hardcoded credential, populated from config
MaxTokens int
BaseURL string
}
Config holds common configuration for AI clients.
func ExtractConfig ¶
func ExtractConfig(atmosConfig *schema.AtmosConfiguration, providerName string, defaults ProviderDefaults) *Config
ExtractConfig extracts AI configuration from AtmosConfiguration for a specific provider. It applies the provider-specific defaults and overrides from the configuration.
type ProviderDefaults ¶
ProviderDefaults contains default values for a provider.
type ToolInfo ¶
type ToolInfo struct {
Name string
Description string
Properties map[string]interface{}
Required []string
}
ToolInfo contains basic tool information extracted for conversion.
func ExtractAllToolInfo ¶
ExtractAllToolInfo extracts tool information from a slice of tools.
func ExtractToolInfo ¶
ExtractToolInfo extracts common tool information from a Tool interface. This provides a single point of extraction that all providers can use.
type ToolParameterSchema ¶
type ToolParameterSchema struct {
Type string `json:"type"`
Properties map[string]ToolPropertySchema `json:"properties"`
Required []string `json:"required"`
}
ToolParameterSchema represents the full JSON Schema for tool parameters.
type ToolPropertySchema ¶
type ToolPropertySchema struct {
Type string `json:"type"`
Description string `json:"description"`
}
ToolPropertySchema represents a JSON Schema property for a tool parameter.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package openaicompat provides shared utilities for OpenAI-compatible API providers.
|
Package openaicompat provides shared utilities for OpenAI-compatible API providers. |