summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2025-08-08 09:43:00 +0300
committerGrail Finder <wohilas@gmail.com>2025-08-08 09:43:00 +0300
commit3c23ff2403124753314cc960635930d9b1134760 (patch)
tree2898181c9619ba40a3be16c9282840736fa22e07
parent9cb4561c828426502b5a28797b932db6c06e22b1 (diff)
Feat: openai type func call for llamacpp
-rw-r--r--bot.go14
-rw-r--r--llm.go24
-rw-r--r--models/models.go2
-rw-r--r--tools.go31
4 files changed, 48 insertions, 23 deletions
diff --git a/bot.go b/bot.go
index 3403b5d..423a7cb 100644
--- a/bot.go
+++ b/bot.go
@@ -554,12 +554,14 @@ func init() {
cluedoState = extra.CluedoPrepCards(playerOrder)
}
if cfg.OpenRouterToken != "" {
- ORModels, err := fetchORModels(true)
- if err != nil {
- logger.Error("failed to fetch or models", "error", err)
- } else {
- ORFreeModels = ORModels
- }
+ go func() {
+ ORModels, err := fetchORModels(true)
+ if err != nil {
+ logger.Error("failed to fetch or models", "error", err)
+ } else {
+ ORFreeModels = ORModels
+ }
+ }()
}
choseChunkParser()
httpClient = createClient(time.Second * 15)
diff --git a/llm.go b/llm.go
index 6d1cdbf..060e90c 100644
--- a/llm.go
+++ b/llm.go
@@ -151,26 +151,18 @@ func (op OpenAIer) ParseChunk(data []byte) (string, bool, error) {
func (op OpenAIer) FormMsg(msg, role string, resume bool) (io.Reader, error) {
logger.Debug("formmsg openaier", "link", cfg.CurrentAPI)
- if cfg.ToolUse && !resume {
- // prompt += "\n" + cfg.ToolRole + ":\n" + toolSysMsg
- // add to chat body
- chatBody.Messages = append(chatBody.Messages, models.RoleMsg{Role: cfg.ToolRole, Content: toolSysMsg})
- }
if msg != "" { // otherwise let the bot continue
newMsg := models.RoleMsg{Role: role, Content: msg}
chatBody.Messages = append(chatBody.Messages, newMsg)
- // if rag
- if cfg.RAGEnabled {
- ragResp, err := chatRagUse(newMsg.Content)
- if err != nil {
- logger.Error("failed to form a rag msg", "error", err)
- return nil, err
- }
- ragMsg := models.RoleMsg{Role: cfg.ToolRole, Content: ragResp}
- chatBody.Messages = append(chatBody.Messages, ragMsg)
- }
}
- data, err := json.Marshal(chatBody)
+ req := models.OpenAIReq{
+ ChatBody: chatBody,
+ Tools: nil,
+ }
+ if cfg.ToolUse && !resume {
+ req.Tools = baseTools // set tools to use
+ }
+ data, err := json.Marshal(req)
if err != nil {
logger.Error("failed to form a msg", "error", err)
return nil, err
diff --git a/models/models.go b/models/models.go
index 51a4b87..c88417f 100644
--- a/models/models.go
+++ b/models/models.go
@@ -285,7 +285,7 @@ type Tool struct {
}
type OpenAIReq struct {
- ChatBody
+ *ChatBody
Tools []Tool `json:"tools"`
}
diff --git a/tools.go b/tools.go
index 01ab32b..3b5fbf6 100644
--- a/tools.go
+++ b/tools.go
@@ -166,4 +166,35 @@ var baseTools = []models.Tool{
},
},
},
+ // recall
+ models.Tool{
+ Type: "function",
+ Function: models.ToolFunc{
+ Name: "recall",
+ Description: "recall topic-data from key-value cache",
+ Parameters: models.ToolFuncParams{
+ Type: "object",
+ Required: []string{"topic"},
+ Properties: map[string]models.ToolArgProps{
+ "topic": models.ToolArgProps{
+ Type: "string",
+ Description: "topic is the key to recall data from",
+ },
+ },
+ },
+ },
+ },
+ // recall_topics
+ models.Tool{
+ Type: "function",
+ Function: models.ToolFunc{
+ Name: "recall_topics",
+ Description: "recall all topics from key-value cache",
+ Parameters: models.ToolFuncParams{
+ Type: "object",
+ Required: []string{},
+ Properties: map[string]models.ToolArgProps{},
+ },
+ },
+ },
}