Feat: add switch between sys prompts
This commit is contained in:
@@ -13,12 +13,13 @@
|
||||
- stop stream from the bot; +
|
||||
- sqlitedb instead of chatfiles; +
|
||||
- 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;
|
||||
- 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;
|
||||
- change temp, min-p and other params from tui;
|
||||
- help page with all key bindings;
|
||||
|
||||
### FIX:
|
||||
- bot responding (or haninging) blocks everything; +
|
||||
|
||||
2
bot.go
2
bot.go
@@ -23,13 +23,13 @@ var httpClient = http.Client{
|
||||
|
||||
var (
|
||||
logger *slog.Logger
|
||||
APIURL = "http://localhost:8080/v1/chat/completions"
|
||||
userRole = "user"
|
||||
assistantRole = "assistant"
|
||||
toolRole = "tool"
|
||||
assistantIcon = "<🤖>: "
|
||||
userIcon = "<user>: "
|
||||
// TODO: pass as an cli arg or have config
|
||||
APIURL = "http://localhost:8080/v1/chat/completions"
|
||||
logFileName = "log.txt"
|
||||
showSystemMsgs bool
|
||||
chunkLimit = 1000
|
||||
|
||||
26
main.go
26
main.go
@@ -102,6 +102,27 @@ func main() {
|
||||
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().
|
||||
SetPlaceholder("Replace msg...")
|
||||
editArea.SetBorder(true).SetTitle("input")
|
||||
@@ -218,6 +239,11 @@ func main() {
|
||||
textArea.SetText("pressed ctrl+e", true)
|
||||
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
|
||||
if event.Key() == tcell.KeyEscape && !editMode && !botRespMode {
|
||||
fromRow, fromColumn, _, _ := textArea.GetCursor()
|
||||
|
||||
29
tools.go
29
tools.go
@@ -9,29 +9,9 @@ import (
|
||||
|
||||
var (
|
||||
// TODO: form that message based on existing funcs
|
||||
// systemMsg = `You're a helpful assistant.
|
||||
// # Tools
|
||||
// You can do functions call if needed.
|
||||
// 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.
|
||||
basicSysMsg = `Large Language Model that helps user with any of his requests.`
|
||||
toolCallRE = regexp.MustCompile(`__tool_call__\s*([\s\S]*?)__tool_call__`)
|
||||
toolSysMsg = `You're a helpful assistant.
|
||||
# Tools
|
||||
You can do functions call if needed.
|
||||
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.
|
||||
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"}
|
||||
)
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user