ZovOS_AI/internal/ai/provider.go
Dan4ick 460d20539f feat: initial project structure - Phase 1 MVP
- Project infrastructure: go.mod, Makefile, .gitignore, README
- Configuration system with YAML parsing and env overrides
- Structured logging with slog
- AI provider interface with Ollama, OpenAI, Anthropic implementations
- Provider manager with runtime switching
- Agent orchestrator with ReAct loop (reason-act-observe)
- Tool registry with JSON Schema descriptions
- Terminal tool: shell command execution with safety controls
- Filesystem tools: read, write, list with path access control
- Conversation memory with session management
- Web UI server with WebSocket streaming
- Modern dark theme UI with glassmorphism, animations
- Frontend: WebSocket client, markdown rendering, tool call display
2026-03-20 00:38:22 +03:00

66 lines
2 KiB
Go

package ai
import "context"
// Message represents a single message in a conversation.
type Message struct {
Role string `json:"role"` // "system", "user", "assistant", "tool"
Content string `json:"content"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
Name string `json:"name,omitempty"`
}
// ToolCall represents a function call requested by the model.
type ToolCall struct {
ID string `json:"id"`
Function struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
}
// Tool describes a tool available to the model.
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]interface{} `json:"parameters"`
}
// Response is the result from a provider.
type Response struct {
Content string `json:"content"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
Model string `json:"model"`
Usage Usage `json:"usage"`
}
// Usage tracks token usage.
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
}
// StreamChunk is a piece of a streamed response.
type StreamChunk struct {
Content string `json:"content,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
Done bool `json:"done"`
Error error `json:"-"`
}
// Provider is the interface that all AI backends must implement.
type Provider interface {
// Chat sends messages and returns a complete response.
Chat(ctx context.Context, messages []Message, tools []Tool) (*Response, error)
// StreamChat sends messages and returns a channel of streamed chunks.
StreamChat(ctx context.Context, messages []Message, tools []Tool) (<-chan StreamChunk, error)
// Name returns the provider's display name.
Name() string
// Models returns the list of available model names.
Models() []string
}