Fix: resolve points on the fixlist

This commit is contained in:
Grail Finder
2024-12-07 12:53:35 +03:00
parent e811bc51d4
commit 7c4d057994
5 changed files with 36 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
### TODO: ### TODO:
- scrolling chat history; (somewhat works out of box); + - scrolling chat history; (somewhat works out of the box); +
- log errors to file; + - log errors to file; +
- give serial id to each msg in chat to track it; (use slice index) + - give serial id to each msg in chat to track it; (use slice index) +
- show msg id next to the msg; + - show msg id next to the msg; +
@@ -23,26 +23,26 @@
- fullscreen textarea option (bothersome to implement); - fullscreen textarea option (bothersome to implement);
- consider adding use /completion of llamacpp, since openai endpoint clearly has template|format issues; - consider adding use /completion of llamacpp, since openai endpoint clearly has template|format issues;
- export whole chat into a json file; - export whole chat into a json file;
- directoty with sys prompts (charcards png & json); - directory with sys prompts (charcards png & json);
- 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); - 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);
- colourschemes, colours or markdown of quotes and styles; - colourschemes, colours or markdown of quotes and styles;
- RAG support|implementation; - RAG support|implementation;
- change card-chat pair with one binding; - 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);
### FIX: ### FIX:
- bot responding (or haninging) blocks everything; + - bot responding (or hanging) blocks everything; +
- programm requires history folder, but it is .gitignore; + - program requires history folder, but it is .gitignore; +
- at first run chat table does not exist; run migrations sql on startup; + - at first run chat table does not exist; run migrations sql on startup; +
- Tab is needed to copy paste text into textarea box, use shift+tab to switch focus; (changed tp pgup) + - Tab is needed to copy paste text into textarea box, use shift+tab to switch focus; (changed tp pgup) +
- sometimes bots put additional info around the tool call, have a regexp to match tool call; + - sometimes bots put additional info around the tool call, have a regexp to match tool call; +
- remove all panics from code; + - remove all panics from code; +
- new chat replaces old ones in db; + - new chat replaces old ones in db; +
- empty input to continue bot msg gens new msg index and bot icon; + - empty input to continue bot msg gens new msg index and bot icon; +
- delete last msg: can have unexpected behavior (deletes what appears to be two messages if last bot msg was not generated (should only delete icon in that case)) (should use regen instead of delete in that case); - if option to show sys msg enabled: it show display new tool responses; +
- lets say we have two (or more) agents with the same name across multiple chats. These agents go and ask db for topics they memoriesed. Now they can access topics that aren't meant for them. (so memory should have an option: shareble; that indicates if that memory can be shared across chats); - delete last msg: can have unexpected behavior (deletes what appears to be two messages if last bot msg was not generated (should only delete icon in that case)); +
- if option to show sys msg enabled: it show display new tool responses; - when bot generation ended with err: need a way to switch back to the bot_resp_false mode; +
- when bot generation ended with err: need a way to switch back to the bot_resp_false mode; - no selection focus on modal sys buttons after opening it a second time; (cannot reproduce) +
- no selection focus on modal sys buttons after opening it a second time; - chat should contain char in it (one to many: char: []chats); +
- chat should contain char in it (one to many: char: []chats);
- 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?

6
bot.go
View File

@@ -54,6 +54,7 @@ func sendMsgToLLM(body io.Reader) {
resp, err := httpClient.Post(cfg.APIURL, "application/json", body) resp, err := httpClient.Post(cfg.APIURL, "application/json", body)
if err != nil { if err != nil {
logger.Error("llamacpp api", "error", err) logger.Error("llamacpp api", "error", err)
streamDone <- true
return return
} }
defer resp.Body.Close() defer resp.Body.Close()
@@ -92,6 +93,9 @@ func sendMsgToLLM(body io.Reader) {
// logger.Info("streamview", "chunk", llmchunk) // logger.Info("streamview", "chunk", llmchunk)
// if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason != "chat.completion.chunk" { // if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason != "chat.completion.chunk" {
if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason == "stop" { if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason == "stop" {
if llmchunk.Choices[len(llmchunk.Choices)-1].Delta.Content != "" {
logger.Warn("text inside of finish llmchunk", "chunk", llmchunk, "counter", counter)
}
streamDone <- true streamDone <- true
// last chunk // last chunk
break break
@@ -125,6 +129,7 @@ out:
respText.WriteString(chunk) respText.WriteString(chunk)
tv.ScrollToEnd() tv.ScrollToEnd()
case <-streamDone: case <-streamDone:
botRespMode = false
break out break out
} }
} }
@@ -133,6 +138,7 @@ out:
Role: cfg.AssistantRole, Content: respText.String(), Role: cfg.AssistantRole, Content: respText.String(),
}) })
colorText() colorText()
updateStatusLine()
// bot msg is done; // bot msg is done;
// now check it for func call // now check it for func call
// logChat(activeChatName, chatBody.Messages) // logChat(activeChatName, chatBody.Messages)

