Fix: config & ds prompt

This commit is contained in:
Grail Finder
2025-05-27 15:42:30 +03:00
parent c155654d5f
commit 6dcc3f0309
2 changed files with 21 additions and 9 deletions

View File

@ -20,8 +20,8 @@ type ServerConfig struct {
} }
type LLMConfig struct { type LLMConfig struct {
URL string `toml:"LLM_URL"` URL string `toml:"URL"`
TOKEN string `toml:"LLM_TOKEN"` TOKEN string `toml:"TOKEN"`
} }
func LoadConfigOrDefault(fn string) *Config { func LoadConfigOrDefault(fn string) *Config {
@ -38,5 +38,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)
return config return config
} }

View File

@ -25,6 +25,8 @@ var (
// botname -> channel // botname -> channel
SignalChanMap = make(map[string]chan bool) SignalChanMap = make(map[string]chan bool)
DoneChanMap = make(map[string]chan bool) DoneChanMap = make(map[string]chan bool)
// got prompt: control character (\\u0000-\\u001F) found while parsing a string at line 4 column 0
MimePrompt = `we are playing alias;\nyou are a mime (player who gives a clue of one noun word and number of cards you expect them to open) of the red team (people who would guess by your clue want open the red cards);\nplease return your clue, number of cards to open and what words you mean them to find using that clue in json like:\n{\n\"clue\": \"one-word-noun\",\n\"number\": \"number-from-0-to-9\",\n\"word_I_mean_my_team_to_open\": [\"this\", \"that\", ...]\n}\nthe team who openes all their cards first wins.\nplease return json only.\nunopen Blue cards left: %d;\nunopen Red cards left: %d;\nhere is the game info in json:\n%s`
) )
type Bot struct { type Bot struct {
@ -185,12 +187,21 @@ func (b *Bot) BuildPrompt(room *models.Room) string {
} }
toText["cards"] = copiedCards toText["cards"] = copiedCards
} }
data, err := json.MarshalIndent(toText, "", " ") data, err := json.Marshal(toText)
if err != nil { if err != nil {
// log b.log.Error("failed to marshal", "error", err)
return "" return ""
} }
return string(data) // Escape the JSON string for inclusion in another JSON field
escapedData := strings.ReplaceAll(string(data), `"`, `\"`)
if b.Role == models.UserRoleMime {
return fmt.Sprintf(MimePrompt, room.BlueCounter, room.RedCounter, escapedData)
}
if b.Role == models.UserRoleMime {
// TODO:
return ""
}
return ""
} }
func (b *Bot) CallLLM(prompt string) error { func (b *Bot) CallLLM(prompt string) error {
@ -213,7 +224,7 @@ func (b *Bot) CallLLM(prompt string) error {
client := &http.Client{} client := &http.Client{}
req, err := http.NewRequest(method, b.cfg.LLMConfig.URL, payload) req, err := http.NewRequest(method, b.cfg.LLMConfig.URL, payload)
if err != nil { if err != nil {
fmt.Println(err) b.log.Error("failed to make new request", "error", err, "url", b.cfg.LLMConfig.URL)
return err return err
} }
req.Header.Add("Content-Type", "application/json") req.Header.Add("Content-Type", "application/json")
@ -221,15 +232,15 @@ func (b *Bot) CallLLM(prompt string) error {
req.Header.Add("Authorization", "Bearer "+b.cfg.LLMConfig.TOKEN) req.Header.Add("Authorization", "Bearer "+b.cfg.LLMConfig.TOKEN)
res, err := client.Do(req) res, err := client.Do(req)
if err != nil { if err != nil {
fmt.Println(err) b.log.Error("failed to make request", "error", err, "url", b.cfg.LLMConfig.URL)
return err return err
} }
defer res.Body.Close() defer res.Body.Close()
body, err := io.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
fmt.Println(err) b.log.Error("failed to read resp body", "error", err, "url", b.cfg.LLMConfig.URL)
return err return err
} }
fmt.Println(string(body)) b.log.Debug("llm resp", "body", string(body))
return nil return nil
} }