renderPrompt 渲染提示词模板
(template string, args map[string]string)
| 81 | |
| 82 | // renderPrompt 渲染提示词模板 |
| 83 | func (e *Executor) renderPrompt(template string, args map[string]string) string { |
| 84 | result := template |
| 85 | |
| 86 | // 替换占位符 |
| 87 | for key, value := range args { |
| 88 | placeholder := "{" + strings.ToUpper(key) + "}" |
| 89 | result = strings.ReplaceAll(result, placeholder, value) |
| 90 | } |
| 91 | |
| 92 | // 替换 {SCRIPT} 占位符 |
| 93 | if e.sandbox != nil { |
| 94 | result = strings.ReplaceAll(result, "{SCRIPT}", "script") |
| 95 | } |
| 96 | |
| 97 | return result |
| 98 | } |
| 99 | |
| 100 | // buildCommandMessage 构建命令消息 |
| 101 | func (e *Executor) buildCommandMessage(cmd *CommandDefinition, prompt string) string { |