diff options
author | Grail Finder <wohilas@gmail.com> | 2024-11-27 15:09:43 +0300 |
---|---|---|
committer | Grail Finder <wohilas@gmail.com> | 2024-11-27 15:09:43 +0300 |
commit | 55007d27f808426128a7b2d86169e86c4cf01b57 (patch) | |
tree | 683b0e6ff99117024feedca253588c15c85f564e /bot.go | |
parent | 7f48741b11038715f82747f1eacee14470547855 (diff) |
Fix: tool calls
Diffstat (limited to 'bot.go')
-rw-r--r-- | bot.go | 24 |
1 files changed, 8 insertions, 16 deletions
@@ -31,7 +31,7 @@ var ( // TODO: pass as an cli arg or have config APIURL = "http://localhost:8080/v1/chat/completions" logFileName = "log.txt" - showSystemMsgs bool + showSystemMsgs = true chunkLimit = 1000 activeChatName string chunkChan = make(chan string, 10) @@ -158,21 +158,16 @@ out: } func findCall(msg string, tv *tview.TextView) { - // prefix := "__tool_call__\n" - // suffix := "\n__tool_call__" - // if !strings.HasPrefix(msg, prefix) || - // !strings.HasSuffix(msg, suffix) { - // return - // } - // jsStr := strings.TrimSuffix(strings.TrimPrefix(msg, prefix), suffix) fc := models.FuncCall{} jsStr := toolCallRE.FindString(msg) if jsStr == "" { - // tool call not found return } + prefix := "__tool_call__\n" + suffix := "\n__tool_call__" + jsStr = strings.TrimSuffix(strings.TrimPrefix(jsStr, prefix), suffix) if err := json.Unmarshal([]byte(jsStr), &fc); err != nil { - logger.Error("failed to unmarshal tool call", "error", err) + logger.Error("failed to unmarshal tool call", "error", err, "json_string", jsStr) return } // call a func @@ -182,12 +177,9 @@ func findCall(msg string, tv *tview.TextView) { chatRound(m, toolRole, tv) return } - resp := f(fc.Args) - toolMsg := fmt.Sprintf("tool response: %+v", resp) - // reader := formMsg(chatBody, toolMsg, toolRole) - // sendMsgToLLM() + resp := f(fc.Args...) + toolMsg := fmt.Sprintf("tool response: %+v", string(resp)) chatRound(toolMsg, toolRole, tv) - // return func result to the llm } func chatToTextSlice(showSys bool) []string { @@ -248,7 +240,7 @@ func init() { // load all chats in memory loadHistoryChats() lastChat := loadOldChatOrGetNew() - logger.Info("loaded history", "chat", lastChat) + logger.Info("loaded history") chatBody = &models.ChatBody{ Model: "modl_name", Stream: true, |