Feat: add switch between sys prompts

This commit is contained in:
Grail Finder
2024-11-23 18:34:02 +03:00
parent 692e0ada4b
commit 6625a8103b
4 changed files with 36 additions and 26 deletions

View File

@@ -13,12 +13,13 @@
- stop stream from the bot; + - stop stream from the bot; +
- sqlitedb instead of chatfiles; + - sqlitedb instead of chatfiles; +
- define tools and sys prompt for them to be used; + - define tools and sys prompt for them to be used; +
- add system prompt without tools (for mistral); +
- option to switch between predefined sys prompts; +
- sqlite for the bot memory; - sqlite for the bot memory;
- fullscreen textarea option (bothersome to implement); - fullscreen textarea option (bothersome to implement);
- add system prompt without tools (for mistral);
- option to switch between predefined sys prompts;
- 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;
- change temp, min-p and other params from tui; - change temp, min-p and other params from tui;
- help page with all key bindings;
### FIX: ### FIX:
- bot responding (or haninging) blocks everything; + - bot responding (or haninging) blocks everything; +

2
bot.go
View File

@@ -23,13 +23,13 @@ var httpClient = http.Client{
var ( var (
logger *slog.Logger logger *slog.Logger
APIURL = "http://localhost:8080/v1/chat/completions"
userRole = "user" userRole = "user"
assistantRole = "assistant" assistantRole = "assistant"
toolRole = "tool" toolRole = "tool"
assistantIcon = "<🤖>: " assistantIcon = "<🤖>: "
userIcon = "<user>: " userIcon = "<user>: "
// TODO: pass as an cli arg or have config // TODO: pass as an cli arg or have config
APIURL = "http://localhost:8080/v1/chat/completions"
logFileName = "log.txt" logFileName = "log.txt"
showSystemMsgs bool showSystemMsgs bool
chunkLimit = 1000 chunkLimit = 1000

26
main.go
View File

@@ -102,6 +102,27 @@ func main() {
return return
} }
}) })
sysModal := tview.NewModal().
SetText("Switch sys msg:").
AddButtons(sysLabels).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
switch buttonLabel {
case "cancel":
pages.RemovePage("sys")
return
default:
sysMsg, ok := sysMap[buttonLabel]
if !ok {
logger.Warn("no such sys msg", "name", buttonLabel)
pages.RemovePage("sys")
return
}
chatBody.Messages[0].Content = sysMsg
// replace textview
textView.SetText(chatToText(showSystemMsgs))
pages.RemovePage("sys")
}
})
editArea := tview.NewTextArea(). editArea := tview.NewTextArea().
SetPlaceholder("Replace msg...") SetPlaceholder("Replace msg...")
editArea.SetBorder(true).SetTitle("input") editArea.SetBorder(true).SetTitle("input")
@@ -218,6 +239,11 @@ func main() {
textArea.SetText("pressed ctrl+e", true) textArea.SetText("pressed ctrl+e", true)
return nil return nil
} }
if event.Key() == tcell.KeyCtrlS {
// switch sys prompt
pages.AddPage("sys", sysModal, true, true)
return nil
}
// cannot send msg in editMode or botRespMode // cannot send msg in editMode or botRespMode
if event.Key() == tcell.KeyEscape && !editMode && !botRespMode { if event.Key() == tcell.KeyEscape && !editMode && !botRespMode {
fromRow, fromColumn, _, _ := textArea.GetCursor() fromRow, fromColumn, _, _ := textArea.GetCursor()

View File

@@ -9,29 +9,9 @@ import (
var ( var (
// TODO: form that message based on existing funcs // TODO: form that message based on existing funcs
// systemMsg = `You're a helpful assistant. basicSysMsg = `Large Language Model that helps user with any of his requests.`
// # Tools toolCallRE = regexp.MustCompile(`__tool_call__\s*([\s\S]*?)__tool_call__`)
// You can do functions call if needed. toolSysMsg = `You're a helpful assistant.
// Your current tools:
// <tools>
// {
// "name":"get_id",
// "args": "username"
// }
// </tools>
// To make a function call return a json object within __tool_call__ tags;
// Example:
// __tool_call__
// {
// "name":"get_id",
// "args": "Adam"
// }
// __tool_call__
// When making function call avoid typing anything else. 'tool' user will respond with the results of the call.
// After that you are free to respond to the user.
// `
toolCallRE = regexp.MustCompile(`__tool_call__\s*([\s\S]*?)__tool_call__`)
systemMsg = `You're a helpful assistant.
# Tools # Tools
You can do functions call if needed. You can do functions call if needed.
Your current tools: Your current tools:
@@ -65,6 +45,9 @@ __tool_call__
When done right, tool call will be delivered to the 'tool' agent. 'tool' agent will respond with the results of the call. When done right, tool call will be delivered to the 'tool' agent. 'tool' agent will respond with the results of the call.
After that you are free to respond to the user. After that you are free to respond to the user.
` `
systemMsg = toolSysMsg
sysMap = map[string]string{"basic_sys": basicSysMsg, "tool_sys": toolSysMsg}
sysLabels = []string{"cancel", "basic_sys", "tool_sys"}
) )
/* /*