diff options
| author | Grail Finder <wohilas@gmail.com> | 2026-03-03 11:46:03 +0300 |
|---|---|---|
| committer | Grail Finder <wohilas@gmail.com> | 2026-03-03 11:46:03 +0300 |
| commit | 0e5d37666f92bc75f12f118fc77a7e4af4a5924b (patch) | |
| tree | 967b9de608288a3cfbd40aaf284b6bd7b640a4b9 /models | |
| parent | 093103bdd7cd02e10f2339e7beeb71375fb16256 (diff) | |
Enha: id for card map
Diffstat (limited to 'models')
| -rw-r--r-- | models/card.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/models/card.go b/models/card.go index 9bf6665..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,6 +35,7 @@ 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{ + ID: ComputeCardID(c.Name, fpath), SysPrompt: sysPr, FirstMsg: fm, Role: c.Name, @@ -39,7 +44,12 @@ func (c *CharCardSpec) Simplify(userName, fpath string) *CharCard { } } +func ComputeCardID(role, filePath string) string { + return fmt.Sprintf("%x", md5.Sum([]byte(role+filePath))) +} + type CharCard struct { + ID string `json:"id"` SysPrompt string `json:"sys_prompt"` FirstMsg string `json:"first_msg"` Role string `json:"role"` |
