Feat: tool model for or

This commit is contained in:
Grail Finder
2025-11-24 18:30:46 +03:00
parent 73c048e666
commit adfa6bd783
2 changed files with 4 additions and 10 deletions

13
llm.go
View File

@@ -76,7 +76,6 @@ type OpenRouterChat struct {
Model string Model string
} }
func (lcp LlamaCPPeer) GetToken() string { func (lcp LlamaCPPeer) GetToken() string {
return "" return ""
} }
@@ -484,16 +483,9 @@ func (or OpenRouterChat) GetToken() string {
func (or OpenRouterChat) FormMsg(msg, role string, resume bool) (io.Reader, error) { func (or OpenRouterChat) FormMsg(msg, role string, resume bool) (io.Reader, error) {
logger.Debug("formmsg open router completion", "link", cfg.CurrentAPI) logger.Debug("formmsg open router completion", "link", cfg.CurrentAPI)
// Capture the image attachment path at the beginning to avoid race conditions // Capture the image attachment path at the beginning to avoid race conditions
// with API rotation that might clear the global variable // with API rotation that might clear the global variable
localImageAttachmentPath := imageAttachmentPath localImageAttachmentPath := imageAttachmentPath
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
var newMsg models.RoleMsg var newMsg models.RoleMsg
// Check if we have an image to add to this message // Check if we have an image to add to this message
@@ -536,7 +528,6 @@ func (or OpenRouterChat) FormMsg(msg, role string, resume bool) (io.Reader, erro
Model: chatBody.Model, Model: chatBody.Model,
Stream: chatBody.Stream, Stream: chatBody.Stream,
} }
for i, msg := range chatBody.Messages { for i, msg := range chatBody.Messages {
bodyCopy.Messages[i] = msg bodyCopy.Messages[i] = msg
// Standardize role if it's a user role // Standardize role if it's a user role
@@ -544,8 +535,10 @@ func (or OpenRouterChat) FormMsg(msg, role string, resume bool) (io.Reader, erro
bodyCopy.Messages[i].Role = "user" bodyCopy.Messages[i].Role = "user"
} }
} }
orBody := models.NewOpenRouterChatReq(*bodyCopy, defaultLCPProps) orBody := models.NewOpenRouterChatReq(*bodyCopy, defaultLCPProps)
if cfg.ToolUse && !resume && role != cfg.ToolRole {
orBody.Tools = baseTools // set tools to use
}
data, err := json.Marshal(orBody) data, err := json.Marshal(orBody)
if err != nil { if err != nil {
logger.Error("failed to form a msg", "error", err) logger.Error("failed to form a msg", "error", err)

View File

@@ -31,6 +31,7 @@ type OpenRouterChatReq struct {
Temperature float32 `json:"temperature"` Temperature float32 `json:"temperature"`
MinP float32 `json:"min_p"` MinP float32 `json:"min_p"`
NPredict int32 `json:"max_tokens"` NPredict int32 `json:"max_tokens"`
Tools []Tool `json:"tools"`
} }
func NewOpenRouterChatReq(cb ChatBody, props map[string]float32) OpenRouterChatReq { func NewOpenRouterChatReq(cb ChatBody, props map[string]float32) OpenRouterChatReq {