From cc84c037ece2a89424d490d9ee819f06cf4bb347 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Thu, 21 Nov 2024 20:16:47 +0300 Subject: Enha: match tool call with regexp; clear panics --- main.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 6a1311e..c7528f5 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "elefant/models" - "encoding/json" "fmt" "strconv" "time" @@ -63,7 +62,7 @@ func main() { chatOpts := []string{"cancel", "new"} fList, err := loadHistoryChats() if err != nil { - panic(err) + logger.Error("failed to load chat history", "error", err) } chatOpts = append(chatOpts, fList...) chatActModal := tview.NewModal(). @@ -74,15 +73,10 @@ func main() { case "new": // set chat body chatBody.Messages = defaultStarter - // TODO: use predefined var since it is the same each time - msgsBytes, err := json.Marshal(chatBody.Messages) - if err != nil { - logger.Error(err.Error()) - } textView.SetText(chatToText(showSystemMsgs)) newChat := &models.Chat{ Name: fmt.Sprintf("%v_%v", "new", time.Now().Unix()), - Msgs: string(msgsBytes), + Msgs: string(defaultStarterBytes), } // activeChatName = path.Join(historyDir, fmt.Sprintf("%d_chat.json", time.Now().Unix())) activeChatName = newChat.Name @@ -166,10 +160,10 @@ func main() { textView.ScrollToEnd() app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyF1 { - // fList, err := listHistoryFiles(historyDir) fList, err := loadHistoryChats() if err != nil { - panic(err) + logger.Error("failed to load chat history", "error", err) + return nil } chatOpts = append(chatOpts, fList...) pages.AddPage("history", chatActModal, true, true) @@ -220,6 +214,10 @@ func main() { pages.AddPage("getIndex", indexPickWindow, true, true) return nil } + if event.Key() == tcell.KeyCtrlE { + textArea.SetText("pressed ctrl+e", true) + return nil + } // cannot send msg in editMode or botRespMode if event.Key() == tcell.KeyEscape && !editMode && !botRespMode { fromRow, fromColumn, _, _ := textArea.GetCursor() @@ -251,6 +249,7 @@ func main() { pages.AddPage("main", flex, true, true) if err := app.SetRoot(pages, true).EnableMouse(true).Run(); err != nil { - panic(err) + logger.Error("failed to start tview app", "error", err) + return } } -- cgit v1.2.3