Enha: charlist in cards
This commit is contained in:
1
bot.go
1
bot.go
@@ -1063,7 +1063,6 @@ func addNewChat(chatName string) {
|
||||
|
||||
func applyCharCard(cc *models.CharCard) {
|
||||
cfg.AssistantRole = cc.Role
|
||||
// FIXME: remove
|
||||
history, err := loadAgentsLastChat(cfg.AssistantRole)
|
||||
if err != nil {
|
||||
// too much action for err != nil; loadAgentsLastChat needs to be split up
|
||||
|
||||
25
helpfuncs.go
25
helpfuncs.go
@@ -164,7 +164,7 @@ func setLogLevel(sl string) {
|
||||
}
|
||||
|
||||
func listRolesWithUser() []string {
|
||||
roles := chatBody.ListRoles()
|
||||
roles := listChatRoles()
|
||||
// Remove user role if it exists in the list (to avoid duplicates and ensure it's at position 0)
|
||||
filteredRoles := make([]string, 0, len(roles))
|
||||
for _, role := range roles {
|
||||
@@ -250,3 +250,26 @@ func randString(n int) string {
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// set of roles within card definition and mention in chat history
|
||||
func listChatRoles() []string {
|
||||
currentChat, ok := chatMap[activeChatName]
|
||||
cbc := chatBody.ListRoles()
|
||||
if !ok {
|
||||
return cbc
|
||||
}
|
||||
currentCard, ok := sysMap[currentChat.Agent]
|
||||
if !ok {
|
||||
// log error
|
||||
logger.Warn("failed to find current card in sysMap", "agent", currentChat.Agent, "sysMap", sysMap)
|
||||
return cbc
|
||||
}
|
||||
charset := []string{}
|
||||
for _, name := range currentCard.Characters {
|
||||
if !strInSlice(name, cbc) {
|
||||
charset = append(charset, name)
|
||||
}
|
||||
}
|
||||
charset = append(charset, cbc...)
|
||||
return charset
|
||||
}
|
||||
|
||||
@@ -31,18 +31,20 @@ func (c *CharCardSpec) Simplify(userName, fpath string) *CharCard {
|
||||
fm := strings.ReplaceAll(strings.ReplaceAll(c.FirstMes, "{{char}}", c.Name), "{{user}}", userName)
|
||||
sysPr := strings.ReplaceAll(strings.ReplaceAll(c.Description, "{{char}}", c.Name), "{{user}}", userName)
|
||||
return &CharCard{
|
||||
SysPrompt: sysPr,
|
||||
FirstMsg: fm,
|
||||
Role: c.Name,
|
||||
FilePath: fpath,
|
||||
SysPrompt: sysPr,
|
||||
FirstMsg: fm,
|
||||
Role: c.Name,
|
||||
FilePath: fpath,
|
||||
Characters: []string{c.Name, userName},
|
||||
}
|
||||
}
|
||||
|
||||
type CharCard struct {
|
||||
SysPrompt string `json:"sys_prompt"`
|
||||
FirstMsg string `json:"first_msg"`
|
||||
Role string `json:"role"`
|
||||
FilePath string `json:"filepath"`
|
||||
SysPrompt string `json:"sys_prompt"`
|
||||
FirstMsg string `json:"first_msg"`
|
||||
Role string `json:"role"`
|
||||
Characters []string `json:"chars"`
|
||||
FilePath string `json:"filepath"`
|
||||
}
|
||||
|
||||
func (cc *CharCard) ToSpec(userName string) *CharCardSpec {
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
"role2": "Bob",
|
||||
"role3": "Carl",
|
||||
"filepath": "sysprompts/alice_bob_carl.json",
|
||||
"chars": ["Alice", "Bob", "Carl"],
|
||||
"first_msg": "Hey guys! Want to play Alias like game? I'll tell Bob a word and he needs to describe that word so Carl can guess what it was?"
|
||||
}
|
||||
|
||||
7
tui.go
7
tui.go
@@ -836,7 +836,7 @@ func init() {
|
||||
if injectRole {
|
||||
status = "enabled"
|
||||
}
|
||||
if err := notifyUser("injectRole", fmt.Sprintf("Role injection %s", status)); err != nil {
|
||||
if err := notifyUser("injectRole", "Role injection "+status); err != nil {
|
||||
logger.Error("failed to send notification", "error", err)
|
||||
}
|
||||
updateStatusLine()
|
||||
@@ -1218,7 +1218,8 @@ func init() {
|
||||
if cfg.WriteNextMsgAsCompletionAgent != "" {
|
||||
botPersona = cfg.WriteNextMsgAsCompletionAgent
|
||||
}
|
||||
roles := chatBody.ListRoles()
|
||||
// roles := chatBody.ListRoles()
|
||||
roles := listChatRoles()
|
||||
if len(roles) == 0 {
|
||||
logger.Warn("empty roles in chat")
|
||||
}
|
||||
@@ -1229,11 +1230,9 @@ func init() {
|
||||
if strings.EqualFold(role, botPersona) {
|
||||
if i == len(roles)-1 {
|
||||
cfg.WriteNextMsgAsCompletionAgent = roles[0] // reached last, get first
|
||||
botPersona = cfg.WriteNextMsgAsCompletionAgent
|
||||
break
|
||||
}
|
||||
cfg.WriteNextMsgAsCompletionAgent = roles[i+1] // get next role
|
||||
botPersona = cfg.WriteNextMsgAsCompletionAgent
|
||||
// logger.Info("picked role", "roles", roles, "index", i+1)
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user