-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompts.go
More file actions
54 lines (45 loc) · 1.12 KB
/
Copy pathprompts.go
File metadata and controls
54 lines (45 loc) · 1.12 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
package main
import (
"bytes"
_ "embed"
"fmt"
"text/template"
)
//go:embed prompts/agent-reply.tmpl
var agentReplyTmplStr string
var agentReplyTmpl = template.Must(template.New("agent-reply").Parse(agentReplyTmplStr))
// formatMessagesData is the data passed to the "format-messages" template.
type formatMessagesData struct {
Messages []messageData
Files []fileData
}
type messageData struct {
Text string
IsVoice bool
}
type fileData struct {
Path string
Type string
Size string
}
// replyInstructionsData is the data passed to the "reply-instructions" template.
type replyInstructionsData struct {
IsVoice bool
}
func execTemplate(name string, data any) string {
var buf bytes.Buffer
if err := agentReplyTmpl.ExecuteTemplate(&buf, name, data); err != nil {
panic(fmt.Sprintf("template %s: %v", name, err))
}
return buf.String()
}
// formatSize returns a human-readable size string.
func formatSize(size int64) string {
if size >= 1024*1024 {
return fmt.Sprintf("%.1fMB", float64(size)/1024/1024)
}
if size >= 1024 {
return fmt.Sprintf("%.0fKB", float64(size)/1024)
}
return fmt.Sprintf("%dB", size)
}