Files
GovAI/server/pkg/llm/provider.go
T
2026-06-15 23:48:37 +08:00

56 lines
1.3 KiB
Go

package llm
import (
"context"
"io"
)
type Role string
const (
RoleSystem Role = "system"
RoleUser Role = "user"
RoleAssistant Role = "assistant"
)
type Message struct {
Role Role `json:"role"`
Content string `json:"content"`
}
type ChatRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Temperature float64 `json:"temperature,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Stream bool `json:"stream"`
}
type ChatResponse struct {
Content string `json:"content"`
Model string `json:"model"`
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
ConversationID string `json:"conversation_id,omitempty"`
}
type StreamDelta struct {
Content string `json:"content"`
FinishReason string `json:"finish_reason,omitempty"`
}
// Provider abstracts an LLM API (OpenAI, Anthropic, etc.)
type Provider interface {
ChatCompletion(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
ChatStream(ctx context.Context, req *ChatRequest) (io.ReadCloser, error)
Name() string
}
type ProviderConfig struct {
Type string `json:"type"`
APIKey string `json:"api_key"`
BaseURL string `json:"base_url,omitempty"`
Model string `json:"model,omitempty"`
}