summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2025-11-24 19:08:34 +0300
committerGrail Finder <wohilas@gmail.com>2025-11-24 19:08:34 +0300
commitfc963f86c94f8d96224414e409fda757f3b2d11d (patch)
treeb770f6e73ead85563d73c2afa4b2e39499c8d6ca
parentadfa6bd78389e01e2b5a6a6d71a718a2c9f10298 (diff)
Feat: parse func call from or
-rw-r--r--llm.go13
-rw-r--r--models/openrouter.go14
2 files changed, 21 insertions, 6 deletions
diff --git a/llm.go b/llm.go
index 55051bd..47a1d46 100644
--- a/llm.go
+++ b/llm.go
@@ -468,6 +468,19 @@ func (or OpenRouterChat) ParseChunk(data []byte) (*models.TextChunk, error) {
resp := &models.TextChunk{
Chunk: llmchunk.Choices[len(llmchunk.Choices)-1].Delta.Content,
}
+
+ // Handle tool calls similar to OpenAIer
+ if len(llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls) > 0 {
+ resp.ToolChunk = llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0].Function.Arguments
+ fname := llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0].Function.Name
+ if fname != "" {
+ resp.FuncName = fname
+ }
+ }
+ if resp.ToolChunk != "" {
+ resp.ToolResp = true
+ }
+
if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason == "stop" {
if resp.Chunk != "" {
logger.Error("text inside of finish llmchunk", "chunk", llmchunk)
diff --git a/models/openrouter.go b/models/openrouter.go
index ac37a85..50f26b6 100644
--- a/models/openrouter.go
+++ b/models/openrouter.go
@@ -57,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 {
@@ -79,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"`