Fix: deepseek mime clue

This commit is contained in:
Grail Finder
2025-05-29 10:21:47 +03:00
parent e8507463e0
commit 9ebce0a7d0
2 changed files with 56 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package config package config
import ( import (
"fmt"
"log/slog" "log/slog"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
@ -38,6 +39,6 @@ func LoadConfigOrDefault(fn string) *Config {
config.ServerConfig.Host = "localhost" config.ServerConfig.Host = "localhost"
config.ServerConfig.Port = "3000" config.ServerConfig.Port = "3000"
} }
// fmt.Printf("config debug; config.LLMConfig.URL: %s\n", config.LLMConfig.URL) fmt.Printf("config debug; config.LLMConfig.URL: %s\n", config.LLMConfig.URL)
return config return config
} }

View File

@ -32,6 +32,19 @@ var (
// notifier = // notifier =
) )
type DSResp struct {
ID string `json:"id"`
Choices []struct {
Text string `json:"text"`
Index int `json:"index"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
Created int `json:"created"`
Model string `json:"model"`
SystemFingerprint string `json:"system_fingerprint"`
Object string `json:"object"`
}
type MimeResp struct { type MimeResp struct {
Clue string `json:"clue"` Clue string `json:"clue"`
Number string `json:"number"` Number string `json:"number"`
@ -77,18 +90,46 @@ func (b *Bot) StartBot() {
b.log.Error("bot loop", "error", err) b.log.Error("bot loop", "error", err)
return return
} }
dsResp := DSResp{}
if err := json.Unmarshal(llmResp, &dsResp); err != nil {
b.log.Error("failed to unmarshall", "error", err)
return
}
if len(dsResp.Choices) == 0 {
b.log.Error("empty choices", "dsResp", dsResp)
return
}
text := dsResp.Choices[0].Text
li := strings.Index(text, "{")
ri := strings.LastIndex(text, "}")
if li < 0 || ri < 1 {
b.log.Error("not a json", "msg", text)
return
}
sj := text[li : ri+1]
// jb, err := json.Marshal(sj)
// if err != nil {
// b.log.Error("failed to marshal", "error", err, "string-json", sj)
// return
// }
// parse response // parse response
// if mime -> give clue // if mime -> give clue
// if guesser -> open card (does opening one card prompting new loop?) // if guesser -> open card (does opening one card prompting new loop?)
// send notification to sse broker // send notification to sse broker
eventName := models.NotifyBacklogPrefix + room.ID
eventPayload := ""
tempMap := make(map[string]any)
switch b.Role { switch b.Role {
case models.UserRoleMime: case models.UserRoleMime:
// respMap := make(map[string]any) // respMap := make(map[string]any)
mimeResp := MimeResp{} mimeResp := MimeResp{}
if err := json.Unmarshal(llmResp, &mimeResp); err != nil { if err := json.Unmarshal([]byte(sj), &tempMap); err != nil {
b.log.Error("failed to unmarshal mime resp", "error", err) b.log.Error("failed to unmarshal mime resp", "error", err, "string-json", sj)
return return
} }
b.log.Info("mime resp log", "mimeResp", tempMap)
mimeResp.Clue = tempMap["clue"].(string)
mimeResp.Number = tempMap["number"].(string)
action := models.Action{ action := models.Action{
Actor: b.BotName, Actor: b.BotName,
ActorColor: b.Team, ActorColor: b.Team,
@ -99,20 +140,26 @@ func (b *Bot) StartBot() {
} }
room.ActionHistory = append(room.ActionHistory, action) room.ActionHistory = append(room.ActionHistory, action)
room.MimeDone = true room.MimeDone = true
// notify(models.NotifyBacklogPrefix+room.ID, clue+num) eventPayload = mimeResp.Clue + mimeResp.Number
case models.UserRoleGuesser: case models.UserRoleGuesser:
gr := GusserResp{} gr := GusserResp{}
if err := json.Unmarshal(llmResp, &gr); err != nil { if err := json.Unmarshal([]byte(sj), &gr); err != nil {
b.log.Error("failed to unmarshal guesser resp", "error", err) b.log.Error("failed to unmarshal guesser resp", "error", err)
return return
} }
b.log.Info("mime resp log", "guesserResp", gr)
default: default:
b.log.Error("unexpected role", "role", b.Role) b.log.Error("unexpected role", "role", b.Role, "llmResp", sj)
return
}
// save room
if err := saveRoom(room); err != nil {
b.log.Error("failed to save room", "error", err)
return return
} }
broker.Notifier.Notifier <- broker.NotificationEvent{ broker.Notifier.Notifier <- broker.NotificationEvent{
EventName: "", EventName: eventName,
Payload: "", Payload: eventPayload,
} }
// update room info // update room info
case <-DoneChanMap[b.BotName]: case <-DoneChanMap[b.BotName]: