Enha: export chat to export dir
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ history_bak/
|
||||
.aider*
|
||||
tags
|
||||
gf-lt
|
||||
chat_exports/*.json
|
||||
|
||||
@@ -126,9 +126,8 @@ func ReadDirCards(dirname, uname string, log *slog.Logger) ([]*models.CharCard,
|
||||
fpath := path.Join(dirname, f.Name())
|
||||
cc, err := ReadCard(fpath, uname)
|
||||
if err != nil {
|
||||
log.Warn("failed to load card", "error", err)
|
||||
log.Warn("failed to load card", "error", err, "card", fpath)
|
||||
continue
|
||||
// return nil, err // better to log and continue
|
||||
}
|
||||
resp = append(resp, cc)
|
||||
}
|
||||
@@ -136,7 +135,8 @@ func ReadDirCards(dirname, uname string, log *slog.Logger) ([]*models.CharCard,
|
||||
fpath := path.Join(dirname, f.Name())
|
||||
cc, err := ReadCardJson(fpath)
|
||||
if err != nil {
|
||||
return nil, err // better to log and continue
|
||||
log.Warn("failed to load card", "error", err, "card", fpath)
|
||||
continue
|
||||
}
|
||||
cc.FirstMsg = strings.ReplaceAll(strings.ReplaceAll(cc.FirstMsg, "{{char}}", cc.Role), "{{user}}", uname)
|
||||
cc.SysPrompt = strings.ReplaceAll(strings.ReplaceAll(cc.SysPrompt, "{{char}}", cc.Role), "{{user}}", uname)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gf-lt/models"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gf-lt/models"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -32,7 +33,8 @@ func exportChat() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(activeChatName+".json", data, 0666)
|
||||
fp := path.Join(exportDir, activeChatName+".json")
|
||||
return os.WriteFile(fp, data, 0666)
|
||||
}
|
||||
|
||||
func importChat(filename string) error {
|
||||
|
||||
7
tui.go
7
tui.go
@@ -42,6 +42,7 @@ var (
|
||||
propsPage = "propsPage"
|
||||
codeBlockPage = "codeBlockPage"
|
||||
imgPage = "imgPage"
|
||||
exportDir = "chat_exports"
|
||||
// help text
|
||||
helpText = `
|
||||
[yellow]Esc[white]: send msg
|
||||
@@ -618,19 +619,19 @@ func init() {
|
||||
}
|
||||
if event.Key() == tcell.KeyF11 {
|
||||
// read files in chat_exports
|
||||
dirname := "chat_exports"
|
||||
filelist, err := os.ReadDir(dirname)
|
||||
filelist, err := os.ReadDir(exportDir)
|
||||
if err != nil {
|
||||
if err := notifyUser("failed to load exports", err.Error()); err != nil {
|
||||
logger.Error("failed to send notification", "error", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
fli := []string{}
|
||||
for _, f := range filelist {
|
||||
if f.IsDir() || !strings.HasSuffix(f.Name(), ".json") {
|
||||
continue
|
||||
}
|
||||
fpath := path.Join(dirname, f.Name())
|
||||
fpath := path.Join(exportDir, f.Name())
|
||||
fli = append(fli, fpath)
|
||||
}
|
||||
// check error
|
||||
|
||||
Reference in New Issue
Block a user