Feat: openai type func call for llamacpp
This commit is contained in:
2
bot.go
2
bot.go
@@ -554,12 +554,14 @@ func init() {
|
|||||||
cluedoState = extra.CluedoPrepCards(playerOrder)
|
cluedoState = extra.CluedoPrepCards(playerOrder)
|
||||||
}
|
}
|
||||||
if cfg.OpenRouterToken != "" {
|
if cfg.OpenRouterToken != "" {
|
||||||
|
go func() {
|
||||||
ORModels, err := fetchORModels(true)
|
ORModels, err := fetchORModels(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("failed to fetch or models", "error", err)
|
logger.Error("failed to fetch or models", "error", err)
|
||||||
} else {
|
} else {
|
||||||
ORFreeModels = ORModels
|
ORFreeModels = ORModels
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
choseChunkParser()
|
choseChunkParser()
|
||||||
httpClient = createClient(time.Second * 15)
|
httpClient = createClient(time.Second * 15)
|
||||||
|
|||||||
20
llm.go
20
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) {
|
func (op OpenAIer) FormMsg(msg, role string, resume bool) (io.Reader, error) {
|
||||||
logger.Debug("formmsg openaier", "link", cfg.CurrentAPI)
|
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
|
if msg != "" { // otherwise let the bot continue
|
||||||
newMsg := models.RoleMsg{Role: role, Content: msg}
|
newMsg := models.RoleMsg{Role: role, Content: msg}
|
||||||
chatBody.Messages = append(chatBody.Messages, newMsg)
|
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}
|
req := models.OpenAIReq{
|
||||||
chatBody.Messages = append(chatBody.Messages, ragMsg)
|
ChatBody: chatBody,
|
||||||
|
Tools: nil,
|
||||||
}
|
}
|
||||||
|
if cfg.ToolUse && !resume {
|
||||||
|
req.Tools = baseTools // set tools to use
|
||||||
}
|
}
|
||||||
data, err := json.Marshal(chatBody)
|
data, err := json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("failed to form a msg", "error", err)
|
logger.Error("failed to form a msg", "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ type Tool struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OpenAIReq struct {
|
type OpenAIReq struct {
|
||||||
ChatBody
|
*ChatBody
|
||||||
Tools []Tool `json:"tools"`
|
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