Documentation
¶
Index ¶
- func BoolPtr(v bool) *bool
- func Float64Ptr(v float64) *float64
- func IntPtr(v int) *int
- func ModelAliases() map[string]string
- func NewLogger(verbose bool) *slog.Logger
- func ResolveModel(model string) string
- type APIError
- type ChatClient
- type ChatOptions
- type ChatRequest
- type ChatResponse
- type Choice
- type Client
- func (c *Client) Chat(ctx context.Context, prompt string, opts ChatOptions) (string, Usage, error)
- func (c *Client) ChatStream(ctx context.Context, prompt string, opts ChatOptions) (StreamResult, error)
- func (c *Client) Embed(ctx context.Context, texts []string, model string) (*EmbeddingResponse, error)
- func (c *Client) ListModels(ctx context.Context) ([]Model, error)
- func (c *Client) Search(ctx context.Context, query string) (*SearchResponse, error)
- func (c *Client) Vision(ctx context.Context, prompt string, imageSource string, opts ChatOptions) (string, error)
- type ClientConfig
- type EmbeddingClient
- type EmbeddingData
- type EmbeddingRequest
- type EmbeddingResponse
- type EmbeddingUsage
- type HTTPDoer
- type Message
- type Model
- type ModelClient
- type ModelsResponse
- type RetryConfig
- type SearchClient
- type SearchRequest
- type SearchResponse
- type SearchResult
- type StreamChoice
- type StreamChunk
- type StreamDelta
- type StreamOptions
- type StreamResult
- type Usage
- type VisionClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModelAliases ¶
ModelAliases returns a copy of the model alias map.
func ResolveModel ¶
ResolveModel resolves a model alias to its full name, or returns the input if not an alias.
Types ¶
type ChatClient ¶
type ChatClient interface {
Chat(ctx context.Context, prompt string, opts ChatOptions) (string, Usage, error)
}
ChatClient interface for testability (ISP compliance).
type ChatOptions ¶
type ChatOptions struct {
Model string
Temperature *float64
MaxTokens *int
TopP *float64
FilePath string // Optional file to include in context
Context []Message // Previous messages for context
}
ChatOptions configures chat requests.
func DefaultChatOptions ¶
func DefaultChatOptions() ChatOptions
DefaultChatOptions returns sensible defaults for CLI usage.
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Temperature float64 `json:"temperature,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
TopP float64 `json:"top_p,omitempty"`
Stream bool `json:"stream,omitempty"`
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
}
ChatRequest represents the /chat/completions API request.
type ChatResponse ¶
type ChatResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []Choice `json:"choices"`
Usage Usage `json:"usage"`
}
ChatResponse represents the /chat/completions API response.
type Choice ¶
type Choice struct {
Index int `json:"index"`
Message Message `json:"message"`
FinishReason string `json:"finish_reason"`
}
Choice represents a response choice.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements all client interfaces with Synthetic API.
func NewClient ¶
func NewClient(cfg ClientConfig, logger *slog.Logger, httpClient HTTPDoer) *Client
NewClient creates a client with injected dependencies.
func (*Client) ChatStream ¶ added in v1.0.0
func (c *Client) ChatStream(ctx context.Context, prompt string, opts ChatOptions) (StreamResult, error)
ChatStream sends a streaming chat request and returns the assembled result with TTFT.
func (*Client) Embed ¶
func (c *Client) Embed(ctx context.Context, texts []string, model string) (*EmbeddingResponse, error)
Embed generates embeddings for the given texts.
func (*Client) ListModels ¶
ListModels fetches available models from the API.
type ClientConfig ¶
type ClientConfig struct {
APIKey string
BaseURL string // OpenAI-compatible
AnthropicURL string // Anthropic-compatible
Model string
EmbeddingModel string
Timeout time.Duration
Verbose bool
RetryConfig RetryConfig
}
ClientConfig holds all configuration for the Synthetic client.
type EmbeddingClient ¶
type EmbeddingClient interface {
Embed(ctx context.Context, texts []string, model string) (*EmbeddingResponse, error)
}
EmbeddingClient interface for embeddings (ISP compliance).
type EmbeddingData ¶
type EmbeddingData struct {
Object string `json:"object"`
Embedding []float64 `json:"embedding"`
Index int `json:"index"`
}
EmbeddingData represents a single embedding.
type EmbeddingRequest ¶
type EmbeddingRequest struct {
Model string `json:"model"`
Input []string `json:"input"` // Array of strings to embed
}
EmbeddingRequest represents the /embeddings API request.
type EmbeddingResponse ¶
type EmbeddingResponse struct {
Object string `json:"object"`
Data []EmbeddingData `json:"data"`
Model string `json:"model"`
Usage EmbeddingUsage `json:"usage"`
}
EmbeddingResponse represents the /embeddings API response.
type EmbeddingUsage ¶
type EmbeddingUsage struct {
PromptTokens int `json:"prompt_tokens"`
TotalTokens int `json:"total_tokens"`
}
EmbeddingUsage represents embedding token usage.
type Message ¶
type Message struct {
Role string `json:"role"` // "user", "assistant", "system"
Content string `json:"content"`
}
Message represents a chat message.
type Model ¶
type Model struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
OwnedBy string `json:"owned_by"`
}
Model represents a single model.
type ModelClient ¶
ModelClient interface for model listing (ISP compliance).
type ModelsResponse ¶
ModelsResponse represents the /models API response.
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int // Maximum number of retry attempts (default: 3)
InitialBackoff time.Duration // Initial backoff duration (default: 1s)
MaxBackoff time.Duration // Maximum backoff duration (default: 30s)
}
RetryConfig configures retry behavior for transient failures.
type SearchClient ¶
type SearchClient interface {
Search(ctx context.Context, query string) (*SearchResponse, error)
}
SearchClient interface for web search (ISP compliance).
type SearchRequest ¶
type SearchRequest struct {
Query string `json:"query"`
}
SearchRequest represents the /v2/search API request.
type SearchResponse ¶
type SearchResponse struct {
Results []SearchResult `json:"results"`
}
SearchResponse represents the /v2/search API response.
type SearchResult ¶
type SearchResult struct {
Title string `json:"title"`
URL string `json:"url"`
Snippet string `json:"snippet"`
Published string `json:"published,omitempty"` // ISO 8601 timestamp
}
SearchResult represents a single search result.
type StreamChoice ¶ added in v1.0.0
type StreamChoice struct {
Index int `json:"index"`
Delta StreamDelta `json:"delta"`
}
StreamChoice represents a choice delta in a streaming chunk.
type StreamChunk ¶ added in v1.0.0
type StreamChunk struct {
ID string `json:"id"`
Choices []StreamChoice `json:"choices"`
Usage *Usage `json:"usage,omitempty"`
}
StreamChunk represents a single SSE chunk from a streaming response.
type StreamDelta ¶ added in v1.0.0
type StreamDelta struct {
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
}
StreamDelta represents incremental content in a streaming response.
type StreamOptions ¶ added in v1.0.0
type StreamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
StreamOptions configures streaming behavior.
type StreamResult ¶ added in v1.0.0
type StreamResult struct {
Content string
Usage Usage
TTFMS int64 // time to first token in milliseconds
}
StreamResult contains the assembled result of a streaming chat request.
type Usage ¶
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
}
Usage represents token usage statistics.
type VisionClient ¶
type VisionClient interface {
Vision(ctx context.Context, prompt string, imageSource string, opts ChatOptions) (string, error)
}
VisionClient interface for vision/image analysis (ISP compliance).