diff options
author | Grail Finder <wohilas@gmail.com> | 2024-12-09 19:26:26 +0300 |
---|---|---|
committer | Grail Finder <wohilas@gmail.com> | 2024-12-09 19:26:26 +0300 |
commit | 67f36d417fa97c4087e326623508370f60d3d3b8 (patch) | |
tree | 1a4466737b8bd854238d508d48945bde84ad0e31 /bot.go | |
parent | bdd40ea8df60b6b161da3c1d201e9ec05ef743d1 (diff) |
Feat: load char/agent; agent-chat flow
Diffstat (limited to 'bot.go')
-rw-r--r-- | bot.go | 37 |
1 files changed, 33 insertions, 4 deletions
@@ -13,6 +13,7 @@ import ( "net/http" "os" "strings" + "time" "github.com/rivo/tview" ) @@ -192,11 +193,39 @@ func chatToText(showSys bool) string { func applyCharCard(cc *models.CharCard) { cfg.AssistantRole = cc.Role - newChat := []models.RoleMsg{ - {Role: "system", Content: cc.SysPrompt}, - {Role: cfg.AssistantRole, Content: cc.FirstMsg}, + // try to load last active chat + history, err := loadAgentsLastChat(cfg.AssistantRole) + if err != nil { + logger.Warn("failed to load last agent chat;", "agent", cc.Role, "err", err) + history = []models.RoleMsg{ + {Role: "system", Content: cc.SysPrompt}, + {Role: cfg.AssistantRole, Content: cc.FirstMsg}, + } + id, err := store.ChatGetMaxID() + if err != nil { + logger.Error("failed to get max chat id from db;", "id:", id) + // INFO: will rewrite first chat + } + chat := &models.Chat{ + ID: id + 1, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + Agent: cfg.AssistantRole, + } + chat.Name = fmt.Sprintf("%d_%s", chat.ID, cfg.AssistantRole) + chatMap[chat.Name] = chat + activeChatName = chat.Name + } + chatBody.Messages = history +} + +func charToStart(agentName string) bool { + cc, ok := sysMap[agentName] + if !ok { + return false } - chatBody.Messages = newChat + applyCharCard(cc) + return true } // func textToMsg(rawMsg string) models.RoleMsg { |