Enha: table for sysprompts

This commit is contained in:
Grail Finder
2025-01-15 18:05:47 +03:00
parent 1ea19ba11e
commit db678b5215
4 changed files with 97 additions and 37 deletions

View File

@@ -58,5 +58,6 @@
- message editing broke ( runtime error: index out of range [-1]); + - message editing broke ( runtime error: index out of range [-1]); +
- RAG: encode multiple sentences (~5-10) to embeddings a piece. + - RAG: encode multiple sentences (~5-10) to embeddings a piece. +
- number of sentences in a batch should depend on number of words there. + - 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); - 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; - after chat is deleted: load undeleted chat; +
- syscards sometimes store data inside of chub key;

View File

@@ -59,8 +59,6 @@ func makeChatTable(chatList []string) *tview.Table {
textView.SetText(chatToText(cfg.ShowSys)) textView.SetText(chatToText(cfg.ShowSys))
activeChatName = selectedChat activeChatName = selectedChat
pages.RemovePage(historyPage) pages.RemovePage(historyPage)
colorText()
updateStatusLine()
return return
case "rename": case "rename":
pages.RemovePage(historyPage) pages.RemovePage(historyPage)
@@ -79,6 +77,9 @@ func makeChatTable(chatList []string) *tview.Table {
if err := notifyUser("chat deleted", selectedChat+" was deleted"); err != nil { if err := notifyUser("chat deleted", selectedChat+" was deleted"); err != nil {
logger.Error("failed to send notification", "error", err) logger.Error("failed to send notification", "error", err)
} }
// load last chat
chatBody.Messages = loadOldChatOrGetNew()
textView.SetText(chatToText(cfg.ShowSys))
pages.RemovePage(historyPage) pages.RemovePage(historyPage)
return return
default: default:
@@ -174,9 +175,6 @@ func makeRAGTable(fileList []string) *tview.Flex {
return return
} }
}() }()
// make new page and write status updates to it
// colorText()
// updateStatusLine()
return return
case "delete": case "delete":
fpath = path.Join(cfg.RAGDir, fpath) fpath = path.Join(cfg.RAGDir, fpath)
@@ -189,7 +187,6 @@ func makeRAGTable(fileList []string) *tview.Flex {
} }
return return
default: default:
// pages.RemovePage(RAGPage)
return return
} }
}) })
@@ -249,3 +246,80 @@ func makeLoadedRAGTable(fileList []string) *tview.Table {
}) })
return fileTable 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
}

View File

@@ -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]string{"basic_sys": basicSysMsg, "tool_sys": toolSysMsg}
sysMap = map[string]*models.CharCard{"basic_sys": basicCard, "tool_sys": toolCard} 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
View File

@@ -23,7 +23,7 @@ var (
helpView *tview.TextView helpView *tview.TextView
flex *tview.Flex flex *tview.Flex
// chatActModal *tview.Modal // chatActModal *tview.Modal
sysModal *tview.Modal // sysModal *tview.Modal
indexPickWindow *tview.InputField indexPickWindow *tview.InputField
renameWindow *tview.InputField renameWindow *tview.InputField
// //
@@ -96,6 +96,10 @@ func initSysCards() ([]string, error) {
return nil, err return nil, err
} }
for _, cc := range cards { for _, cc := range cards {
if cc.Role == "" {
logger.Warn("empty role", "file", cc.FilePath)
continue
}
sysMap[cc.Role] = cc sysMap[cc.Role] = cc
labels = append(labels, cc.Role) labels = append(labels, cc.Role)
} }
@@ -157,34 +161,13 @@ func init() {
position = tview.NewTextView(). position = tview.NewTextView().
SetDynamicColors(true). SetDynamicColors(true).
SetTextAlign(tview.AlignCenter) SetTextAlign(tview.AlignCenter)
position.SetChangedFunc(func() {
app.Draw()
})
flex = tview.NewFlex().SetDirection(tview.FlexRow). flex = tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(textView, 0, 40, false). AddItem(textView, 0, 40, false).
AddItem(textArea, 0, 10, true). AddItem(textArea, 0, 10, true).
AddItem(position, 0, 1, false) 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(). editArea = tview.NewTextArea().
SetPlaceholder("Replace msg...") SetPlaceholder("Replace msg...")
editArea.SetBorder(true).SetTitle("input") editArea.SetBorder(true).SetTitle("input")
@@ -332,6 +315,8 @@ func init() {
} }
chatActTable := makeChatTable(nameList) chatActTable := makeChatTable(nameList)
pages.AddPage(historyPage, chatActTable, true, true) pages.AddPage(historyPage, chatActTable, true, true)
colorText()
updateStatusLine()
return nil return nil
} }
if event.Key() == tcell.KeyF2 { if event.Key() == tcell.KeyF2 {
@@ -453,9 +438,10 @@ func init() {
} }
return nil return nil
} }
sysModal.AddButtons(labels) at := makeAgentTable(labels)
// sysModal.AddButtons(labels)
// load all chars // load all chars
pages.AddPage(agentPage, sysModal, true, true) pages.AddPage(agentPage, at, true, true)
updateStatusLine() updateStatusLine()
return nil return nil
} }
@@ -481,7 +467,6 @@ func init() {
} }
// 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 {
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
// read all text into buffer // read all text into buffer
msgText := textArea.GetText() msgText := textArea.GetText()
nl := "\n" nl := "\n"