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"
|
"github.com/revrost/go-openrouter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ToolReasoning struct {
|
||||||
|
Format string `msgpack:"format"`
|
||||||
|
Encrypted string `msgpack:"encrypted"`
|
||||||
|
}
|
||||||
|
|
||||||
type ToolCall struct {
|
type ToolCall struct {
|
||||||
ID string `msgpack:"id"`
|
ID string `msgpack:"id"`
|
||||||
Name string `msgpack:"name"`
|
Name string `msgpack:"name"`
|
||||||
Args string `msgpack:"args"`
|
Args string `msgpack:"args"`
|
||||||
Result string `msgpack:"result,omitempty"`
|
Result string `msgpack:"result,omitempty"`
|
||||||
Done bool `msgpack:"done,omitempty"`
|
Done bool `msgpack:"done,omitempty"`
|
||||||
Invalid bool `msgpack:"invalid,omitempty"`
|
Invalid bool `msgpack:"invalid,omitempty"`
|
||||||
Cost float64 `msgpack:"cost,omitempty"`
|
Cost float64 `msgpack:"cost,omitempty"`
|
||||||
|
Reasoning *ToolReasoning `msgpack:"reasoning,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TextFile struct {
|
type TextFile struct {
|
||||||
@@ -69,7 +75,7 @@ func (t *ToolCall) AsAssistantToolCall(content string) openrouter.ChatCompletion
|
|||||||
content = " "
|
content = " "
|
||||||
}
|
}
|
||||||
|
|
||||||
return openrouter.ChatCompletionMessage{
|
call := openrouter.ChatCompletionMessage{
|
||||||
Role: openrouter.ChatMessageRoleAssistant,
|
Role: openrouter.ChatMessageRoleAssistant,
|
||||||
Content: openrouter.Content{
|
Content: openrouter.Content{
|
||||||
Text: 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 {
|
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
|
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, "{")
|
open += strings.Count(call.Function.Arguments, "{")
|
||||||
close += strings.Count(call.Function.Arguments, "}")
|
close += strings.Count(call.Function.Arguments, "}")
|
||||||
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -18,3 +18,5 @@ require (
|
|||||||
golang.org/x/sys v0.37.0 // indirect
|
golang.org/x/sys v0.37.0 // indirect
|
||||||
golang.org/x/term v0.36.0 // indirect
|
golang.org/x/term v0.36.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace github.com/revrost/go-openrouter => github.com/coalaura/go-openrouter v0.0.2-0.20251118165837-080dd9683303
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,3 +1,5 @@
|
|||||||
|
github.com/coalaura/go-openrouter v0.0.2-0.20251118165837-080dd9683303 h1:Y7ROVL2NxI5Yc04fApAxqExkzBigrWiWv5ag209uNM0=
|
||||||
|
github.com/coalaura/go-openrouter v0.0.2-0.20251118165837-080dd9683303/go.mod h1:jZFcumFqvS25o8oEQc1/+4yeK7lHDSnwPMIJ/pKPdNc=
|
||||||
github.com/coalaura/plain v0.2.0 h1:naGiTT1nmZO78IGHOajm0wc/X4sqaG6g3CSR3Ha9f6w=
|
github.com/coalaura/plain v0.2.0 h1:naGiTT1nmZO78IGHOajm0wc/X4sqaG6g3CSR3Ha9f6w=
|
||||||
github.com/coalaura/plain v0.2.0/go.mod h1:HR/sQt288EMTF3aSEGKHwPmGYFU4FOrfarMUf6ifnLo=
|
github.com/coalaura/plain v0.2.0/go.mod h1:HR/sQt288EMTF3aSEGKHwPmGYFU4FOrfarMUf6ifnLo=
|
||||||
github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc=
|
github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc=
|
||||||
@@ -12,8 +14,6 @@ github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
|
|||||||
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/revrost/go-openrouter v0.2.6 h1:5riNi1FaWHIC2A2EP5hGunUGfU998vcz+CsIWsOWjx0=
|
|
||||||
github.com/revrost/go-openrouter v0.2.6/go.mod h1:jZFcumFqvS25o8oEQc1/+4yeK7lHDSnwPMIJ/pKPdNc=
|
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
||||||
|
|||||||
Reference in New Issue
Block a user