Fix: load json syscards, replace char and user

This commit is contained in:
Grail Finder
2025-02-03 20:18:17 +03:00
parent eb53b13381
commit 6676b7d12b
4 changed files with 20 additions and 29 deletions

View File

@@ -37,11 +37,11 @@
======= =======
- separate messages that are stored and chat and send to the bot, i.e. option to omit tool calls and thinking (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 and thinking (there might be a point where they are no longer needed in ctx); +
- option to remove <thinking> from chat history; + - option to remove <thinking> from chat history; +
- connection to a model status; (need to be tied to some event, perhaps its own shortcut even) +
- char card is the sys message, but how about giving tools to char that does not have it? - char card is the sys message, but how about giving tools to char that does not have it?
- 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); - 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);
- server mode: no tui but api calls with the func calling, rag, other middleware; - server mode: no tui but api calls with the func calling, rag, other middleware;
- boolean flag to use/not use tools. I see it as a msg from a tool to an llm "Hey, it might be good idea to use me!"; - boolean flag to use/not use tools. I see it as a msg from a tool to an llm "Hey, it might be good idea to use me!";
- connection to a model status; (need to be tied to some event, perhaps its own shortcut even)
### FIX: ### FIX:
- bot responding (or hanging) blocks everything; + - bot responding (or hanging) blocks everything; +

12
main.go
View File

@@ -1,6 +1,9 @@
package main package main
import ( import (
"flag"
"fmt"
"net/http"
"unicode" "unicode"
"github.com/rivo/tview" "github.com/rivo/tview"
@@ -24,6 +27,15 @@ func isASCII(s string) bool {
} }
func main() { func main() {
apiPort := flag.Int("port", 0, "port to host api")
flag.Parse()
if apiPort != nil && *apiPort > 3000 {
// start api server
http.HandleFunc("POST /completion", completion)
http.ListenAndServe(fmt.Sprintf(":%d", *apiPort), nil)
// no tui
return
}
pages.AddPage("main", flex, true, true) pages.AddPage("main", flex, true, true)
if err := app.SetRoot(pages, if err := app.SetRoot(pages,
true).EnableMouse(true).EnablePaste(true).Run(); err != nil { true).EnableMouse(true).EnablePaste(true).Run(); err != nil {

View File

@@ -140,6 +140,8 @@ func ReadDirCards(dirname, uname string, log *slog.Logger) ([]*models.CharCard,
if err != nil { if err != nil {
return nil, err // better to log and continue return nil, err // better to log and 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)
resp = append(resp, cc) resp = append(resp, cc)
} }
} }

31
tui.go
View File

@@ -68,30 +68,6 @@ Press Enter to go back
` `
) )
// code block colors get interrupted by " & *
// func codeBlockColor(text string) string {
// fi := strings.Index(text, "```")
// if fi < 0 {
// return text
// }
// li := strings.LastIndex(text, "```")
// if li == fi { // only openning backticks
// return text
// }
// return strings.Replace(text, "```", "```[blue:black:i]", 1)
// }
// func colorText() {
// // INFO: is there a better way to markdown?
// text := textView.GetText(false)
// text = quotesRE.ReplaceAllString(text, `[orange::-]$1[-:-:-]`)
// text = starRE.ReplaceAllString(text, `[turquoise::i]$1[-:-:-]`)
// text = thinkRE.ReplaceAllString(text, `[turquoise::i]$1[-:-:-]`)
// text = codeBlockRE.ReplaceAllString(text, "[blue::i]```\n$1\n```\n[-:-:-]")
// // text = codeBlockRE.ReplaceAllString(text, "[blue:black:i]```\n$1\n```\n[-:-:-]")
// textView.SetText(text)
// }
func colorText() { func colorText() {
text := textView.GetText(false) text := textView.GetText(false)
// Step 1: Extract code blocks and replace them with unique placeholders // Step 1: Extract code blocks and replace them with unique placeholders
@@ -101,7 +77,7 @@ func colorText() {
// Replace code blocks with placeholders and store their styled versions // Replace code blocks with placeholders and store their styled versions
text = codeBlockRE.ReplaceAllStringFunc(text, func(match string) string { text = codeBlockRE.ReplaceAllStringFunc(text, func(match string) string {
// Style the code block and store it // Style the code block and store it
styled := fmt.Sprintf("[brown:yellow:i]%s[-:-:-]", match) styled := fmt.Sprintf("[red::i]%s[-:-:-]", match)
codeBlocks = append(codeBlocks, styled) codeBlocks = append(codeBlocks, styled)
// Generate a unique placeholder (e.g., "__CODE_BLOCK_0__") // Generate a unique placeholder (e.g., "__CODE_BLOCK_0__")
id := fmt.Sprintf(placeholder, counter) id := fmt.Sprintf(placeholder, counter)
@@ -523,9 +499,10 @@ func init() {
return nil return nil
} }
if event.Key() == tcell.KeyCtrlL { if event.Key() == tcell.KeyCtrlL {
fetchModelName() go func() {
textArea.SetText("pressed ctrl+l", true) fetchModelName() // blocks
updateStatusLine() updateStatusLine()
}()
return nil return nil
} }
if event.Key() == tcell.KeyCtrlT { if event.Key() == tcell.KeyCtrlT {