View File

@@ -8,3 +8,4 @@ AssistantIcon = "<🤖>: "
UserIcon = "<user>: " UserIcon = "<user>: "
ToolIcon = "<>>: " ToolIcon = "<>>: "
SysDir = "sysprompts" SysDir = "sysprompts"
ChunkLimit = 100000

View File

@@ -16,8 +16,8 @@ type Config struct {
AssistantIcon string `toml:"AssistantIcon"` AssistantIcon string `toml:"AssistantIcon"`
UserIcon string `toml:"UserIcon"` UserIcon string `toml:"UserIcon"`
ToolIcon string `toml:"ToolIcon"` ToolIcon string `toml:"ToolIcon"`
ChunkLimit uint32 `toml:"ChunkLimit"`
SysDir string `toml:"SysDir"` SysDir string `toml:"SysDir"`
ChunkLimit uint32 `toml:"ChunkLimit"`
} }
func LoadConfigOrDefault(fn string) *Config { func LoadConfigOrDefault(fn string) *Config {
@@ -34,8 +34,8 @@ func LoadConfigOrDefault(fn string) *Config {
config.UserRole = "user" config.UserRole = "user"
config.ToolRole = "tool" config.ToolRole = "tool"
config.AssistantRole = "assistant" config.AssistantRole = "assistant"
config.ChunkLimit = 8192
config.SysDir = "sysprompts" config.SysDir = "sysprompts"
config.ChunkLimit = 8192
} }
return config return config
} }

18
tui.go
View File

@@ -5,6 +5,7 @@ import (
"elefant/pngmeta" "elefant/pngmeta"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
@@ -48,6 +49,10 @@ func colorText() {
textView.SetText(starRE.ReplaceAllString(cq, `[turquoise::i]$1[-:-:-]`)) textView.SetText(starRE.ReplaceAllString(cq, `[turquoise::i]$1[-:-:-]`))
} }
func updateStatusLine() {
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
}
func init() { func init() {
theme := tview.Theme{ theme := tview.Theme{
PrimitiveBackgroundColor: tcell.ColorDefault, PrimitiveBackgroundColor: tcell.ColorDefault,
@@ -84,9 +89,6 @@ func init() {
AddItem(textView, 0, 40, false). AddItem(textView, 0, 40, false).
AddItem(textArea, 0, 10, true). AddItem(textArea, 0, 10, true).
AddItem(position, 0, 1, false) AddItem(position, 0, 1, false)
updateStatusLine := func() {
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
}
chatOpts := []string{"cancel", "new", "rename current"} chatOpts := []string{"cancel", "new", "rename current"}
chatList, err := loadHistoryChats() chatList, err := loadHistoryChats()
if err != nil { if err != nil {
@@ -149,6 +151,7 @@ func init() {
switch buttonLabel { switch buttonLabel {
case "cancel": case "cancel":
pages.RemovePage("sys") pages.RemovePage("sys")
sysModal.ClearButtons()
return return
default: default:
cc, ok := sysMap[buttonLabel] cc, ok := sysMap[buttonLabel]
@@ -295,6 +298,13 @@ func init() {
} }
if event.Key() == tcell.KeyF3 && !botRespMode { if event.Key() == tcell.KeyF3 && !botRespMode {
// delete last msg // delete last msg
// check textarea text; if it ends with bot icon delete only icon:
text := textView.GetText(true)
if strings.HasSuffix(text, cfg.AssistantIcon) {
logger.Info("deleting assistant icon", "icon", cfg.AssistantIcon)
textView.SetText(strings.TrimSuffix(text, cfg.AssistantIcon))
return nil
}
chatBody.Messages = chatBody.Messages[:len(chatBody.Messages)-1] chatBody.Messages = chatBody.Messages[:len(chatBody.Messages)-1]
textView.SetText(chatToText(cfg.ShowSys)) textView.SetText(chatToText(cfg.ShowSys))
return nil return nil
@@ -374,6 +384,8 @@ func init() {
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName)) position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
// read all text into buffer // read all text into buffer
msgText := textArea.GetText() msgText := textArea.GetText()
// TODO: check whose message was latest (user icon / assistant)
// in order to decide if assistant new icon is needed
if msgText != "" { if msgText != "" {
fmt.Fprintf(textView, "\n(%d) <user>: \n%s\n", len(chatBody.Messages), msgText) fmt.Fprintf(textView, "\n(%d) <user>: \n%s\n", len(chatBody.Messages), msgText)
textArea.SetText("", true) textArea.SetText("", true)