-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpretty.go
More file actions
105 lines (92 loc) · 4.14 KB
/
pretty.go
File metadata and controls
105 lines (92 loc) · 4.14 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package ai
import (
"fmt"
"strings"
)
// ANSI color codes
const (
reset = "\033[0m"
dim = "\033[2m"
red = "\033[31m"
green = "\033[32m"
yellow = "\033[33m"
blue = "\033[34m"
magenta = "\033[35m"
cyan = "\033[36m"
)
func colorRed(s string) string { return red + s + reset }
func colorGreen(s string) string { return green + s + reset }
func colorYellow(s string) string { return yellow + s + reset }
func colorBlue(s string) string { return blue + s + reset }
func colorMagenta(s string) string { return magenta + s + reset }
func colorCyan(s string) string { return cyan + s + reset }
func colorDim(s string) string { return dim + s + reset }
// printDebugRequest prints the outgoing request
func printDebugRequest(model Model, messages []Message) {
fmt.Println()
fmt.Println(colorYellow("┌─────────────────────────────────────────────────────────────"))
fmt.Printf("%s DEBUG REQUEST → %s\n", colorYellow("│"), colorCyan(string(model)))
fmt.Println(colorYellow("├─────────────────────────────────────────────────────────────"))
for _, m := range messages {
var role string
switch m.Role {
case "system":
role = colorMagenta(m.Role)
case "user":
role = colorGreen(m.Role)
default:
role = colorDim(m.Role)
}
fmt.Printf("%s [%s]\n", colorYellow("│"), role)
// Indent content
var contentStr string
if str, ok := m.Content.(string); ok {
contentStr = str
}
lines := strings.Split(contentStr, "\n")
for _, line := range lines {
if len(line) > 80 {
fmt.Printf("%s %s...\n", colorYellow("│"), line[:77])
} else {
fmt.Printf("%s %s\n", colorYellow("│"), line)
}
}
}
fmt.Println(colorYellow("└─────────────────────────────────────────────────────────────"))
}
// printDebugResponse prints the incoming response
func printDebugResponse(content string, resp *Response) {
fmt.Println()
fmt.Println(colorGreen("┌─────────────────────────────────────────────────────────────"))
fmt.Printf("%s DEBUG RESPONSE\n", colorGreen("│"))
fmt.Println(colorGreen("├─────────────────────────────────────────────────────────────"))
lines := strings.Split(content, "\n")
for _, line := range lines {
fmt.Printf("%s %s\n", colorGreen("│"), line)
}
fmt.Println(colorGreen("├─────────────────────────────────────────────────────────────"))
fmt.Printf("%s Tokens: prompt=%d, completion=%d, total=%d\n",
colorGreen("│"),
resp.Usage.PromptTokens,
resp.Usage.CompletionTokens,
resp.Usage.TotalTokens,
)
fmt.Println(colorGreen("└─────────────────────────────────────────────────────────────"))
}
// printPrettyResponse prints a formatted response
func printPrettyResponse(model Model, content string) {
fmt.Println()
fmt.Printf("%s %s\n", colorCyan("▸"), colorDim(string(model)))
fmt.Println(colorDim("─────────────────────────────────────────────────────────────"))
fmt.Println(content)
fmt.Println()
}
// printPrettyConversation prints a conversation exchange
func printPrettyConversation(model Model, userMsg, assistantMsg string) {
fmt.Println()
fmt.Printf("%s %s\n", colorGreen("You:"), userMsg)
fmt.Println()
fmt.Printf("%s %s\n", colorBlue(string(model)+":"), "")
fmt.Println(assistantMsg)
fmt.Println()
}