Enha: table for sysprompts
This commit is contained in:
@@ -58,5 +58,6 @@
|
||||
- message editing broke ( runtime error: index out of range [-1]); +
|
||||
- RAG: encode multiple sentences (~5-10) to embeddings a piece. +
|
||||
- number of sentences in a batch should depend on number of words there. +
|
||||
- F1 can load any chat, by loading chat of other agent it does not switch agents, if that chat is continued, it will rewrite agent in db; (either allow only chats from current agent OR switch agent on chat loading);
|
||||
- after chat is deleted: load undeleted chat;
|
||||
- F1 can load any chat, by loading chat of other agent it does not switch agents, if that chat is continued, it will rewrite agent in db; (either allow only chats from current agent OR switch agent on chat loading); +
|
||||
- after chat is deleted: load undeleted chat; +
|
||||
- syscards sometimes store data inside of chub key;
|
||||
|
||||
86
tables.go
86
tables.go
@@ -59,8 +59,6 @@ func makeChatTable(chatList []string) *tview.Table {
|
||||
textView.SetText(chatToText(cfg.ShowSys))
|
||||
activeChatName = selectedChat
|
||||
pages.RemovePage(historyPage)
|
||||
colorText()
|
||||
updateStatusLine()
|
||||
return
|
||||
case "rename":
|
||||
pages.RemovePage(historyPage)
|
||||
@@ -79,6 +77,9 @@ func makeChatTable(chatList []string) *tview.Table {
|
||||
if err := notifyUser("chat deleted", selectedChat+" was deleted"); err != nil {
|
||||
logger.Error("failed to send notification", "error", err)
|
||||
}
|
||||
// load last chat
|
||||
chatBody.Messages = loadOldChatOrGetNew()
|
||||
textView.SetText(chatToText(cfg.ShowSys))
|
||||
pages.RemovePage(historyPage)
|
||||
return
|
||||
default:
|
||||
@@ -174,9 +175,6 @@ func makeRAGTable(fileList []string) *tview.Flex {
|
||||
return
|
||||
}
|
||||
}()
|
||||
// make new page and write status updates to it
|
||||
// colorText()
|
||||
// updateStatusLine()
|
||||
return
|
||||
case "delete":
|
||||
fpath = path.Join(cfg.RAGDir, fpath)
|
||||
@@ -189,7 +187,6 @@ func makeRAGTable(fileList []string) *tview.Flex {
|
||||
}
|
||||
return
|
||||
default:
|
||||
// pages.RemovePage(RAGPage)
|
||||
return
|
||||
}
|
||||
})
|
||||
@@ -249,3 +246,80 @@ func makeLoadedRAGTable(fileList []string) *tview.Table {
|
||||
})
|
||||
return fileTable
|
||||
}
|
||||
|
||||
func makeAgentTable(agentList []string) *tview.Table {
|
||||
actions := []string{"load"}
|
||||
rows, cols := len(agentList), len(actions)+1
|
||||
chatActTable := tview.NewTable().
|
||||
SetBorders(true)
|
||||
for r := 0; r < rows; r++ {
|
||||
for c := 0; c < cols; c++ {
|
||||
color := tcell.ColorWhite
|
||||
if c < 1 {
|
||||
chatActTable.SetCell(r, c,
|
||||
tview.NewTableCell(agentList[r]).
|
||||
SetTextColor(color).
|
||||
SetAlign(tview.AlignCenter))
|
||||
} else {
|
||||
chatActTable.SetCell(r, c,
|
||||
tview.NewTableCell(actions[c-1]).
|
||||
SetTextColor(color).
|
||||
SetAlign(tview.AlignCenter))
|
||||
}
|
||||
}
|
||||
}
|
||||
chatActTable.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
|
||||
if key == tcell.KeyEsc || key == tcell.KeyF1 {
|
||||
pages.RemovePage(agentPage)
|
||||
return
|
||||
}
|
||||
if key == tcell.KeyEnter {
|
||||
chatActTable.SetSelectable(true, true)
|
||||
}
|
||||
}).SetSelectedFunc(func(row int, column int) {
|
||||
tc := chatActTable.GetCell(row, column)
|
||||
tc.SetTextColor(tcell.ColorRed)
|
||||
chatActTable.SetSelectable(false, false)
|
||||
selected := agentList[row]
|
||||
// notification := fmt.Sprintf("chat: %s; action: %s", selectedChat, tc.Text)
|
||||
switch tc.Text {
|
||||
case "load":
|
||||
if ok := charToStart(selected); !ok {
|
||||
logger.Warn("no such sys msg", "name", selected)
|
||||
pages.RemovePage(agentPage)
|
||||
return
|
||||
}
|
||||
// replace textview
|
||||
textView.SetText(chatToText(cfg.ShowSys))
|
||||
colorText()
|
||||
updateStatusLine()
|
||||
// sysModal.ClearButtons()
|
||||
pages.RemovePage(agentPage)
|
||||
app.SetFocus(textArea)
|
||||
return
|
||||
case "rename":
|
||||
pages.RemovePage(agentPage)
|
||||
pages.AddPage(renamePage, renameWindow, true, true)
|
||||
return
|
||||
case "delete":
|
||||
sc, ok := chatMap[selected]
|
||||
if !ok {
|
||||
// no chat found
|
||||
pages.RemovePage(agentPage)
|
||||
return
|
||||
}
|
||||
if err := store.RemoveChat(sc.ID); err != nil {
|
||||
logger.Error("failed to remove chat from db", "chat_id", sc.ID, "chat_name", sc.Name)
|
||||
}
|
||||
if err := notifyUser("chat deleted", selected+" was deleted"); err != nil {
|
||||
logger.Error("failed to send notification", "error", err)
|
||||
}
|
||||
pages.RemovePage(agentPage)
|
||||
return
|
||||
default:
|
||||
pages.RemovePage(agentPage)
|
||||
return
|
||||
}
|
||||
})
|
||||
return chatActTable
|
||||
}
|
||||
|
||||
2
tools.go
2
tools.go
@@ -63,7 +63,7 @@ After that you are free to respond to the user.
|
||||
}
|
||||
// sysMap = map[string]string{"basic_sys": basicSysMsg, "tool_sys": toolSysMsg}
|
||||
sysMap = map[string]*models.CharCard{"basic_sys": basicCard, "tool_sys": toolCard}
|
||||
sysLabels = []string{"cancel", "basic_sys", "tool_sys"}
|
||||
sysLabels = []string{"basic_sys", "tool_sys"}
|
||||
)
|
||||
|
||||
/*
|
||||
|
||||
41
tui.go
41
tui.go
@@ -23,7 +23,7 @@ var (
|
||||
helpView *tview.TextView
|
||||
flex *tview.Flex
|
||||
// chatActModal *tview.Modal
|
||||
sysModal *tview.Modal
|
||||
// sysModal *tview.Modal
|
||||
indexPickWindow *tview.InputField
|
||||
renameWindow *tview.InputField
|
||||
//
|
||||
@@ -96,6 +96,10 @@ func initSysCards() ([]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
for _, cc := range cards {
|
||||
if cc.Role == "" {
|
||||
logger.Warn("empty role", "file", cc.FilePath)
|
||||
continue
|
||||
}
|
||||
sysMap[cc.Role] = cc
|
||||
labels = append(labels, cc.Role)
|
||||
}
|
||||
@@ -157,34 +161,13 @@ func init() {
|
||||
position = tview.NewTextView().
|
||||
SetDynamicColors(true).
|
||||
SetTextAlign(tview.AlignCenter)
|
||||
|
||||
position.SetChangedFunc(func() {
|
||||
app.Draw()
|
||||
})
|
||||
flex = tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(textView, 0, 40, false).
|
||||
AddItem(textArea, 0, 10, true).
|
||||
AddItem(position, 0, 1, false)
|
||||
sysModal = tview.NewModal().
|
||||
SetText("Switch sys msg:").
|
||||
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
||||
switch buttonLabel {
|
||||
case "cancel":
|
||||
pages.RemovePage(agentPage)
|
||||
sysModal.ClearButtons()
|
||||
return
|
||||
default:
|
||||
if ok := charToStart(buttonLabel); !ok {
|
||||
logger.Warn("no such sys msg", "name", buttonLabel)
|
||||
pages.RemovePage(agentPage)
|
||||
return
|
||||
}
|
||||
// replace textview
|
||||
textView.SetText(chatToText(cfg.ShowSys))
|
||||
colorText()
|
||||
updateStatusLine()
|
||||
sysModal.ClearButtons()
|
||||
pages.RemovePage(agentPage)
|
||||
app.SetFocus(textArea)
|
||||
}
|
||||
})
|
||||
editArea = tview.NewTextArea().
|
||||
SetPlaceholder("Replace msg...")
|
||||
editArea.SetBorder(true).SetTitle("input")
|
||||
@@ -332,6 +315,8 @@ func init() {
|
||||
}
|
||||
chatActTable := makeChatTable(nameList)
|
||||
pages.AddPage(historyPage, chatActTable, true, true)
|
||||
colorText()
|
||||
updateStatusLine()
|
||||
return nil
|
||||
}
|
||||
if event.Key() == tcell.KeyF2 {
|
||||
@@ -453,9 +438,10 @@ func init() {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
sysModal.AddButtons(labels)
|
||||
at := makeAgentTable(labels)
|
||||
// sysModal.AddButtons(labels)
|
||||
// load all chars
|
||||
pages.AddPage(agentPage, sysModal, true, true)
|
||||
pages.AddPage(agentPage, at, true, true)
|
||||
updateStatusLine()
|
||||
return nil
|
||||
}
|
||||
@@ -481,7 +467,6 @@ func init() {
|
||||
}
|
||||
// cannot send msg in editMode or botRespMode
|
||||
if event.Key() == tcell.KeyEscape && !editMode && !botRespMode {
|
||||
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
|
||||
// read all text into buffer
|
||||
msgText := textArea.GetText()
|
||||
nl := "\n"
|
||||
|
||||
Reference in New Issue
Block a user