Enha: add openrouter parser

This commit is contained in:
Grail Finder
2025-06-23 12:05:20 +03:00
parent c085e0dca1
commit 840b85887b
3 changed files with 125 additions and 55 deletions

View File

@ -27,61 +27,6 @@ var (
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`
)
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 LLMResp struct {
Index int `json:"index"`
Content string `json:"content"`
Tokens []any `json:"tokens"`
IDSlot int `json:"id_slot"`
Stop bool `json:"stop"`
Model string `json:"model"`
TokensPredicted int `json:"tokens_predicted"`
TokensEvaluated int `json:"tokens_evaluated"`
Prompt string `json:"prompt"`
HasNewLine bool `json:"has_new_line"`
Truncated bool `json:"truncated"`
StopType string `json:"stop_type"`
StoppingWord string `json:"stopping_word"`
TokensCached int `json:"tokens_cached"`
}
type MimeResp struct {
Clue string `json:"clue"`
Number string `json:"number"`
Answer []string `json:"words_I_mean_my_team_to_open"`
}
type GusserResp struct {
Guesses []string `json:"guesses"`
CouldBe []string `json:"could_be"`
}
type Bot struct {
Role string `json:"role"`
Team string `json:"team"`
cfg *config.Config `json:"-"`
RoomID string `json:"room_id"` // can we get a room from here?
BotName string `json:"bot_name"`
log *slog.Logger `json:"-"`
LLMParser RespParser `json:"-"`
// channels for communicaton
// channels are not serializable
// SignalsCh chan bool
// DoneCh chan bool
}
func convertToSliceOfStrings(value any) ([]string, error) {
switch v := value.(type) {
case []string:
@ -299,6 +244,8 @@ func NewBot(role, team, name, roomID string, cfg *config.Config, recovery bool)
bot.LLMParser = NewLCPRespParser(bot.log)
if strings.Contains(cfg.LLMConfig.URL, "api.deepseek.com") {
bot.LLMParser = NewDeepSeekParser(bot.log)
} else if strings.Contains(cfg.LLMConfig.URL, "openrouter.ai") {
bot.LLMParser = NewOpenRouterParser(bot.log)
}
// add to room
room, err := getRoomByID(bot.RoomID)