Fix: openrouter payload, player restore (relogin)
This commit is contained in:
		| @@ -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` | ||||
| 	// 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` | ||||
| 	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) { | ||||
| @@ -210,15 +210,15 @@ func (b *Bot) StartBot() { | ||||
| 				b.log.Error("failed to save room", "error", err) | ||||
| 				continue | ||||
| 			} | ||||
| 			// will it notify itself? | ||||
| 			if botName := room.WhichBotToMove(); botName != "" { | ||||
| 				b.log.Debug("notifying bot", "name", botName) | ||||
| 				SignalChanMap[botName] <- true | ||||
| 			} | ||||
| 			broker.Notifier.Notifier <- broker.NotificationEvent{ | ||||
| 				EventName: eventName, | ||||
| 				Payload:   eventPayload, | ||||
| 			} | ||||
| 		// update room info | ||||
| 			continue | ||||
| 		case <-DoneChanMap[b.BotName]: | ||||
| 			b.log.Debug("got done signal", "bot-name", b.BotName) | ||||
| 			return | ||||
| @@ -295,8 +295,9 @@ func NewBot(role, team, name, roomID string, cfg *config.Config, recovery bool) | ||||
| 	if err := saveBot(bot); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	SignalChanMap[bot.BotName] = make(chan bool) | ||||
| 	DoneChanMap[bot.BotName] = make(chan bool) | ||||
| 	// buffered channel to send to it in the same goroutine | ||||
| 	SignalChanMap[bot.BotName] = make(chan bool, 1) | ||||
| 	DoneChanMap[bot.BotName] = make(chan bool, 1) | ||||
| 	go bot.StartBot() // run bot routine | ||||
| 	return bot, nil | ||||
| } | ||||
| @@ -335,12 +336,12 @@ func saveRoom(room *models.Room) error { | ||||
|  | ||||
| func (b *Bot) BuildSimpleGuesserPrompt(room *models.Room) string { | ||||
| 	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)) | ||||
| 	for i, card := range room.Cards { | ||||
| 		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 { | ||||
| @@ -354,16 +355,6 @@ func (b *Bot) BuildPrompt(room *models.Room) string { | ||||
| 	if b.Role == models.UserRoleMime { | ||||
| 		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) | ||||
| 	if err != nil { | ||||
| 		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 { | ||||
| 	return strings.NewReader(fmt.Sprintf(`{ | ||||
| 	strPayload := fmt.Sprintf(`{ | ||||
| 	"model": "deepseek/deepseek-chat-v3-0324:free", | ||||
| 	"messages": [ | ||||
| 		{ | ||||
| 		"role": "user", | ||||
| 		"content": %s | ||||
| 		"content": "%s" | ||||
| 		} | ||||
| 	] | ||||
| 	}`, prompt)) | ||||
| 	}`, prompt) | ||||
| 	p.log.Debug("made openrouter payload", "payload", strPayload) | ||||
| 	return strings.NewReader(strPayload) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder