Feat: bot failed state to show/hide llm restart btn
This commit is contained in:
@ -18,7 +18,7 @@
|
||||
if (!window.actionHistoryScrollSet) {
|
||||
htmx.onLoad(function(target) {
|
||||
if (target.id === 'actionHistoryContainer') {
|
||||
target.scrollTop = target.scrollHeight;
|
||||
target.scrollToBottom();
|
||||
}
|
||||
});
|
||||
window.actionHistoryScrollSet = true;
|
||||
|
@ -74,7 +74,7 @@
|
||||
{{end}}
|
||||
</div>
|
||||
<div>
|
||||
{{if and (eq .State.Username .Room.CreatorName) (.Room.IsRunning)}}
|
||||
{{if and (eq .State.Username .Room.CreatorName) (.Room.BotFailed)}}
|
||||
<button hx-get="/renotify-bot" hx-swap="none" class="bg-gray-100 text-black px-1 py-1 rounded">Btn in case llm call failed</button>
|
||||
{{end}}
|
||||
</div>
|
||||
|
@ -188,6 +188,11 @@ func (b *Bot) BotMove() {
|
||||
b.log.Error("bot loop", "error", err)
|
||||
return
|
||||
}
|
||||
if room.BotFailed {
|
||||
if err := repo.RoomUnSetBotFailed(context.Background(), room.ID); err != nil {
|
||||
b.log.Error("failed to unset bot failed bool", "error", err)
|
||||
}
|
||||
}
|
||||
// eventName := models.NotifyBacklogPrefix + room.ID
|
||||
eventName := models.NotifyRoomUpdatePrefix + room.ID
|
||||
eventPayload := ""
|
||||
@ -231,6 +236,9 @@ func (b *Bot) BotMove() {
|
||||
b.log.Warn("failed to write to journal", "entry", lj)
|
||||
}
|
||||
b.log.Error("bot loop", "error", err)
|
||||
if err := repo.RoomSetBotFailed(context.Background(), room.ID); err != nil {
|
||||
b.log.Error("failed to set bot failed bool", "error", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
tempMap, err := b.LLMParser.ParseBytes(llmResp)
|
||||
@ -666,16 +674,5 @@ func (b *Bot) CallLLM(prompt string) ([]byte, error) {
|
||||
b.log.Debug("llm resp", "body", string(body), "url", b.cfg.LLMConfig.URL, "attempt", attempt)
|
||||
return body, nil
|
||||
}
|
||||
entry := fmt.Sprintf("bot '%s' exceeded attempts to call llm;", b.BotName)
|
||||
lj := models.Journal{
|
||||
Entry: entry,
|
||||
Username: b.BotName,
|
||||
RoomID: b.RoomID,
|
||||
}
|
||||
if err := repo.JournalCreate(context.Background(), &lj); err != nil {
|
||||
b.log.Warn("failed to write to journal", "entry", lj)
|
||||
}
|
||||
// notify room
|
||||
// This line should not be reached because each error path returns in the loop.
|
||||
return nil, errors.New("unknown error in retry loop")
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ CREATE TABLE rooms (
|
||||
mime_done BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
is_running BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
is_over BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
bot_failed BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
team_won TEXT NOT NULL DEFAULT '',
|
||||
room_link TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
@ -178,6 +178,8 @@ type Room struct {
|
||||
BotMap map[string]BotPlayer `db:"-"`
|
||||
LogJournal []Journal `db:"-"`
|
||||
Settings GameSettings `db:"-"`
|
||||
//
|
||||
BotFailed bool `db:"bot_failed"`
|
||||
}
|
||||
|
||||
func (r *Room) FindColor(word string) (WordColor, bool) {
|
||||
|
@ -15,6 +15,20 @@ type RoomsRepo interface {
|
||||
RoomCreate(ctx context.Context, room *models.Room) error
|
||||
RoomDeleteByID(ctx context.Context, id string) error
|
||||
RoomUpdate(ctx context.Context, room *models.Room) error
|
||||
RoomSetBotFailed(ctx context.Context, roomID string) error
|
||||
RoomUnSetBotFailed(ctx context.Context, roomID string) error
|
||||
}
|
||||
|
||||
func (p *RepoProvider) RoomSetBotFailed(ctx context.Context, roomID string) error {
|
||||
db := getDB(ctx, p.DB)
|
||||
_, err := db.ExecContext(ctx, "UPDATE rooms SET bot_failed = true WHERE id = ?", roomID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *RepoProvider) RoomUnSetBotFailed(ctx context.Context, roomID string) error {
|
||||
db := getDB(ctx, p.DB)
|
||||
_, err := db.ExecContext(ctx, "UPDATE rooms SET bot_failed = false WHERE id = ?", roomID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *RepoProvider) RoomList(ctx context.Context) ([]*models.Room, error) {
|
||||
|
Reference in New Issue
Block a user