diff options
Diffstat (limited to 'models/card.go')
| -rw-r--r-- | models/card.go | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/models/card.go b/models/card.go index adfb030..0bf437c 100644 --- a/models/card.go +++ b/models/card.go @@ -1,6 +1,10 @@ package models -import "strings" +import ( + "crypto/md5" + "fmt" + "strings" +) // https://github.com/malfoyslastname/character-card-spec-v2/blob/main/spec_v2.md // what a bloat; trim to Role->Msg pair and first msg @@ -31,18 +35,26 @@ 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, + ID: ComputeCardID(c.Name, fpath), + SysPrompt: sysPr, + FirstMsg: fm, + Role: c.Name, + FilePath: fpath, + Characters: []string{c.Name, userName}, } } +func ComputeCardID(role, filePath string) string { + return fmt.Sprintf("%x", md5.Sum([]byte(role+filePath))) +} + type CharCard struct { - SysPrompt string `json:"sys_prompt"` - FirstMsg string `json:"first_msg"` - Role string `json:"role"` - FilePath string `json:"filepath"` + ID string `json:"id"` + 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 { |
