summaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2025-11-28 14:35:13 +0300
committerGrail Finder <wohilas@gmail.com>2025-11-28 14:35:13 +0300
commit4bd76fc7d5b69252f5391aab193a59f7ca82a38b (patch)
tree97846b889835924f007ea9e6963b96ab45d9a73a /models
parent7b8505174488d9475ad3594cd355a08e1d2ba5a8 (diff)
parent860160ea0e4d940eee43da8f20538293612093a5 (diff)
Merge branch 'enha/or-tools'HEADmaster
Diffstat (limited to 'models')
-rw-r--r--models/models.go44
-rw-r--r--models/openrouter.go15
2 files changed, 37 insertions, 22 deletions
diff --git a/models/models.go b/models/models.go
index 58f0291..798ea35 100644
--- a/models/models.go
+++ b/models/models.go
@@ -9,6 +9,7 @@ import (
)
type FuncCall struct {
+ ID string `json:"id,omitempty"`
Name string `json:"name"`
Args map[string]string `json:"args"`
}
@@ -39,6 +40,7 @@ type ToolDeltaFunc struct {
}
type ToolDeltaResp struct {
+ ID string `json:"id,omitempty"`
Index int `json:"index"`
Function ToolDeltaFunc `json:"function"`
}
@@ -70,6 +72,7 @@ type TextChunk struct {
Finished bool
ToolResp bool
FuncName string
+ ToolID string
}
type TextContentPart struct {
@@ -86,10 +89,11 @@ type ImageContentPart struct {
// RoleMsg represents a message with content that can be either a simple string or structured content parts
type RoleMsg struct {
- Role string `json:"role"`
- Content string `json:"-"`
- ContentParts []interface{} `json:"-"`
- hasContentParts bool // Flag to indicate which content type to marshal
+ Role string `json:"role"`
+ Content string `json:"-"`
+ ContentParts []interface{} `json:"-"`
+ ToolCallID string `json:"tool_call_id,omitempty"` // For tool response messages
+ hasContentParts bool // Flag to indicate which content type to marshal
}
// MarshalJSON implements custom JSON marshaling for RoleMsg
@@ -97,21 +101,25 @@ func (m RoleMsg) MarshalJSON() ([]byte, error) {
if m.hasContentParts {
// Use structured content format
aux := struct {
- Role string `json:"role"`
- Content []interface{} `json:"content"`
+ Role string `json:"role"`
+ Content []interface{} `json:"content"`
+ ToolCallID string `json:"tool_call_id,omitempty"`
}{
- Role: m.Role,
- Content: m.ContentParts,
+ Role: m.Role,
+ Content: m.ContentParts,
+ ToolCallID: m.ToolCallID,
}
return json.Marshal(aux)
} else {
// Use simple content format
aux := struct {
- Role string `json:"role"`
- Content string `json:"content"`
+ Role string `json:"role"`
+ Content string `json:"content"`
+ ToolCallID string `json:"tool_call_id,omitempty"`
}{
- Role: m.Role,
- Content: m.Content,
+ Role: m.Role,
+ Content: m.Content,
+ ToolCallID: m.ToolCallID,
}
return json.Marshal(aux)
}
@@ -121,26 +129,30 @@ func (m RoleMsg) MarshalJSON() ([]byte, error) {
func (m *RoleMsg) UnmarshalJSON(data []byte) error {
// First, try to unmarshal as structured content format
var structured struct {
- Role string `json:"role"`
- Content []interface{} `json:"content"`
+ Role string `json:"role"`
+ Content []interface{} `json:"content"`
+ ToolCallID string `json:"tool_call_id,omitempty"`
}
if err := json.Unmarshal(data, &structured); err == nil && len(structured.Content) > 0 {
m.Role = structured.Role
m.ContentParts = structured.Content
+ m.ToolCallID = structured.ToolCallID
m.hasContentParts = true
return nil
}
// Otherwise, unmarshal as simple content format
var simple struct {
- Role string `json:"role"`
- Content string `json:"content"`
+ Role string `json:"role"`
+ Content string `json:"content"`
+ ToolCallID string `json:"tool_call_id,omitempty"`
}
if err := json.Unmarshal(data, &simple); err != nil {
return err
}
m.Role = simple.Role
m.Content = simple.Content
+ m.ToolCallID = simple.ToolCallID
m.hasContentParts = false
return nil
}
diff --git a/models/openrouter.go b/models/openrouter.go
index 933598e..50f26b6 100644
--- a/models/openrouter.go
+++ b/models/openrouter.go
@@ -31,6 +31,7 @@ type OpenRouterChatReq struct {
Temperature float32 `json:"temperature"`
MinP float32 `json:"min_p"`
NPredict int32 `json:"max_tokens"`
+ Tools []Tool `json:"tools"`
}
func NewOpenRouterChatReq(cb ChatBody, props map[string]float32) OpenRouterChatReq {
@@ -56,10 +57,11 @@ type OpenRouterChatRespNonStream struct {
NativeFinishReason string `json:"native_finish_reason"`
Index int `json:"index"`
Message struct {
- Role string `json:"role"`
- Content string `json:"content"`
- Refusal any `json:"refusal"`
- Reasoning any `json:"reasoning"`
+ Role string `json:"role"`
+ Content string `json:"content"`
+ Refusal any `json:"refusal"`
+ Reasoning any `json:"reasoning"`
+ ToolCalls []ToolDeltaResp `json:"tool_calls"`
} `json:"message"`
} `json:"choices"`
Usage struct {
@@ -78,8 +80,9 @@ type OpenRouterChatResp struct {
Choices []struct {
Index int `json:"index"`
Delta struct {
- Role string `json:"role"`
- Content string `json:"content"`
+ Role string `json:"role"`
+ Content string `json:"content"`
+ ToolCalls []ToolDeltaResp `json:"tool_calls"`
} `json:"delta"`
FinishReason string `json:"finish_reason"`
NativeFinishReason string `json:"native_finish_reason"`