diff options
author | Grail Finder <wohilas@gmail.com> | 2024-12-23 19:02:36 +0300 |
---|---|---|
committer | Grail Finder <wohilas@gmail.com> | 2024-12-23 19:02:36 +0300 |
commit | 4db8aea43dded3f2c1d0d41b5a3fb322a38d4730 (patch) | |
tree | c8929dda92bb942d1e1bc8193102508d14dda132 | |
parent | 923c96b73d02a5725a6b94d6052b2399b6f2def8 (diff) |
Feat: read json sysprompt cards
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | models/card.go | 8 | ||||
-rw-r--r-- | pngmeta/metareader.go | 35 | ||||
-rw-r--r-- | tools.go | 3 | ||||
-rw-r--r-- | tui.go | 12 |
6 files changed, 44 insertions, 18 deletions
@@ -5,4 +5,4 @@ elefant history/ *.db config.toml -sysprompts/*.png +sysprompts/* @@ -28,7 +28,6 @@ - consider adding use /completion of llamacpp, since openai endpoint clearly has template|format issues; - separate messages that are stored and chat and send to the bot, i.e. option to omit tool calls (there might be a point where they are no longer needed in ctx); - RAG support|implementation; -- change card-chat pair with one binding; - char card is the sys message, but how about giving tools to char that does not have it? - it is a bit clumsy to mix chats in db and chars from the external files, maybe load external files in db on startup? - lets say we have two (or more) agents with the same name across multiple chats. These agents go and ask db for topics they memorised. Now they can access topics that aren't meant for them. (so memory should have an option: shareable; that indicates if that memory can be shared across chats); @@ -51,4 +50,5 @@ - all page names should be vars; + - normal case regen omits assistant icon; + - user icon (and role?) from config is not used; + +- message editing broke ( runtime error: index out of range [-1]); + - F1 can load any chat, by loading chat of other agent it does not switch agents, if that chat is continued, it will rewrite agent in db; (either allow only chats from current agent OR switch agent on chat loading); diff --git a/models/card.go b/models/card.go index 24226d3..4ff2d8b 100644 --- a/models/card.go +++ b/models/card.go @@ -34,8 +34,8 @@ func (c *CharCardSpec) Simplify(userName, fpath string) *CharCard { } type CharCard struct { - SysPrompt string - FirstMsg string - Role string - FilePath string + SysPrompt string `json:"sys_prompt"` + FirstMsg string `json:"first_msg"` + Role string `json:"role"` + FilePath string `json:"filepath"` } diff --git a/pngmeta/metareader.go b/pngmeta/metareader.go index ea726c9..5542e86 100644 --- a/pngmeta/metareader.go +++ b/pngmeta/metareader.go @@ -84,6 +84,18 @@ func ReadCard(fname, uname string) (*models.CharCard, error) { return charSpec.Simplify(uname, fname), nil } +func readCardJson(fname string) (*models.CharCard, error) { + data, err := os.ReadFile(fname) + if err != nil { + return nil, err + } + card := models.CharCard{} + if err := json.Unmarshal(data, &card); err != nil { + return nil, err + } + return &card, nil +} + func ReadDirCards(dirname, uname string) ([]*models.CharCard, error) { files, err := os.ReadDir(dirname) if err != nil { @@ -91,17 +103,22 @@ func ReadDirCards(dirname, uname string) ([]*models.CharCard, error) { } resp := []*models.CharCard{} for _, f := range files { - if !strings.HasSuffix(f.Name(), ".png") { - continue + if strings.HasSuffix(f.Name(), ".png") { + fpath := path.Join(dirname, f.Name()) + cc, err := ReadCard(fpath, uname) + if err != nil { + return nil, err // better to log and continue + } + resp = append(resp, cc) } - fpath := path.Join(dirname, f.Name()) - cc, err := ReadCard(fpath, uname) - if err != nil { - // log err - return nil, err - // continue + if strings.HasSuffix(f.Name(), ".json") { + fpath := path.Join(dirname, f.Name()) + cc, err := readCardJson(fpath) + if err != nil { + return nil, err // better to log and continue + } + resp = append(resp, cc) } - resp = append(resp, cc) } return resp, nil } @@ -107,7 +107,8 @@ func recall(args ...string) []byte { logger.Error(msg) return []byte(msg) } - return []byte(mind) + answer := fmt.Sprintf("under the topic: %s is stored:\n%s", args[0], mind) + return []byte(answer) } func recallTopics(args ...string) []byte { @@ -117,7 +117,9 @@ func makeChatTable(chatList []string) *tview.Table { if err := store.RemoveChat(sc.ID); err != nil { logger.Error("failed to remove chat from db", "chat_id", sc.ID, "chat_name", sc.Name) } - notifyUser("chat deleted", selectedChat+" was deleted") + if err := notifyUser("chat deleted", selectedChat+" was deleted"); err != nil { + logger.Error("failed to send notification", "error", err) + } pages.RemovePage(historyPage) return default: @@ -288,10 +290,16 @@ func init() { return event case tcell.KeyEnter: si := indexPickWindow.GetText() - selectedIndex, err := strconv.Atoi(si) + siInt, err := strconv.Atoi(si) if err != nil { logger.Error("failed to convert provided index", "error", err, "si", si) + if err := notifyUser("cancel", "no index provided"); err != nil { + logger.Error("failed to send notification", "error", err) + } + pages.RemovePage(indexPage) + return event } + selectedIndex = siInt if len(chatBody.Messages)+1 < selectedIndex || selectedIndex < 0 { msg := "chosen index is out of bounds" logger.Warn(msg, "index", selectedIndex) |