- internal/llama/template.go: ChatML/Llama3 template engine with stop tokens - internal/agent/reasoning.go: parse <think>/<reasoning> tags from LLM output - companion/promptbuilder.go: output structured BuildResult, add date/time context - agent/agent.go: wire templates + reasoning split into message loop - storage: add reasoning TEXT column to messages table + migration - channel/tui.go: collapsible reasoning (tab toggle), mouse scroll, polished dimmed style - config: CHAT_TEMPLATE env var (chatml|llama3|none) - plan.md: mark Phase 2 complete, add themes TODO
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package companion
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.db123.ir/db123/divacode/internal/config"
|
|
)
|
|
|
|
type PromptBuilder struct {
|
|
cfg *config.Config
|
|
}
|
|
|
|
func NewPromptBuilder(cfg *config.Config) *PromptBuilder {
|
|
return &PromptBuilder{cfg: cfg}
|
|
}
|
|
|
|
type BuildResult struct {
|
|
SystemContent string
|
|
}
|
|
|
|
func (pb *PromptBuilder) Build(in *BuildInput) *BuildResult {
|
|
var b strings.Builder
|
|
|
|
now := time.Now()
|
|
b.WriteString(fmt.Sprintf("Current date and time: %s\n", now.Format("2006-01-02 15:04:05 (MST)")))
|
|
b.WriteString(in.SystemPrompt)
|
|
b.WriteString("\n\n")
|
|
|
|
b.WriteString("Current Personality:\n")
|
|
for _, t := range in.Traits {
|
|
label := string(t.Trait)
|
|
pct := int(t.Value * 100)
|
|
b.WriteString(fmt.Sprintf("- %s: %d%%\n", label, pct))
|
|
}
|
|
|
|
b.WriteString(fmt.Sprintf("\nMood: %s\n", in.Mood))
|
|
|
|
if in.Relationship != nil && in.Relationship.Familiarity > 0.1 {
|
|
b.WriteString("\nRelationship:\n")
|
|
b.WriteString(fmt.Sprintf("- Familiarity: %d%%\n", int(in.Relationship.Familiarity*100)))
|
|
b.WriteString(fmt.Sprintf("- Trust: %d%%\n", int(in.Relationship.Trust*100)))
|
|
if len(in.Relationship.SharedTopics) > 0 {
|
|
b.WriteString(fmt.Sprintf("- Shared interests: %s\n", strings.Join(in.Relationship.SharedTopics, ", ")))
|
|
}
|
|
}
|
|
|
|
if len(in.Observations) > 0 {
|
|
b.WriteString("\nObservations:\n")
|
|
for _, o := range in.Observations {
|
|
b.WriteString(fmt.Sprintf("- %s\n", o.Content))
|
|
}
|
|
}
|
|
|
|
if len(in.Memories) > 0 {
|
|
b.WriteString("\nMemories:\n")
|
|
for i, m := range in.Memories {
|
|
if i >= 5 {
|
|
break
|
|
}
|
|
b.WriteString(fmt.Sprintf("- %s\n", m))
|
|
}
|
|
}
|
|
|
|
return &BuildResult{SystemContent: b.String()}
|
|
}
|