Compare commits
1
Commits
6e972335c9
...
a5e3c7c817
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5e3c7c817 |
+1
-1
@@ -195,7 +195,7 @@ func emitParsed(ctx context.Context, r io.Reader, out chan<- Event) {
|
|||||||
// A finish reason alone does not prove the tool arguments arrived intact.
|
// A finish reason alone does not prove the tool arguments arrived intact.
|
||||||
// Preserve returned usage when rejecting a partial terminal, so the host
|
// Preserve returned usage when rejecting a partial terminal, so the host
|
||||||
// can charge this call and stop rather than treating it as a free retry.
|
// can charge this call and stop rather than treating it as a free retry.
|
||||||
if finished == "tool_calls" && len(order) == 0 {
|
if (finished == "tool_calls" || finished == "function_call") && len(order) == 0 {
|
||||||
sendTerminalFailure("tool call finish reason without a tool call")
|
sendTerminalFailure("tool call finish reason without a tool call")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-14
@@ -94,20 +94,24 @@ func TestParseSSEToolCallIncrements(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseSSEToolFinishWithoutCallFails(t *testing.T) {
|
func TestParseSSEToolFinishWithoutCallFails(t *testing.T) {
|
||||||
body := strings.Join([]string{
|
for _, reason := range []string{"tool_calls", "function_call"} {
|
||||||
`data: {"choices":[{"delta":{},"finish_reason":"tool_calls"}],"usage":{"prompt_tokens":12,"completion_tokens":5,"total_tokens":17}}`,
|
t.Run(reason, func(t *testing.T) {
|
||||||
`data: [DONE]`,
|
body := strings.Join([]string{
|
||||||
"",
|
`data: {"choices":[{"delta":{},"finish_reason":"` + reason + `"}],"usage":{"prompt_tokens":12,"completion_tokens":5,"total_tokens":17}}`,
|
||||||
}, "\n")
|
`data: [DONE]`,
|
||||||
var end Event
|
"",
|
||||||
for ev := range ParseSSE(context.Background(), strings.NewReader(body)) {
|
}, "\n")
|
||||||
if ev.Kind == KindMessageEnd {
|
var end Event
|
||||||
end = ev
|
for ev := range ParseSSE(context.Background(), strings.NewReader(body)) {
|
||||||
}
|
if ev.Kind == KindMessageEnd {
|
||||||
}
|
end = ev
|
||||||
if end.Err == nil || end.Message.StopReason != StopError || end.Usage.TotalTokens != 17 ||
|
}
|
||||||
!end.StreamComplete || len(end.Message.ToolCalls) != 0 {
|
}
|
||||||
t.Fatalf("empty tool finish must fail and retain Usage: %#v", end)
|
if end.Err == nil || end.Message.StopReason != StopError || end.Usage.TotalTokens != 17 ||
|
||||||
|
!end.StreamComplete || len(end.Message.ToolCalls) != 0 {
|
||||||
|
t.Fatalf("empty tool finish must fail and retain Usage: %#v", end)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user