assistant.go

44 lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
// 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
}