Enha: rag loader
This commit is contained in:
152
tables.go
152
tables.go
@@ -307,59 +307,105 @@ func makeRAGTable(fileList []string) *tview.Flex {
|
|||||||
return ragflex
|
return ragflex
|
||||||
}
|
}
|
||||||
|
|
||||||
// func makeLoadedRAGTable(fileList []string) *tview.Table {
|
func makeLoadedRAGTable(fileList []string) *tview.Flex {
|
||||||
// actions := []string{"delete"}
|
actions := []string{"delete"}
|
||||||
// rows, cols := len(fileList), len(actions)+1
|
rows, cols := len(fileList), len(actions)+1
|
||||||
// fileTable := tview.NewTable().
|
// Add 1 extra row for the "exit" option at the top
|
||||||
// SetBorders(true)
|
fileTable := tview.NewTable().
|
||||||
// for r := 0; r < rows; r++ {
|
SetBorders(true)
|
||||||
// for c := 0; c < cols; c++ {
|
longStatusView := tview.NewTextView()
|
||||||
// color := tcell.ColorWhite
|
longStatusView.SetText("Loaded RAG files list")
|
||||||
// if c < 1 {
|
longStatusView.SetBorder(true).SetTitle("status")
|
||||||
// fileTable.SetCell(r, c,
|
longStatusView.SetChangedFunc(func() {
|
||||||
// tview.NewTableCell(fileList[r]).
|
app.Draw()
|
||||||
// SetTextColor(color).
|
})
|
||||||
// SetAlign(tview.AlignCenter))
|
ragflex := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||||
// } else {
|
AddItem(longStatusView, 0, 10, false).
|
||||||
// fileTable.SetCell(r, c,
|
AddItem(fileTable, 0, 60, true)
|
||||||
// tview.NewTableCell(actions[c-1]).
|
|
||||||
// SetTextColor(color).
|
// Add the exit option as the first row (row 0)
|
||||||
// SetAlign(tview.AlignCenter))
|
fileTable.SetCell(0, 0,
|
||||||
// }
|
tview.NewTableCell("Exit Loaded Files manager").
|
||||||
// }
|
SetTextColor(tcell.ColorWhite).
|
||||||
// }
|
SetAlign(tview.AlignCenter))
|
||||||
// fileTable.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
|
fileTable.SetCell(0, 1,
|
||||||
// if key == tcell.KeyEsc || key == tcell.KeyF1 {
|
tview.NewTableCell("(Close without action)").
|
||||||
// pages.RemovePage(RAGPage)
|
SetTextColor(tcell.ColorGray).
|
||||||
// return
|
SetAlign(tview.AlignCenter))
|
||||||
// }
|
fileTable.SetCell(0, 2,
|
||||||
// if key == tcell.KeyEnter {
|
tview.NewTableCell("exit").
|
||||||
// fileTable.SetSelectable(true, true)
|
SetTextColor(tcell.ColorGray).
|
||||||
// }
|
SetAlign(tview.AlignCenter))
|
||||||
// }).SetSelectedFunc(func(row int, column int) {
|
|
||||||
// defer pages.RemovePage(RAGPage)
|
// Add the file rows starting from row 1
|
||||||
// tc := fileTable.GetCell(row, column)
|
for r := 0; r < rows; r++ {
|
||||||
// tc.SetTextColor(tcell.ColorRed)
|
for c := 0; c < cols; c++ {
|
||||||
// fileTable.SetSelectable(false, false)
|
color := tcell.ColorWhite
|
||||||
// fpath := fileList[row]
|
if c < 1 {
|
||||||
// // notification := fmt.Sprintf("chat: %s; action: %s", fpath, tc.Text)
|
fileTable.SetCell(r+1, c, // +1 to account for the exit row at index 0
|
||||||
// switch tc.Text {
|
tview.NewTableCell(fileList[r]).
|
||||||
// case "delete":
|
SetTextColor(color).
|
||||||
// if err := ragger.RemoveFile(fpath); err != nil {
|
SetAlign(tview.AlignCenter))
|
||||||
// logger.Error("failed to delete file", "filename", fpath, "error", err)
|
} else {
|
||||||
// return
|
fileTable.SetCell(r+1, c, // +1 to account for the exit row at index 0
|
||||||
// }
|
tview.NewTableCell(actions[c-1]).
|
||||||
// if err := notifyUser("chat deleted", fpath+" was deleted"); err != nil {
|
SetTextColor(color).
|
||||||
// logger.Error("failed to send notification", "error", err)
|
SetAlign(tview.AlignCenter))
|
||||||
// }
|
}
|
||||||
// return
|
}
|
||||||
// default:
|
}
|
||||||
// // pages.RemovePage(RAGPage)
|
|
||||||
// return
|
fileTable.Select(0, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
|
||||||
// }
|
if key == tcell.KeyEsc || key == tcell.KeyF1 || key == tcell.Key('x') || key == tcell.KeyCtrlX {
|
||||||
// })
|
pages.RemovePage(RAGLoadedPage)
|
||||||
// return fileTable
|
return
|
||||||
// }
|
}
|
||||||
|
if key == tcell.KeyEnter {
|
||||||
|
fileTable.SetSelectable(true, true)
|
||||||
|
}
|
||||||
|
}).SetSelectedFunc(func(row int, column int) {
|
||||||
|
tc := fileTable.GetCell(row, column)
|
||||||
|
tc.SetTextColor(tcell.ColorRed)
|
||||||
|
fileTable.SetSelectable(false, false)
|
||||||
|
|
||||||
|
// Check if the selected row is the exit row (row 0) - do this first to avoid index issues
|
||||||
|
if row == 0 {
|
||||||
|
pages.RemovePage(RAGLoadedPage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// For file rows, get the filename (row index - 1 because of the exit row at index 0)
|
||||||
|
fpath := fileList[row-1] // -1 to account for the exit row at index 0
|
||||||
|
|
||||||
|
switch tc.Text {
|
||||||
|
case "delete":
|
||||||
|
if err := ragger.RemoveFile(fpath); err != nil {
|
||||||
|
logger.Error("failed to delete file from RAG", "filename", fpath, "error", err)
|
||||||
|
longStatusView.SetText(fmt.Sprintf("Error deleting file: %v", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := notifyUser("RAG file deleted", fpath+" was deleted from RAG system"); err != nil {
|
||||||
|
logger.Error("failed to send notification", "error", err)
|
||||||
|
}
|
||||||
|
longStatusView.SetText(fpath + " was deleted from RAG system")
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
pages.RemovePage(RAGLoadedPage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Add input capture to the flex container to handle 'x' key for closing
|
||||||
|
ragflex.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||||
|
if event.Key() == tcell.KeyRune && event.Rune() == 'x' {
|
||||||
|
pages.RemovePage(RAGLoadedPage)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return event
|
||||||
|
})
|
||||||
|
|
||||||
|
return ragflex
|
||||||
|
}
|
||||||
|
|
||||||
func makeAgentTable(agentList []string) *tview.Table {
|
func makeAgentTable(agentList []string) *tview.Table {
|
||||||
actions := []string{"filepath", "load"}
|
actions := []string{"filepath", "load"}
|
||||||
|
|||||||
36
tui.go
36
tui.go
@@ -39,6 +39,7 @@ var (
|
|||||||
helpPage = "helpPage"
|
helpPage = "helpPage"
|
||||||
renamePage = "renamePage"
|
renamePage = "renamePage"
|
||||||
RAGPage = "RAGPage"
|
RAGPage = "RAGPage"
|
||||||
|
RAGLoadedPage = "RAGLoadedPage"
|
||||||
propsPage = "propsPage"
|
propsPage = "propsPage"
|
||||||
codeBlockPage = "codeBlockPage"
|
codeBlockPage = "codeBlockPage"
|
||||||
imgPage = "imgPage"
|
imgPage = "imgPage"
|
||||||
@@ -75,6 +76,7 @@ var (
|
|||||||
[yellow]Ctrl+j[white]: if chat agent is char.png will show the image; then any key to return
|
[yellow]Ctrl+j[white]: if chat agent is char.png will show the image; then any key to return
|
||||||
[yellow]Ctrl+a[white]: interrupt tts (needs tts server)
|
[yellow]Ctrl+a[white]: interrupt tts (needs tts server)
|
||||||
[yellow]Ctrl+g[white]: open RAG file manager (load files for context retrieval)
|
[yellow]Ctrl+g[white]: open RAG file manager (load files for context retrieval)
|
||||||
|
[yellow]Ctrl+y[white]: list loaded RAG files (view and manage loaded files)
|
||||||
[yellow]Ctrl+q[white]: cycle through mentioned chars in chat, to pick persona to send next msg as
|
[yellow]Ctrl+q[white]: cycle through mentioned chars in chat, to pick persona to send next msg as
|
||||||
[yellow]Ctrl+x[white]: cycle through mentioned chars in chat, to pick persona to send next msg as (for llm)
|
[yellow]Ctrl+x[white]: cycle through mentioned chars in chat, to pick persona to send next msg as (for llm)
|
||||||
RAG Window: [yellow]x[white]: close window | [yellow]Enter[white]: select action
|
RAG Window: [yellow]x[white]: close window | [yellow]Enter[white]: select action
|
||||||
@@ -823,26 +825,6 @@ func init() {
|
|||||||
pages.AddPage(imgPage, imgView, true, true)
|
pages.AddPage(imgPage, imgView, true, true)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// DEPRECATED: rag is deprecated until I change my mind
|
|
||||||
// if event.Key() == tcell.KeyCtrlR && cfg.HFToken != "" {
|
|
||||||
// // rag load
|
|
||||||
// // menu of the text files from defined rag directory
|
|
||||||
// files, err := os.ReadDir(cfg.RAGDir)
|
|
||||||
// if err != nil {
|
|
||||||
// logger.Error("failed to read dir", "dir", cfg.RAGDir, "error", err)
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
// fileList := []string{}
|
|
||||||
// for _, f := range files {
|
|
||||||
// if f.IsDir() {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// fileList = append(fileList, f.Name())
|
|
||||||
// }
|
|
||||||
// chatRAGTable := makeRAGTable(fileList)
|
|
||||||
// pages.AddPage(RAGPage, chatRAGTable, true, true)
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
if event.Key() == tcell.KeyCtrlR && cfg.STT_ENABLED {
|
if event.Key() == tcell.KeyCtrlR && cfg.STT_ENABLED {
|
||||||
defer updateStatusLine()
|
defer updateStatusLine()
|
||||||
if asr.IsRecording() {
|
if asr.IsRecording() {
|
||||||
@@ -961,6 +943,20 @@ func init() {
|
|||||||
pages.AddPage(RAGPage, chatRAGTable, true, true)
|
pages.AddPage(RAGPage, chatRAGTable, true, true)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if event.Key() == tcell.KeyCtrlY { // Use Ctrl+Y to list loaded RAG files
|
||||||
|
// List files already loaded into the RAG system
|
||||||
|
fileList, err := ragger.ListLoaded()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("failed to list loaded RAG files", "error", err)
|
||||||
|
if notifyerr := notifyUser("failed to list RAG files", err.Error()); notifyerr != nil {
|
||||||
|
logger.Error("failed to send notification", "error", notifyerr)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
chatLoadedRAGTable := makeLoadedRAGTable(fileList)
|
||||||
|
pages.AddPage(RAGLoadedPage, chatLoadedRAGTable, 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 {
|
||||||
// read all text into buffer
|
// read all text into buffer
|
||||||
|
|||||||
Reference in New Issue
Block a user