Fix: openrouter payload, player restore (relogin)
This commit is contained in:
@ -84,7 +84,11 @@ func HandleFrontLogin(w http.ResponseWriter, r *http.Request) {
|
|||||||
abortWithError(w, err.Error())
|
abortWithError(w, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userstate := models.InitState(cleanName)
|
// check if that user was already in db
|
||||||
|
userstate, err := loadState(cleanName)
|
||||||
|
if err != nil || userstate == nil {
|
||||||
|
userstate = models.InitState(cleanName)
|
||||||
|
}
|
||||||
fi := &models.FullInfo{
|
fi := &models.FullInfo{
|
||||||
State: userstate,
|
State: userstate,
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ var (
|
|||||||
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 %s team (people who would guess by your clue want open the %s 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\"words_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`
|
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 %s team (people who would guess by your clue want open the %s 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\"words_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`
|
||||||
// TODO: simplify; bot gets confused; so show it only unrevealed cards and last clue (maybe older clues as well);
|
// TODO: simplify; bot gets confused; so show it only unrevealed cards and last clue (maybe older clues as well);
|
||||||
GuesserPrompt = `we are playing alias;\nyou are to guess words of the %s team (you want open %s cards) by given clue and a number of meant guesses;\nplease return your guesses and words that could be meant by the clue, but you do not wish to open yet, in json like:\n{\n\"guesses\": [\"word1\", \"word2\", ...],\n\"could_be\": [\"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 cards (and other info), you need to choose revealed==false words:\n%s`
|
GuesserPrompt = `we are playing alias;\nyou are to guess words of the %s team (you want open %s cards) by given clue and a number of meant guesses;\nplease return your guesses and words that could be meant by the clue, but you do not wish to open yet, in json like:\n{\n\"guesses\": [\"word1\", \"word2\", ...],\n\"could_be\": [\"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 cards (and other info), you need to choose revealed==false words:\n%s`
|
||||||
GuesserSimplePrompt = `we are playing game of alias;\n you were given a clue: \"%s\";\nplease return your guess and words that could be meant by the clue, but you do not wish to open yet, in json like:\n{\n\"guess\": \"most_relevant_word_to_the_clue\",\n\"could_be\": [\"this\", \"that\", ...]\n}\nhere is the words that left:\n%s`
|
GuesserSimplePrompt = `we are playing game of alias;\n you were given a clue: \"%s\";\nplease return your guess and words that could be meant by the clue, but you do not wish to open yet, in json like:\n{\n\"guess\": \"most_relevant_word_to_the_clue\",\n\"could_be\": [\"this\", \"that\", ...]\n}\nhere is the words that left:\n%v`
|
||||||
)
|
)
|
||||||
|
|
||||||
func convertToSliceOfStrings(value any) ([]string, error) {
|
func convertToSliceOfStrings(value any) ([]string, error) {
|
||||||
@ -210,15 +210,15 @@ func (b *Bot) StartBot() {
|
|||||||
b.log.Error("failed to save room", "error", err)
|
b.log.Error("failed to save room", "error", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// will it notify itself?
|
|
||||||
if botName := room.WhichBotToMove(); botName != "" {
|
if botName := room.WhichBotToMove(); botName != "" {
|
||||||
|
b.log.Debug("notifying bot", "name", botName)
|
||||||
SignalChanMap[botName] <- true
|
SignalChanMap[botName] <- true
|
||||||
}
|
}
|
||||||
broker.Notifier.Notifier <- broker.NotificationEvent{
|
broker.Notifier.Notifier <- broker.NotificationEvent{
|
||||||
EventName: eventName,
|
EventName: eventName,
|
||||||
Payload: eventPayload,
|
Payload: eventPayload,
|
||||||
}
|
}
|
||||||
// update room info
|
continue
|
||||||
case <-DoneChanMap[b.BotName]:
|
case <-DoneChanMap[b.BotName]:
|
||||||
b.log.Debug("got done signal", "bot-name", b.BotName)
|
b.log.Debug("got done signal", "bot-name", b.BotName)
|
||||||
return
|
return
|
||||||
@ -295,8 +295,9 @@ func NewBot(role, team, name, roomID string, cfg *config.Config, recovery bool)
|
|||||||
if err := saveBot(bot); err != nil {
|
if err := saveBot(bot); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
SignalChanMap[bot.BotName] = make(chan bool)
|
// buffered channel to send to it in the same goroutine
|
||||||
DoneChanMap[bot.BotName] = make(chan bool)
|
SignalChanMap[bot.BotName] = make(chan bool, 1)
|
||||||
|
DoneChanMap[bot.BotName] = make(chan bool, 1)
|
||||||
go bot.StartBot() // run bot routine
|
go bot.StartBot() // run bot routine
|
||||||
return bot, nil
|
return bot, nil
|
||||||
}
|
}
|
||||||
@ -335,12 +336,12 @@ func saveRoom(room *models.Room) error {
|
|||||||
|
|
||||||
func (b *Bot) BuildSimpleGuesserPrompt(room *models.Room) string {
|
func (b *Bot) BuildSimpleGuesserPrompt(room *models.Room) string {
|
||||||
clue := room.ActionHistory[len(room.ActionHistory)-1].Word
|
clue := room.ActionHistory[len(room.ActionHistory)-1].Word
|
||||||
number := room.ActionHistory[len(room.ActionHistory)-1].Number
|
// number := room.ActionHistory[len(room.ActionHistory)-1].Number
|
||||||
words := make([]string, len(room.Cards))
|
words := make([]string, len(room.Cards))
|
||||||
for i, card := range room.Cards {
|
for i, card := range room.Cards {
|
||||||
words[i] = card.Word
|
words[i] = card.Word
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(GuesserSimplePrompt, clue, number, words)
|
return fmt.Sprintf(GuesserSimplePrompt, clue, words)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) BuildPrompt(room *models.Room) string {
|
func (b *Bot) BuildPrompt(room *models.Room) string {
|
||||||
@ -354,16 +355,6 @@ func (b *Bot) BuildPrompt(room *models.Room) string {
|
|||||||
if b.Role == models.UserRoleMime {
|
if b.Role == models.UserRoleMime {
|
||||||
toText["cards"] = room.Cards
|
toText["cards"] = room.Cards
|
||||||
}
|
}
|
||||||
// if b.Role == models.UserRoleGuesser {
|
|
||||||
// copiedCards := make([]models.WordCard, len(room.Cards))
|
|
||||||
// copy(copiedCards, room.Cards)
|
|
||||||
// for i, card := range copiedCards {
|
|
||||||
// if !card.Revealed {
|
|
||||||
// copiedCards[i].Color = models.WordColorUknown
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// toText["cards"] = copiedCards
|
|
||||||
// }
|
|
||||||
data, err := json.Marshal(toText)
|
data, err := json.Marshal(toText)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.log.Error("failed to marshal", "error", err)
|
b.log.Error("failed to marshal", "error", err)
|
||||||
|
@ -160,13 +160,15 @@ func (p *openRouterParser) ParseBytes(body []byte) (map[string]any, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *openRouterParser) MakePayload(prompt string) io.Reader {
|
func (p *openRouterParser) MakePayload(prompt string) io.Reader {
|
||||||
return strings.NewReader(fmt.Sprintf(`{
|
strPayload := fmt.Sprintf(`{
|
||||||
"model": "deepseek/deepseek-chat-v3-0324:free",
|
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||||
"messages": [
|
"messages": [
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": %s
|
"content": "%s"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}`, prompt))
|
}`, prompt)
|
||||||
|
p.log.Debug("made openrouter payload", "payload", strPayload)
|
||||||
|
return strings.NewReader(strPayload)
|
||||||
}
|
}
|
||||||
|
1
todos.md
1
todos.md
@ -17,6 +17,7 @@
|
|||||||
- ended turn action to backlog;
|
- ended turn action to backlog;
|
||||||
- clear indication that model (llm) is thinking / answered;
|
- clear indication that model (llm) is thinking / answered;
|
||||||
- instead of guessing all words at ones, ask only for 1 word to be open.
|
- instead of guessing all words at ones, ask only for 1 word to be open.
|
||||||
|
- ways to remove bots from teams;
|
||||||
|
|
||||||
#### sse points
|
#### sse points
|
||||||
- clue sse update;
|
- clue sse update;
|
||||||
|
Reference in New Issue
Block a user