fix(providers): normalize responses truncation reason
This commit is contained in:
parent
f18f15766a
commit
3d5c36eb60
2 changed files with 28 additions and 2 deletions
|
|
@ -359,7 +359,7 @@ func parseResponseEnvelope(apiResp *responseEnvelope) (*protocoltypes.LLMRespons
|
||||||
if len(toolCalls) > 0 {
|
if len(toolCalls) > 0 {
|
||||||
finishReason = "tool_calls"
|
finishReason = "tool_calls"
|
||||||
} else if status == "incomplete" {
|
} else if status == "incomplete" {
|
||||||
finishReason = "length"
|
finishReason = "truncated"
|
||||||
if apiResp.IncompleteDetails != nil &&
|
if apiResp.IncompleteDetails != nil &&
|
||||||
apiResp.IncompleteDetails.Reason != "" &&
|
apiResp.IncompleteDetails.Reason != "" &&
|
||||||
apiResp.IncompleteDetails.Reason != "max_output_tokens" {
|
apiResp.IncompleteDetails.Reason != "max_output_tokens" {
|
||||||
|
|
@ -438,7 +438,7 @@ func parseResponse(apiResp *responses.Response) *protocoltypes.LLMResponse {
|
||||||
}
|
}
|
||||||
switch apiResp.Status {
|
switch apiResp.Status {
|
||||||
case responses.ResponseStatusIncomplete:
|
case responses.ResponseStatusIncomplete:
|
||||||
finishReason = "length"
|
finishReason = "truncated"
|
||||||
case responses.ResponseStatusFailed:
|
case responses.ResponseStatusFailed:
|
||||||
finishReason = "error"
|
finishReason = "error"
|
||||||
case responses.ResponseStatusCancelled:
|
case responses.ResponseStatusCancelled:
|
||||||
|
|
|
||||||
|
|
@ -474,6 +474,32 @@ func TestParseResponseBody_IncompleteStatus(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseResponseBody_IncompleteStatusUsesTruncatedForMaxOutputTokens(t *testing.T) {
|
||||||
|
body := strings.NewReader(`{
|
||||||
|
"id": "resp_inc_truncated",
|
||||||
|
"object": "response",
|
||||||
|
"status": "incomplete",
|
||||||
|
"output": [
|
||||||
|
{
|
||||||
|
"type": "message",
|
||||||
|
"content": [{"type": "output_text", "text": "partial"}]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"incomplete_details": {"reason": "max_output_tokens"},
|
||||||
|
"usage": {"input_tokens": 5, "output_tokens": 2, "total_tokens": 7,
|
||||||
|
"input_tokens_details": {"cached_tokens": 0},
|
||||||
|
"output_tokens_details": {"reasoning_tokens": 0}}
|
||||||
|
}`)
|
||||||
|
|
||||||
|
result, err := ParseResponseBody(body)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error: %v", err)
|
||||||
|
}
|
||||||
|
if result.FinishReason != "truncated" {
|
||||||
|
t.Fatalf("FinishReason = %q, want %q", result.FinishReason, "truncated")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseResponseBody_FailedStatus(t *testing.T) {
|
func TestParseResponseBody_FailedStatus(t *testing.T) {
|
||||||
body := strings.NewReader(`{
|
body := strings.NewReader(`{
|
||||||
"id": "resp_fail",
|
"id": "resp_fail",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue