Enha: add bool to apply card
This commit is contained in:
8
bot.go
8
bot.go
@@ -1150,16 +1150,16 @@ func addNewChat(chatName string) {
|
|||||||
activeChatName = chat.Name
|
activeChatName = chat.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyCharCard(cc *models.CharCard) {
|
func applyCharCard(cc *models.CharCard, loadHistory bool) {
|
||||||
cfg.AssistantRole = cc.Role
|
cfg.AssistantRole = cc.Role
|
||||||
history, err := loadAgentsLastChat(cfg.AssistantRole)
|
history, err := loadAgentsLastChat(cfg.AssistantRole)
|
||||||
if err != nil {
|
if err != nil || !loadHistory {
|
||||||
// too much action for err != nil; loadAgentsLastChat needs to be split up
|
// too much action for err != nil; loadAgentsLastChat needs to be split up
|
||||||
logger.Warn("failed to load last agent chat;", "agent", cc.Role, "err", err)
|
|
||||||
history = []models.RoleMsg{
|
history = []models.RoleMsg{
|
||||||
{Role: "system", Content: cc.SysPrompt},
|
{Role: "system", Content: cc.SysPrompt},
|
||||||
{Role: cfg.AssistantRole, Content: cc.FirstMsg},
|
{Role: cfg.AssistantRole, Content: cc.FirstMsg},
|
||||||
}
|
}
|
||||||
|
logger.Warn("failed to load last agent chat;", "agent", cc.Role, "err", err, "new_history", history)
|
||||||
addNewChat("")
|
addNewChat("")
|
||||||
}
|
}
|
||||||
chatBody.Messages = history
|
chatBody.Messages = history
|
||||||
@@ -1170,7 +1170,7 @@ func charToStart(agentName string) bool {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
applyCharCard(cc)
|
applyCharCard(cc, true)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ func makeChatTable(chatMap map[string]models.Chat) *tview.Table {
|
|||||||
}
|
}
|
||||||
// Update sysMap with fresh card data
|
// Update sysMap with fresh card data
|
||||||
sysMap[agentName] = newCard
|
sysMap[agentName] = newCard
|
||||||
applyCharCard(newCard)
|
applyCharCard(newCard, false)
|
||||||
startNewChat()
|
startNewChat()
|
||||||
pages.RemovePage(historyPage)
|
pages.RemovePage(historyPage)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user