增加多个ai
This commit is contained in:
@@ -17,12 +17,11 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("加载配置失败: %v", err)
|
||||
}
|
||||
if cfg.APIKey == "" {
|
||||
log.Println("提示: 未配置 api_key,请编辑 data/config.yaml")
|
||||
}
|
||||
fmt.Printf("🤖 %s 已启动 (模型: %s)。输入问题开始对话,输入 /exit 退出。\n", cfg.BotName, cfg.Model)
|
||||
|
||||
b := bot.New(cfg)
|
||||
provider, model := b.Current()
|
||||
fmt.Printf("🤖 %s 已启动 (供应商: %s, 模型: %s)。输入问题开始对话,输入 /help 查看命令。\n",
|
||||
cfg.BotName, provider, model)
|
||||
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for {
|
||||
fmt.Print("你: ")
|
||||
@@ -33,9 +32,11 @@ func main() {
|
||||
if input == "" {
|
||||
continue
|
||||
}
|
||||
if input == "/exit" || input == "/quit" {
|
||||
fmt.Println("再见!")
|
||||
break
|
||||
if strings.HasPrefix(input, "/") {
|
||||
if !handleCommand(b, input) {
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
answer, err := b.Chat(context.Background(), input)
|
||||
if err != nil {
|
||||
@@ -48,3 +49,40 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleCommand(b *bot.Bot, input string) bool {
|
||||
fields := strings.Fields(input)
|
||||
cmd, args := fields[0], fields[1:]
|
||||
switch cmd {
|
||||
case "/exit", "/quit":
|
||||
fmt.Println("再见!")
|
||||
return false
|
||||
case "/help":
|
||||
fmt.Println("命令列表:")
|
||||
fmt.Println(" /models 列出所有供应商和模型")
|
||||
fmt.Println(" /use <模型> 切换模型,如 /use deepseek-chat 或 /use deepseek/deepseek-chat")
|
||||
fmt.Println(" /info 显示当前供应商和模型")
|
||||
fmt.Println(" /exit 退出")
|
||||
case "/models":
|
||||
for _, m := range b.Models() {
|
||||
fmt.Println(" " + m)
|
||||
}
|
||||
case "/use":
|
||||
if len(args) == 0 {
|
||||
fmt.Println("用法: /use <模型>,如 /use deepseek-chat")
|
||||
return true
|
||||
}
|
||||
if err := b.SwitchModel(args[0]); err != nil {
|
||||
fmt.Printf("⚠️ %v\n", err)
|
||||
return true
|
||||
}
|
||||
provider, model := b.Current()
|
||||
fmt.Printf("已切换到 %s/%s (对话历史已保留)\n", provider, model)
|
||||
case "/info":
|
||||
provider, model := b.Current()
|
||||
fmt.Printf("供应商: %s, 模型: %s\n", provider, model)
|
||||
default:
|
||||
fmt.Printf("未知命令: %s,输入 /help 查看命令列表\n", cmd)
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user