mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-17 19:47:10 +08:00
fix: request OpenAI Responses reasoning summaries
This commit is contained in:
@@ -50,6 +50,7 @@ type openAIResponsesRequestBody struct {
|
|||||||
|
|
||||||
type openAIResponsesReasoning struct {
|
type openAIResponsesReasoning struct {
|
||||||
Effort string `json:"effort,omitempty"`
|
Effort string `json:"effort,omitempty"`
|
||||||
|
Summary string `json:"summary,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type openAIToolAccumulator struct {
|
type openAIToolAccumulator struct {
|
||||||
@@ -944,7 +945,7 @@ func (adapter *OpenAIAdapter) streamResponses(ctx context.Context, req StreamReq
|
|||||||
requestBody.Tools = tools
|
requestBody.Tools = tools
|
||||||
}
|
}
|
||||||
if effort := strings.TrimSpace(req.ReasoningEffort); effort != "" {
|
if effort := strings.TrimSpace(req.ReasoningEffort); effort != "" {
|
||||||
requestBody.Reasoning = &openAIResponsesReasoning{Effort: effort}
|
requestBody.Reasoning = &openAIResponsesReasoning{Effort: effort, Summary: "auto"}
|
||||||
requestBody.Include = []string{"reasoning.encrypted_content"}
|
requestBody.Include = []string{"reasoning.encrypted_content"}
|
||||||
}
|
}
|
||||||
body = requestBody
|
body = requestBody
|
||||||
|
|||||||
@@ -2,12 +2,67 @@ package modeladapter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestOpenAIResponsesRequestsReasoningSummary(t *testing.T) {
|
||||||
|
var requestBody map[string]any
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
if err := json.NewDecoder(request.Body).Decode(&requestBody); err != nil {
|
||||||
|
http.Error(writer, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writer.Header().Set("Content-Type", "text/event-stream")
|
||||||
|
_, _ = fmt.Fprint(writer, "data: {\"type\":\"response.reasoning_summary_text.delta\",\"delta\":\"check the request\"}\n\n")
|
||||||
|
_, _ = fmt.Fprint(writer, "data: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp-1\",\"model\":\"gpt-5.6\",\"status\":\"completed\",\"output_text\":\"done\"}}\n\n")
|
||||||
|
_, _ = fmt.Fprint(writer, "data: [DONE]\n\n")
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
adapter := &OpenAIAdapter{client: server.Client()}
|
||||||
|
events := make([]ModelEvent, 0, 4)
|
||||||
|
err := adapter.Stream(context.Background(), StreamRequest{
|
||||||
|
RequestID: "request-1",
|
||||||
|
RunID: "run-1",
|
||||||
|
ModelCallID: "model-call-1",
|
||||||
|
BaseURL: server.URL,
|
||||||
|
APIKey: "test-key",
|
||||||
|
ProviderModelID: "gpt-5.6",
|
||||||
|
OpenAIEndpoint: "/v1/responses",
|
||||||
|
ReasoningEffort: "high",
|
||||||
|
Messages: []Message{{Role: "user", Content: "hello"}},
|
||||||
|
MaxTokens: 128,
|
||||||
|
}, func(event ModelEvent) error {
|
||||||
|
events = append(events, event)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("stream failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
reasoning, ok := requestBody["reasoning"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("reasoning request body missing: %#v", requestBody)
|
||||||
|
}
|
||||||
|
if got := reasoning["effort"]; got != "high" {
|
||||||
|
t.Fatalf("reasoning.effort = %#v, want high", got)
|
||||||
|
}
|
||||||
|
if got := reasoning["summary"]; got != "auto" {
|
||||||
|
t.Fatalf("reasoning.summary = %#v, want auto", got)
|
||||||
|
}
|
||||||
|
include, ok := requestBody["include"].([]any)
|
||||||
|
if !ok || len(include) != 1 || include[0] != "reasoning.encrypted_content" {
|
||||||
|
t.Fatalf("reasoning include = %#v, want encrypted content", requestBody["include"])
|
||||||
|
}
|
||||||
|
assertOpenAIEventKindCount(t, events, ModelEventKindThinkingDelta, 1)
|
||||||
|
assertOpenAIEventKindCount(t, events, ModelEventKindThinkingCompleted, 1)
|
||||||
|
assertOpenAIEventKindCount(t, events, ModelEventKindTextDelta, 1)
|
||||||
|
}
|
||||||
|
|
||||||
func TestOpenAIChatCompletionsIgnoresBlankFinishReason(t *testing.T) {
|
func TestOpenAIChatCompletionsIgnoresBlankFinishReason(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "text/event-stream")
|
writer.Header().Set("Content-Type", "text/event-stream")
|
||||||
|
|||||||
Reference in New Issue
Block a user