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