summaryrefslogtreecommitdiff
path: root/bot.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2024-11-19 17:15:02 +0300
committerGrail Finder <wohilas@gmail.com>2024-11-19 17:15:02 +0300
commitf32375488f5127c910021f627d83e017c5c7a10f (patch)
tree5a697ca8a42e3651fa57ea346af223b67f3e3a3a /bot.go
parentd3cc8774b13a0c8e9fbf11947b9caca216595a8d (diff)
Feat: add storage interface; add sqlite impl
Diffstat (limited to 'bot.go')
-rw-r--r--bot.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/bot.go b/bot.go
index be35a09..3a4fb6d 100644
--- a/bot.go
+++ b/bot.go
@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"elefant/models"
+ "elefant/storage"
"encoding/json"
"fmt"
"io"
@@ -37,12 +38,14 @@ var (
chunkChan = make(chan string, 10)
streamDone = make(chan bool, 1)
chatBody *models.ChatBody
+ store storage.ChatHistory
defaultFirstMsg = "Hello! What can I do for you?"
defaultStarter = []models.MessagesStory{
{Role: "system", Content: systemMsg},
{Role: assistantRole, Content: defaultFirstMsg},
}
- systemMsg = `You're a helpful assistant.
+ interruptResp = false
+ systemMsg = `You're a helpful assistant.
# Tools
You can do functions call if needed.
Your current tools:
@@ -116,11 +119,17 @@ func sendMsgToLLM(body io.Reader) (any, error) {
logger.Error("llamacpp api", "error", err)
return nil, err
}
+ defer resp.Body.Close()
llmResp := []models.LLMRespChunk{}
// chunkChan <- assistantIcon
reader := bufio.NewReader(resp.Body)
counter := 0
for {
+ if interruptResp {
+ interruptResp = false
+ logger.Info("interrupted bot response")
+ break
+ }
llmchunk := models.LLMRespChunk{}
if counter > 2000 {
streamDone <- true
@@ -340,6 +349,10 @@ func init() {
if err != nil {
panic(err)
}
+ // create dir if does not exist
+ if err := os.MkdirAll(historyDir, os.ModePerm); err != nil {
+ panic(err)
+ }
// defer file.Close()
logger = slog.New(slog.NewTextHandler(file, nil))
logger.Info("test msg")
@@ -351,4 +364,5 @@ func init() {
Stream: true,
Messages: lastChat,
}
+ store = storage.NewProviderSQL("test.db")
}