Feat: openai type func call for llamacpp
This commit is contained in:
14
bot.go
14
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)
|
||||
|
||||
24
llm.go
24
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
|
||||
|
||||
@@ -285,7 +285,7 @@ type Tool struct {
|
||||
}
|
||||
|
||||
type OpenAIReq struct {
|
||||
ChatBody
|
||||
*ChatBody
|
||||
Tools []Tool `json:"tools"`
|
||||
}
|
||||
|
||||
|
||||
31
tools.go
31
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{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user