支持流式输出思考过程与思考模式配置
This commit is contained in:
@@ -38,12 +38,29 @@ func main() {
|
||||
}
|
||||
continue
|
||||
}
|
||||
answer, err := b.Chat(context.Background(), input)
|
||||
fmt.Printf("%s: ", cfg.BotName)
|
||||
thinkStyle, resetStyle := false, false
|
||||
_, err = b.Chat(context.Background(), input,
|
||||
func(text string) {
|
||||
if !thinkStyle {
|
||||
fmt.Print("\x1b[3;90m🧠 ")
|
||||
thinkStyle, resetStyle = true, true
|
||||
}
|
||||
fmt.Print(text)
|
||||
},
|
||||
func(text string) {
|
||||
if resetStyle {
|
||||
fmt.Print("\x1b[0m")
|
||||
thinkStyle, resetStyle = false, false
|
||||
}
|
||||
fmt.Print(text)
|
||||
},
|
||||
)
|
||||
fmt.Println()
|
||||
if err != nil {
|
||||
fmt.Printf("⚠️ %v\n", err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("%s: %s\n", cfg.BotName, answer)
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -61,7 +78,9 @@ func handleCommand(b *bot.Bot, input string) bool {
|
||||
fmt.Println("命令列表:")
|
||||
fmt.Println(" /models 列出所有供应商和模型")
|
||||
fmt.Println(" /use <模型> 切换模型,如 /use deepseek-chat 或 /use deepseek/deepseek-chat")
|
||||
fmt.Println(" /info 显示当前供应商和模型")
|
||||
fmt.Println(" /think <on|off> 开启或关闭当前供应商的思考模式")
|
||||
fmt.Println(" /effort <low|high|max> 设置思考强度")
|
||||
fmt.Println(" /info 显示当前供应商、模型和思考配置")
|
||||
fmt.Println(" /exit 退出")
|
||||
case "/models":
|
||||
for _, m := range b.Models() {
|
||||
@@ -78,9 +97,37 @@ func handleCommand(b *bot.Bot, input string) bool {
|
||||
}
|
||||
provider, model := b.Current()
|
||||
fmt.Printf("已切换到 %s/%s (对话历史已保留)\n", provider, model)
|
||||
case "/think":
|
||||
if len(args) == 0 {
|
||||
fmt.Println("用法: /think <on|off>")
|
||||
return true
|
||||
}
|
||||
v := map[string]string{"on": "enabled", "off": "disabled"}[args[0]]
|
||||
if err := b.SetThinking(v); err != nil {
|
||||
fmt.Printf("⚠️ %v\n", err)
|
||||
return true
|
||||
}
|
||||
fmt.Printf("思考模式已%s\n", map[string]string{"enabled": "开启", "disabled": "关闭"}[v])
|
||||
case "/effort":
|
||||
if len(args) == 0 {
|
||||
fmt.Println("用法: /effort <low|high|max>")
|
||||
return true
|
||||
}
|
||||
if err := b.SetEffort(args[0]); err != nil {
|
||||
fmt.Printf("⚠️ %v\n", err)
|
||||
return true
|
||||
}
|
||||
fmt.Printf("思考强度已设置为 %s\n", args[0])
|
||||
case "/info":
|
||||
provider, model := b.Current()
|
||||
fmt.Printf("供应商: %s, 模型: %s\n", provider, model)
|
||||
thinking, effort := b.ThinkingConfig()
|
||||
if thinking == "" {
|
||||
thinking = "enabled(默认)"
|
||||
}
|
||||
if effort == "" {
|
||||
effort = "high(默认)"
|
||||
}
|
||||
fmt.Printf("供应商: %s, 模型: %s, 思考模式: %s, 思考强度: %s\n", provider, model, thinking, effort)
|
||||
default:
|
||||
fmt.Printf("未知命令: %s,输入 /help 查看命令列表\n", cmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user