Files
Cyrene_v2/backend/services/ai-core/model/model.go
T
Aska 3b3e5a0697 feat(ai-core): add LLM orchestration engine
- model: shared data types (Message, Intent, StreamToken, LLMMessage)
- persona: YAML/Raw loading + system prompt injection
- llm: OpenAI-compatible adapter with streaming + semantic cache
- context: sliding window context store with token budgeting
- subsession: parallel provider dispatch + review message parser
- orchestrator: intent analysis pipeline (IoT/greeting/chat/memory)
- background: autonomous thinking engine
- 20+ tests, build + vet clean, ~130 total tests
2026-08-09 21:21:27 +08:00

96 lines
3.1 KiB
Go

// Package model defines shared data types for the AI-Core engine.
package model
import "time"
// Message represents a single chat message in a conversation.
type Message struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Role string `json:"role"` // "user" | "assistant" | "action" | "system"
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
}
// Session represents a conversation session.
type Session struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Title string `json:"title"`
State string `json:"state"` // "active" | "idle"
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// SubSessionResult holds the result from a single subsession provider.
type SubSessionResult struct {
Provider string `json:"provider"` // "general" | "memory" | "iot" | "review"
Content string `json:"content"`
Error string `json:"error,omitempty"`
}
// Intent represents the detected intent of a user message.
type Intent struct {
Type string `json:"type"` // "chat" | "iot_control" | "iot_query" | "greeting" | "memory_trigger" | "knowledge" | "task"
Confidence float64 `json:"confidence"` // 0.0 - 1.0
Entities []string `json:"entities"` // Detected entities (device names, etc.)
RawText string `json:"raw_text"`
}
// LLMMessage is the standardized format sent to LLM APIs.
type LLMMessage struct {
Role string `json:"role"` // "system" | "user" | "assistant" | "tool"
Content string `json:"content"`
Name string `json:"name,omitempty"`
}
// LLMResponse represents a non-streaming LLM response.
type LLMResponse struct {
Content string `json:"content"`
FinishReason string `json:"finish_reason"` // "stop" | "length" | "tool_calls"
Model string `json:"model"`
TokensUsed int `json:"tokens_used"`
}
// StreamToken is a single token from a streaming LLM response.
type StreamToken struct {
Content string `json:"content"`
FinishReason string `json:"finish_reason,omitempty"`
Done bool `json:"done"`
}
// ReviewSegment represents a parsed action/chat segment from LLM output.
type ReviewSegment struct {
Type string `json:"type"` // "action" | "chat"
Content string `json:"content"`
}
// ToolCall represents a tool call requested by the LLM.
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Arguments map[string]any `json:"arguments"`
}
// Intent types
const (
IntentChat = "chat"
IntentIoTControl = "iot_control"
IntentIoTQuery = "iot_query"
IntentGreeting = "greeting"
IntentMemoryTrigger = "memory_trigger"
IntentKnowledge = "knowledge"
IntentTask = "task"
)
// LLM purposes for model routing
type LLMPurpose string
const (
PurposeChat LLMPurpose = "chat"
PurposeIntentAnalysis LLMPurpose = "intent_analysis"
PurposeDeepThinking LLMPurpose = "deep_thinking"
PurposeMemoryExtraction LLMPurpose = "memory_extraction"
PurposeToolCalling LLMPurpose = "tool_calling"
)