Feat: parse func call from or
This commit is contained in:
13
llm.go
13
llm.go
@@ -468,6 +468,19 @@ func (or OpenRouterChat) ParseChunk(data []byte) (*models.TextChunk, error) {
|
|||||||
resp := &models.TextChunk{
|
resp := &models.TextChunk{
|
||||||
Chunk: llmchunk.Choices[len(llmchunk.Choices)-1].Delta.Content,
|
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 llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason == "stop" {
|
||||||
if resp.Chunk != "" {
|
if resp.Chunk != "" {
|
||||||
logger.Error("text inside of finish llmchunk", "chunk", llmchunk)
|
logger.Error("text inside of finish llmchunk", "chunk", llmchunk)
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ type OpenRouterChatRespNonStream struct {
|
|||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Refusal any `json:"refusal"`
|
Refusal any `json:"refusal"`
|
||||||
Reasoning any `json:"reasoning"`
|
Reasoning any `json:"reasoning"`
|
||||||
|
ToolCalls []ToolDeltaResp `json:"tool_calls"`
|
||||||
} `json:"message"`
|
} `json:"message"`
|
||||||
} `json:"choices"`
|
} `json:"choices"`
|
||||||
Usage struct {
|
Usage struct {
|
||||||
@@ -81,6 +82,7 @@ type OpenRouterChatResp struct {
|
|||||||
Delta struct {
|
Delta struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
ToolCalls []ToolDeltaResp `json:"tool_calls"`
|
||||||
} `json:"delta"`
|
} `json:"delta"`
|
||||||
FinishReason string `json:"finish_reason"`
|
FinishReason string `json:"finish_reason"`
|
||||||
NativeFinishReason string `json:"native_finish_reason"`
|
NativeFinishReason string `json:"native_finish_reason"`
|
||||||
|
|||||||
Reference in New Issue
Block a user