mirror of
https://github.com/coalaura/whiskr.git
synced 2025-12-02 20:22:52 +00:00
keep tool reasoning
This commit is contained in:
49
chat.go
49
chat.go
@@ -14,14 +14,20 @@ import (
|
||||
"github.com/revrost/go-openrouter"
|
||||
)
|
||||
|
||||
type ToolReasoning struct {
|
||||
Format string `msgpack:"format"`
|
||||
Encrypted string `msgpack:"encrypted"`
|
||||
}
|
||||
|
||||
type ToolCall struct {
|
||||
ID string `msgpack:"id"`
|
||||
Name string `msgpack:"name"`
|
||||
Args string `msgpack:"args"`
|
||||
Result string `msgpack:"result,omitempty"`
|
||||
Done bool `msgpack:"done,omitempty"`
|
||||
Invalid bool `msgpack:"invalid,omitempty"`
|
||||
Cost float64 `msgpack:"cost,omitempty"`
|
||||
ID string `msgpack:"id"`
|
||||
Name string `msgpack:"name"`
|
||||
Args string `msgpack:"args"`
|
||||
Result string `msgpack:"result,omitempty"`
|
||||
Done bool `msgpack:"done,omitempty"`
|
||||
Invalid bool `msgpack:"invalid,omitempty"`
|
||||
Cost float64 `msgpack:"cost,omitempty"`
|
||||
Reasoning *ToolReasoning `msgpack:"reasoning,omitempty"`
|
||||
}
|
||||
|
||||
type TextFile struct {
|
||||
@@ -69,7 +75,7 @@ func (t *ToolCall) AsAssistantToolCall(content string) openrouter.ChatCompletion
|
||||
content = " "
|
||||
}
|
||||
|
||||
return openrouter.ChatCompletionMessage{
|
||||
call := openrouter.ChatCompletionMessage{
|
||||
Role: openrouter.ChatMessageRoleAssistant,
|
||||
Content: openrouter.Content{
|
||||
Text: content,
|
||||
@@ -85,6 +91,20 @@ func (t *ToolCall) AsAssistantToolCall(content string) openrouter.ChatCompletion
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if t.Reasoning != nil {
|
||||
call.ReasoningDetails = []openrouter.ChatCompletionReasoningDetails{
|
||||
{
|
||||
Type: openrouter.ReasoningDetailsTypeEncrypted,
|
||||
Data: t.Reasoning.Encrypted,
|
||||
ID: t.ID,
|
||||
Format: t.Reasoning.Format,
|
||||
Index: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return call
|
||||
}
|
||||
|
||||
func (t *ToolCall) AsToolMessage() openrouter.ChatCompletionMessage {
|
||||
@@ -521,6 +541,19 @@ func RunCompletion(ctx context.Context, response *Stream, request *openrouter.Ch
|
||||
tool.Name += call.Function.Name
|
||||
}
|
||||
|
||||
if len(delta.ReasoningDetails) != 0 && tool.Reasoning == nil {
|
||||
for _, details := range delta.ReasoningDetails {
|
||||
if details.Type != openrouter.ReasoningDetailsTypeEncrypted {
|
||||
continue
|
||||
}
|
||||
|
||||
tool.Reasoning = &ToolReasoning{
|
||||
Format: details.Format,
|
||||
Encrypted: details.Data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open += strings.Count(call.Function.Arguments, "{")
|
||||
close += strings.Count(call.Function.Arguments, "}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user