-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.go
More file actions
37 lines (32 loc) · 1.35 KB
/
Copy pathtemplate.go
File metadata and controls
37 lines (32 loc) · 1.35 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
package main
import (
_ "embed"
"encoding/json"
"fmt"
"strings"
"qoder2api-plugin/internal/cosy"
)
// baseprompt.json 是 Qoder 上游 agent_chat_generation 的请求模板(移植自 qoder2api)。
// 模板里保留了 {UUIDn}/{TIME1} 占位符:每次建 Bridge 时替换为实际值再解析成 JSON。
//
//go:embed baseprompt.json
var basePromptRaw []byte
// buildTemplateBase 构造一次请求模板。
//
// 与 qoder2api 的差异:这里对解析失败返回错误而不是静默忽略。模板解析失败意味着
// 所有上游请求都会失真,静默继续会让问题表现成"模型答非所问"这种难以定位的现象。
func buildTemplateBase() (map[string]interface{}, error) {
template := string(basePromptRaw)
for _, placeholder := range []string{"{UUID1}", "{UUID2}", "{UUID3}", "{UUID4}", "{UUID5}"} {
template = strings.ReplaceAll(template, placeholder, cosy.NewUUID())
}
template = strings.ReplaceAll(template, "{TIME1}", fmt.Sprintf("%d", cosy.UnixMs()))
var templateBase map[string]interface{}
if errUnmarshal := json.Unmarshal([]byte(template), &templateBase); errUnmarshal != nil {
return nil, fmt.Errorf("baseprompt.json 模板解析失败(内嵌资源损坏或占位符未替换): %w", errUnmarshal)
}
if templateBase == nil {
return nil, fmt.Errorf("baseprompt.json 模板为空")
}
return templateBase, nil
}