Feat: rename user through props

This commit is contained in:
Grail Finder
2025-06-11 11:36:24 +03:00
parent 8902893f6e
commit c2da07ddc3
6 changed files with 139 additions and 81 deletions

View File

@@ -1,8 +1,8 @@
package models
import (
"gf-lt/config"
"fmt"
"gf-lt/config"
"strings"
)
@@ -76,6 +76,27 @@ type ChatBody struct {
Messages []RoleMsg `json:"messages"`
}
func (cb *ChatBody) Rename(oldname, newname string) {
for i, m := range cb.Messages {
cb.Messages[i].Content = strings.ReplaceAll(m.Content, oldname, newname)
cb.Messages[i].Role = strings.ReplaceAll(m.Role, oldname, newname)
}
}
func (cb *ChatBody) ListRoles() []string {
namesMap := make(map[string]struct{})
for _, m := range cb.Messages {
namesMap[m.Role] = struct{}{}
}
resp := make([]string, len(namesMap))
i := 0
for k := range namesMap {
resp[i] = k
i++
}
return resp
}
type ChatToolsBody struct {
Model string `json:"model"`
Messages []RoleMsg `json:"messages"`