Fix: deepseek mime clue
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
@ -38,6 +39,6 @@ func LoadConfigOrDefault(fn string) *Config {
|
||||
config.ServerConfig.Host = "localhost"
|
||||
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
|
||||
}
|
||||
|
@ -32,6 +32,19 @@ var (
|
||||
// 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 {
|
||||
Clue string `json:"clue"`
|
||||
Number string `json:"number"`
|
||||
@ -77,18 +90,46 @@ func (b *Bot) StartBot() {
|
||||
b.log.Error("bot loop", "error", err)
|
||||
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
|
||||
// if mime -> give clue
|
||||
// if guesser -> open card (does opening one card prompting new loop?)
|
||||
// send notification to sse broker
|
||||
eventName := models.NotifyBacklogPrefix + room.ID
|
||||
eventPayload := ""
|
||||
tempMap := make(map[string]any)
|
||||
switch b.Role {
|
||||
case models.UserRoleMime:
|
||||
// respMap := make(map[string]any)
|
||||
mimeResp := MimeResp{}
|
||||
if err := json.Unmarshal(llmResp, &mimeResp); err != nil {
|
||||
b.log.Error("failed to unmarshal mime resp", "error", err)
|
||||
if err := json.Unmarshal([]byte(sj), &tempMap); err != nil {
|
||||
b.log.Error("failed to unmarshal mime resp", "error", err, "string-json", sj)
|
||||
return
|
||||
}
|
||||
b.log.Info("mime resp log", "mimeResp", tempMap)
|
||||
mimeResp.Clue = tempMap["clue"].(string)
|
||||
mimeResp.Number = tempMap["number"].(string)
|
||||
action := models.Action{
|
||||
Actor: b.BotName,
|
||||
ActorColor: b.Team,
|
||||
@ -99,20 +140,26 @@ func (b *Bot) StartBot() {
|
||||
}
|
||||
room.ActionHistory = append(room.ActionHistory, action)
|
||||
room.MimeDone = true
|
||||
// notify(models.NotifyBacklogPrefix+room.ID, clue+num)
|
||||
eventPayload = mimeResp.Clue + mimeResp.Number
|
||||
case models.UserRoleGuesser:
|
||||
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)
|
||||
return
|
||||
}
|
||||
b.log.Info("mime resp log", "guesserResp", gr)
|
||||
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
|
||||
}
|
||||
broker.Notifier.Notifier <- broker.NotificationEvent{
|
||||
EventName: "",
|
||||
Payload: "",
|
||||
EventName: eventName,
|
||||
Payload: eventPayload,
|
||||
}
|
||||
// update room info
|
||||
case <-DoneChanMap[b.BotName]:
|
||||
|
Reference in New Issue
Block a user