summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md24
-rw-r--r--bot.go6
-rw-r--r--config.example.toml1
-rw-r--r--config/config.go4
-rw-r--r--tui.go18
5 files changed, 36 insertions, 17 deletions
diff --git a/README.md b/README.md
index 2f0dc2e..f03c6bd 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
### TODO:
-- scrolling chat history; (somewhat works out of box); +
+- scrolling chat history; (somewhat works out of the box); +
- log errors to file; +
- give serial id to each msg in chat to track it; (use slice index) +
- show msg id next to the msg; +
@@ -23,26 +23,26 @@
- fullscreen textarea option (bothersome to implement);
- consider adding use /completion of llamacpp, since openai endpoint clearly has template|format issues;
- 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);
- colourschemes, colours or markdown of quotes and styles;
- 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);
### FIX:
-- bot responding (or haninging) blocks everything; +
-- programm requires history folder, but it is .gitignore; +
+- bot responding (or hanging) blocks everything; +
+- program requires history folder, but it is .gitignore; +
- 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) +
- sometimes bots put additional info around the tool call, have a regexp to match tool call; +
- remove all panics from code; +
- new chat replaces old ones in db; +
- 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);
-- 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);
-- 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;
-- no selection focus on modal sys buttons after opening it a second time;
-- 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?
+- if option to show sys msg enabled: it show display new tool responses; +
+- 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)); +
+- 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) +
+- chat should contain char in it (one to many: char: []chats); +
diff --git a/bot.go b/bot.go
index 23769dd..210a8b4 100644
--- a/bot.go
+++ b/bot.go
@@ -54,6 +54,7 @@ func sendMsgToLLM(body io.Reader) {
resp, err := httpClient.Post(cfg.APIURL, "application/json", body)
if err != nil {
logger.Error("llamacpp api", "error", err)
+ streamDone <- true
return
}
defer resp.Body.Close()
@@ -92,6 +93,9 @@ func sendMsgToLLM(body io.Reader) {
// logger.Info("streamview", "chunk", llmchunk)
// 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].Delta.Content != "" {
+ logger.Warn("text inside of finish llmchunk", "chunk", llmchunk, "counter", counter)
+ }
streamDone <- true
// last chunk
break
@@ -125,6 +129,7 @@ out:
respText.WriteString(chunk)
tv.ScrollToEnd()
case <-streamDone:
+ botRespMode = false
break out
}
}
@@ -133,6 +138,7 @@ out:
Role: cfg.AssistantRole, Content: respText.String(),
})
colorText()
+ updateStatusLine()
// bot msg is done;
// now check it for func call
// logChat(activeChatName, chatBody.Messages)
diff --git a/config.example.toml b/config.example.toml
index 888de1a..c52f267 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -8,3 +8,4 @@ AssistantIcon = "<🤖>: "
UserIcon = "<user>: "
ToolIcon = "<ï‚­>>: "
SysDir = "sysprompts"
+ChunkLimit = 100000
diff --git a/config/config.go b/config/config.go
index 0c62e76..0561d51 100644
--- a/config/config.go
+++ b/config/config.go
@@ -16,8 +16,8 @@ type Config struct {
AssistantIcon string `toml:"AssistantIcon"`
UserIcon string `toml:"UserIcon"`
ToolIcon string `toml:"ToolIcon"`
- ChunkLimit uint32 `toml:"ChunkLimit"`
SysDir string `toml:"SysDir"`
+ ChunkLimit uint32 `toml:"ChunkLimit"`
}
func LoadConfigOrDefault(fn string) *Config {
@@ -34,8 +34,8 @@ func LoadConfigOrDefault(fn string) *Config {
config.UserRole = "user"
config.ToolRole = "tool"
config.AssistantRole = "assistant"
- config.ChunkLimit = 8192
config.SysDir = "sysprompts"
+ config.ChunkLimit = 8192
}
return config
}
diff --git a/tui.go b/tui.go
index 28d1c44..afb8cc6 100644
--- a/tui.go
+++ b/tui.go
@@ -5,6 +5,7 @@ import (
"elefant/pngmeta"
"fmt"
"strconv"
+ "strings"
"time"
"github.com/gdamore/tcell/v2"
@@ -48,6 +49,10 @@ func colorText() {
textView.SetText(starRE.ReplaceAllString(cq, `[turquoise::i]$1[-:-:-]`))
}
+func updateStatusLine() {
+ position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
+}
+
func init() {
theme := tview.Theme{
PrimitiveBackgroundColor: tcell.ColorDefault,
@@ -84,9 +89,6 @@ func init() {
AddItem(textView, 0, 40, false).
AddItem(textArea, 0, 10, true).
AddItem(position, 0, 1, false)
- updateStatusLine := func() {
- position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
- }
chatOpts := []string{"cancel", "new", "rename current"}
chatList, err := loadHistoryChats()
if err != nil {
@@ -149,6 +151,7 @@ func init() {
switch buttonLabel {
case "cancel":
pages.RemovePage("sys")
+ sysModal.ClearButtons()
return
default:
cc, ok := sysMap[buttonLabel]
@@ -295,6 +298,13 @@ func init() {
}
if event.Key() == tcell.KeyF3 && !botRespMode {
// 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]
textView.SetText(chatToText(cfg.ShowSys))
return nil
@@ -374,6 +384,8 @@ func init() {
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
// read all text into buffer
msgText := textArea.GetText()
+ // TODO: check whose message was latest (user icon / assistant)
+ // in order to decide if assistant new icon is needed
if msgText != "" {
fmt.Fprintf(textView, "\n(%d) <user>: \n%s\n", len(chatBody.Messages), msgText)
textArea.SetText("", true)