summaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/card.go41
-rw-r--r--models/db.go6
-rw-r--r--models/models.go22
3 files changed, 53 insertions, 16 deletions
diff --git a/models/card.go b/models/card.go
new file mode 100644
index 0000000..24226d3
--- /dev/null
+++ b/models/card.go
@@ -0,0 +1,41 @@
+package models
+
+import "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
+type CharCardSpec struct {
+ Name string `json:"name"`
+ Description string `json:"description"`
+ Personality string `json:"personality"`
+ FirstMes string `json:"first_mes"`
+ Avatar string `json:"avatar"`
+ Chat string `json:"chat"`
+ MesExample string `json:"mes_example"`
+ Scenario string `json:"scenario"`
+ CreateDate string `json:"create_date"`
+ Talkativeness string `json:"talkativeness"`
+ Fav bool `json:"fav"`
+ Creatorcomment string `json:"creatorcomment"`
+ Spec string `json:"spec"`
+ SpecVersion string `json:"spec_version"`
+ Tags []any `json:"tags"`
+}
+
+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,
+ }
+}
+
+type CharCard struct {
+ SysPrompt string
+ FirstMsg string
+ Role string
+ FilePath string
+}
diff --git a/models/db.go b/models/db.go
index 5f49003..4f52f68 100644
--- a/models/db.go
+++ b/models/db.go
@@ -8,13 +8,13 @@ import (
type Chat struct {
ID uint32 `db:"id" json:"id"`
Name string `db:"name" json:"name"`
- Msgs string `db:"msgs" json:"msgs"` // []MessagesStory to string json
+ Msgs string `db:"msgs" json:"msgs"` // []RoleMsg to string json
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}
-func (c Chat) ToHistory() ([]MessagesStory, error) {
- resp := []MessagesStory{}
+func (c Chat) ToHistory() ([]RoleMsg, error) {
+ resp := []RoleMsg{}
if err := json.Unmarshal([]byte(c.Msgs), &resp); err != nil {
return nil, err
}
diff --git a/models/models.go b/models/models.go
index 02bec00..0373e9b 100644
--- a/models/models.go
+++ b/models/models.go
@@ -5,12 +5,6 @@ import (
"strings"
)
-// type FuncCall struct {
-// XMLName xml.Name `xml:"tool_call"`
-// Name string `xml:"name"`
-// Args []string `xml:"args"`
-// }
-
type FuncCall struct {
Name string `json:"name"`
Args []string `json:"args"`
@@ -56,12 +50,12 @@ type LLMRespChunk struct {
} `json:"usage"`
}
-type MessagesStory struct {
+type RoleMsg struct {
Role string `json:"role"`
Content string `json:"content"`
}
-func (m MessagesStory) ToText(i int) string {
+func (m RoleMsg) ToText(i int) string {
icon := ""
switch m.Role {
case "assistant":
@@ -72,20 +66,22 @@ func (m MessagesStory) ToText(i int) string {
icon = fmt.Sprintf("(%d) <system>: ", i)
case "tool":
icon = fmt.Sprintf("(%d) <tool>: ", i)
+ default:
+ icon = fmt.Sprintf("(%d) <%s>: ", i, m.Role)
}
textMsg := fmt.Sprintf("%s%s\n", icon, m.Content)
return strings.ReplaceAll(textMsg, "\n\n", "\n")
}
type ChatBody struct {
- Model string `json:"model"`
- Stream bool `json:"stream"`
- Messages []MessagesStory `json:"messages"`
+ Model string `json:"model"`
+ Stream bool `json:"stream"`
+ Messages []RoleMsg `json:"messages"`
}
type ChatToolsBody struct {
- Model string `json:"model"`
- Messages []MessagesStory `json:"messages"`
+ Model string `json:"model"`
+ Messages []RoleMsg `json:"messages"`
Tools []struct {
Type string `json:"type"`
Function struct {