readysite / pkg / assistant / assistant.go
1.5 KB
assistant.go
// Package assistant provides AI provider abstraction for chat completions.
package assistant

import "context"

// Assistant provides AI chat operations.
// Use providers to create: mock.New(), openai.New(), anthropic.New()
type Assistant struct {
	Backend
}

// Backend is the interface that providers implement.
type Backend interface {
	// Chat sends a request and returns the complete response.
	Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)

	// Stream sends a request and returns a stream reader for SSE.
	Stream(ctx context.Context, req ChatRequest) (*StreamReader, error)
}

// ChatRequest configures a chat completion request.
type ChatRequest struct {
	Model       string   // Model identifier (e.g., "gpt-4", "claude-3-opus")
	Messages    []Message // Conversation history
	Tools       []Tool   // Available tools
	MaxTokens   int      // Maximum tokens in response
	Temperature *float64 // Sampling temperature (0-2), nil means provider default
	System      string   // System prompt
}

// ChatResponse is the result of a chat completion.
type ChatResponse struct {
	Content      string     // Text content of the response
	ToolCalls    []ToolCall // Tool calls requested by the model
	FinishReason string     // Why generation stopped: "stop", "tool_calls", "length"
	Usage        Usage      // Token usage statistics
}

// Usage tracks token consumption.
type Usage struct {
	PromptTokens     int // Tokens in the request
	CompletionTokens int // Tokens in the response
	TotalTokens      int // Total tokens used
}
← Back