app

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(v bool) *bool

func Float64Ptr

func Float64Ptr(v float64) *float64

Helper functions for creating pointers

func IntPtr

func IntPtr(v int) *int

func ModelAliases

func ModelAliases() map[string]string

ModelAliases returns a copy of the model alias map.

func NewLogger

func NewLogger(verbose bool) *slog.Logger

NewLogger creates a slog.Logger for the application.

func ResolveModel

func ResolveModel(model string) string

ResolveModel resolves a model alias to its full name, or returns the input if not an alias.

Types

type APIError

type APIError struct {
	StatusCode int
	Body       string
}

APIError represents an error response from the API.

func (*APIError) Error

func (e *APIError) Error() string

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) Chat

func (c *Client) Chat(ctx context.Context, prompt string, opts ChatOptions) (string, Usage, error)

Chat sends a prompt and returns the response with token usage.

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

func (c *Client) ListModels(ctx context.Context) ([]Model, error)

ListModels fetches available models from the API.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string) (*SearchResponse, error)

Search performs a web search using the /v2/search endpoint. Note: This API is under development and may have breaking changes.

func (*Client) Vision

func (c *Client) Vision(ctx context.Context, prompt string, imageSource string, opts ChatOptions) (string, error)

Vision analyzes an image with a prompt using a vision-capable model. imageSource can be a URL (http/https) or a local file path.

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 HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer interface for HTTP operations (DIP compliance, enables testing).

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

type ModelClient interface {
	ListModels(ctx context.Context) ([]Model, error)
}

ModelClient interface for model listing (ISP compliance).

type ModelsResponse

type ModelsResponse struct {
	Object string  `json:"object"`
	Data   []Model `json:"data"`
}

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).

Jump to

Keyboard shortcuts

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