mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 08:06:50 +00:00
Merge pull request #8295 from r266-tech/codex/fix-responses-tool-failover
fix(openai): fail over Sol/Terra tool requests on Chat-only accounts
This commit is contained in:
5 files changed
+348
-16
No files matched your search
@@ -3640,6 +3640,12 @@ func (h *OpenAIGatewayHandler) handleFailoverExhausted(c *gin.Context, failoverE
|
||||
h.handleFailoverExhaustedSimple(c, http.StatusBadGateway, streamStarted)
|
||||
return
|
||||
}
|
||||
if failoverErr.Reason == service.OpenAIResponsesToolsUnsupportedReason {
|
||||
// No upstream request was sent for this local capability mismatch. Keep
|
||||
// the original client error without attributing it to upstream health.
|
||||
h.handleStreamingAwareError(c, failoverErr.ClientStatusCode, "invalid_request_error", failoverErr.ClientMessage, streamStarted)
|
||||
return
|
||||
}
|
||||
copyFailoverRetryAfter(c, failoverErr.ResponseHeaders)
|
||||
if failoverErr.IsOpenAIRequestBodyTooLarge() {
|
||||
// An operator-configured passthrough rule wins over the built-in body
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
//go:build unit
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
const solToolsTestResponse = `{"id":"resp_tools","object":"response","model":"gpt-6.1-sol","status":"completed","output":[{"id":"fc_lookup","type":"function_call","call_id":"call_lookup","name":"lookup","arguments":"{}","status":"completed"}],"usage":{"input_tokens":1,"output_tokens":1}}`
|
||||
|
||||
func TestResponsesSolToolsSwitchAccount(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
for _, stream := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("stream=%t", stream), func(t *testing.T) {
|
||||
accounts := solToolsTestAccounts(false, true)
|
||||
before, err := json.Marshal(accounts)
|
||||
require.NoError(t, err)
|
||||
response := solToolsTestResponse
|
||||
contentType := "application/json"
|
||||
if stream {
|
||||
contentType = "text/event-stream"
|
||||
response = "event: response.created\ndata: {\"type\":\"response.created\",\"response\":{\"id\":\"resp_tools\",\"status\":\"in_progress\"}}\n\n" +
|
||||
"event: response.function_call_arguments.delta\ndata: {\"type\":\"response.function_call_arguments.delta\",\"item_id\":\"fc_lookup\",\"output_index\":0,\"delta\":\"{}\"}\n\n" +
|
||||
"event: response.completed\ndata: {\"type\":\"response.completed\",\"response\":" + solToolsTestResponse + "}\n\n"
|
||||
}
|
||||
upstream := newAstraProCapturedUpstream(&http.Response{
|
||||
StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{contentType}},
|
||||
Body: io.NopCloser(strings.NewReader(response)),
|
||||
})
|
||||
h, repo := newSolToolsFailoverHandler(t, accounts, upstream)
|
||||
body := solToolsTestRequest(stream)
|
||||
c, rec := newAstraProFailoverContext(t, body)
|
||||
|
||||
h.Responses(c)
|
||||
|
||||
urls, accountIDs, bodies := upstream.snapshot()
|
||||
require.Equal(t, []int64{2}, accountIDs, "the first account is incompatible, not an upstream attempt")
|
||||
require.Equal(t, []string{"https://upstream.example/v1/responses"}, urls)
|
||||
require.Len(t, bodies, 1)
|
||||
require.Equal(t, "gpt-6.1-sol", gjson.GetBytes(bodies[0], "model").String())
|
||||
require.JSONEq(t, gjson.Get(body, "tools").Raw, gjson.GetBytes(bodies[0], "tools").Raw)
|
||||
require.Equal(t, http.StatusOK, rec.Code)
|
||||
require.Contains(t, rec.Body.String(), "function_call")
|
||||
require.NotContains(t, rec.Body.String(), "response.failed")
|
||||
require.NotContains(t, rec.Body.String(), "only supports Chat Completions")
|
||||
require.Equal(t, 2, repo.selectorCalls())
|
||||
require.Empty(t, repo.errorIDs())
|
||||
require.Empty(t, repo.rateLimitedAccountIDs())
|
||||
after, err := json.Marshal(accounts)
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, string(before), string(after), "routing must not change capability flags, models or scheduling")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponsesSolToolsFailoverExhausted(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
stream bool
|
||||
started bool
|
||||
maxSwitches int
|
||||
wantSelections int
|
||||
}{
|
||||
{"json", false, false, 10, 3},
|
||||
{"stream_not_started", true, false, 10, 3},
|
||||
{"stream_keepalive", true, true, 10, 3},
|
||||
{"bounded", false, false, 0, 1},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
upstream := newAstraProCapturedUpstream()
|
||||
accounts := solToolsTestAccounts(false, false)
|
||||
before, err := json.Marshal(accounts)
|
||||
require.NoError(t, err)
|
||||
h, repo := newSolToolsFailoverHandler(t, accounts, upstream)
|
||||
h.maxAccountSwitches = tc.maxSwitches
|
||||
c, rec := newAstraProFailoverContext(t, solToolsTestRequest(tc.stream))
|
||||
if tc.started {
|
||||
_, err := c.Writer.WriteString(": keepalive\n\n")
|
||||
require.NoError(t, err)
|
||||
c.Writer.Flush()
|
||||
}
|
||||
|
||||
h.Responses(c)
|
||||
|
||||
_, accountIDs, _ := upstream.snapshot()
|
||||
require.Empty(t, accountIDs)
|
||||
if tc.started {
|
||||
require.Equal(t, 1, strings.Count(rec.Body.String(), "event: response.failed\n"))
|
||||
require.True(t, strings.HasPrefix(rec.Body.String(), ": keepalive\n\nevent: response.failed\n"))
|
||||
} else {
|
||||
require.Equal(t, http.StatusBadRequest, rec.Code)
|
||||
require.True(t, json.Valid(rec.Body.Bytes()), "must not append SSE to a JSON error")
|
||||
require.Equal(t, "invalid_request_error", gjson.GetBytes(rec.Body.Bytes(), "error.type").String())
|
||||
}
|
||||
require.Contains(t, rec.Body.String(), "gpt-6.1-sol")
|
||||
_, hasUpstreamError := c.Get(service.OpsUpstreamStatusCodeKey)
|
||||
require.False(t, hasUpstreamError, "local incompatibility must not be recorded as an upstream HTTP failure")
|
||||
require.Equal(t, tc.wantSelections, repo.selectorCalls())
|
||||
require.Empty(t, repo.errorIDs())
|
||||
require.Empty(t, repo.rateLimitedAccountIDs())
|
||||
after, err := json.Marshal(accounts)
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, string(before), string(after), "exhaustion must not change account state")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponsesSolPlainTextStillUsesChatAccount(t *testing.T) {
|
||||
upstream := newAstraProCapturedUpstream(&http.Response{
|
||||
StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/json"}},
|
||||
Body: io.NopCloser(strings.NewReader(`{"id":"chat_sol","model":"gpt-6.1-sol","choices":[{"message":{"role":"assistant","content":"ok"},"finish_reason":"stop"}],"usage":{"prompt_tokens":1,"completion_tokens":1}}`)),
|
||||
})
|
||||
h, repo := newSolToolsFailoverHandler(t, solToolsTestAccounts(false, true), upstream)
|
||||
c, rec := newAstraProFailoverContext(t, `{"model":"public-alias","input":"hello","stream":false}`)
|
||||
|
||||
h.Responses(c)
|
||||
|
||||
urls, accountIDs, _ := upstream.snapshot()
|
||||
require.Equal(t, []int64{1}, accountIDs)
|
||||
require.Equal(t, []string{"https://upstream.example/v1/chat/completions"}, urls)
|
||||
require.Equal(t, http.StatusOK, rec.Code)
|
||||
require.Equal(t, "ok", gjson.GetBytes(rec.Body.Bytes(), "output.0.content.0.text").String())
|
||||
require.Equal(t, 1, repo.selectorCalls())
|
||||
}
|
||||
|
||||
func solToolsTestRequest(stream bool) string {
|
||||
return fmt.Sprintf(`{"model":"public-alias","input":"hello","stream":%t,"tools":[{"type":"function","name":"lookup","parameters":{"type":"object"}}]}`, stream)
|
||||
}
|
||||
|
||||
func solToolsTestAccounts(supported ...bool) []service.Account {
|
||||
accounts := make([]service.Account, 0, len(supported))
|
||||
for i, value := range supported {
|
||||
accounts = append(accounts, service.Account{
|
||||
ID: int64(i + 1), Name: fmt.Sprintf("responses-account-%d", i+1),
|
||||
Platform: service.PlatformOpenAI, Type: service.AccountTypeAPIKey,
|
||||
Status: service.StatusActive, Schedulable: true, Priority: i,
|
||||
Credentials: map[string]any{
|
||||
"api_key": "test-key", "base_url": "https://upstream.example",
|
||||
"model_mapping": map[string]any{"public-alias": "gpt-6.1-sol"},
|
||||
},
|
||||
Extra: map[string]any{"openai_responses_supported": value},
|
||||
})
|
||||
}
|
||||
return accounts
|
||||
}
|
||||
|
||||
func newSolToolsFailoverHandler(t *testing.T, accounts []service.Account, upstream service.HTTPUpstream) (*OpenAIGatewayHandler, *grokCredentialHandlerRepo) {
|
||||
t.Helper()
|
||||
cfg := &config.Config{RunMode: config.RunModeSimple}
|
||||
repo := &grokCredentialHandlerRepo{accounts: accounts}
|
||||
gateway := service.NewOpenAIGatewayService(
|
||||
repo, nil, nil, nil, nil, nil, nil, cfg,
|
||||
nil, nil, nil, nil, nil, upstream, nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
)
|
||||
billing := service.NewBillingCacheService(nil, nil, nil, nil, nil, nil, cfg, nil)
|
||||
t.Cleanup(billing.Stop)
|
||||
h := NewOpenAIGatewayHandler(
|
||||
gateway, service.NewConcurrencyService(nil), billing,
|
||||
service.NewAPIKeyService(nil, nil, nil, nil, nil, nil, cfg),
|
||||
nil, nil, nil, nil, cfg,
|
||||
)
|
||||
h.maxAccountSwitches = 10
|
||||
return h, repo
|
||||
}
|
||||
@@ -758,8 +758,9 @@ func (r *ForwardResult) upstreamPriceFactor() float64 {
|
||||
type GatewayFailureStage string
|
||||
|
||||
const (
|
||||
GatewayFailureStageInference GatewayFailureStage = "inference"
|
||||
GatewayFailureStageAccountAuth GatewayFailureStage = "account_auth"
|
||||
GatewayFailureStageInference GatewayFailureStage = "inference"
|
||||
GatewayFailureStageAccountAuth GatewayFailureStage = "account_auth"
|
||||
GatewayFailureStageRequestCompatibility GatewayFailureStage = "request_compatibility"
|
||||
)
|
||||
|
||||
// GatewayFailureScope identifies whether selecting another account can help.
|
||||
@@ -811,6 +812,9 @@ func (e *UpstreamFailoverError) Error() string {
|
||||
if e != nil && e.Stage == GatewayFailureStageAccountAuth {
|
||||
return fmt.Sprintf("credential failure: %s (failover)", e.Reason)
|
||||
}
|
||||
if e != nil && e.Stage == GatewayFailureStageRequestCompatibility {
|
||||
return fmt.Sprintf("request compatibility failure: %s (failover)", e.Reason)
|
||||
}
|
||||
return fmt.Sprintf("upstream error: %d (failover)", e.StatusCode)
|
||||
}
|
||||
|
||||
@@ -823,10 +827,10 @@ func (e *UpstreamFailoverError) IsCredentialFailure() bool {
|
||||
}
|
||||
|
||||
// ShouldReportAccountScheduleFailure prevents provider- and request-scoped
|
||||
// credential failures from being misattributed to the selected account. Legacy
|
||||
// and inference failures retain their existing scheduler-health behavior.
|
||||
// credential failures and local request incompatibility from being misattributed
|
||||
// to account health. Legacy and inference failures retain their existing behavior.
|
||||
func (e *UpstreamFailoverError) ShouldReportAccountScheduleFailure() bool {
|
||||
if e == nil {
|
||||
if e == nil || e.Stage == GatewayFailureStageRequestCompatibility {
|
||||
return false
|
||||
}
|
||||
return !e.IsCredentialFailure() || e.Scope == GatewayFailureScopeAccount
|
||||
|
||||
@@ -22,6 +22,8 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const OpenAIResponsesToolsUnsupportedReason GatewayFailureReason = "openai_responses_tools_unsupported"
|
||||
|
||||
// forwardResponsesViaRawChatCompletions serves /v1/responses clients through an
|
||||
// upstream that only supports /v1/chat/completions.
|
||||
func (s *OpenAIGatewayService) forwardResponsesViaRawChatCompletions(
|
||||
@@ -52,6 +54,31 @@ func (s *OpenAIGatewayService) forwardResponsesViaRawChatCompletions(
|
||||
writeOpenAIResponsesFallbackError(c, http.StatusBadRequest, "invalid_request_error", err.Error())
|
||||
return nil, fmt.Errorf("resolve responses tools: %w", err)
|
||||
}
|
||||
billingModel := resolveOpenAIForwardModel(account, originalModel, "")
|
||||
upstreamModel := normalizeOpenAIModelForUpstream(account, billingModel)
|
||||
if err := validateGPT61CompatRequest(body, upstreamModel); err != nil {
|
||||
writeOpenAIResponsesFallbackError(c, http.StatusBadRequest, "invalid_request_error", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
if openai.RequiresResponsesForToolCalls(upstreamModel) && len(effectiveTools) > 0 {
|
||||
err := fmt.Errorf("%s requires Responses for tool calls; this account only supports Chat Completions", normalizeKnownOpenAICodexModel(upstreamModel))
|
||||
// A managed gateway can select another account. Do not commit an error or
|
||||
// attempt a lossy Chat conversion before the existing failover loop runs.
|
||||
// Direct/single-account callers have no selector and keep their JSON 400.
|
||||
if s.accountRepo != nil {
|
||||
return nil, &UpstreamFailoverError{
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Stage: GatewayFailureStageRequestCompatibility,
|
||||
Scope: GatewayFailureScopeRequest,
|
||||
Reason: OpenAIResponsesToolsUnsupportedReason,
|
||||
NextAccountAction: NextAccountRetry,
|
||||
ClientStatusCode: http.StatusBadRequest,
|
||||
ClientMessage: err.Error(),
|
||||
}
|
||||
}
|
||||
writeOpenAIResponsesFallbackError(c, http.StatusBadRequest, "invalid_request_error", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
customTools := apicompat.CustomToolNames(effectiveTools)
|
||||
functionTools := apicompat.FunctionToolNames(effectiveTools)
|
||||
toolSearch := apicompat.HasToolSearchTool(effectiveTools)
|
||||
@@ -69,17 +96,6 @@ func (s *OpenAIGatewayService) forwardResponsesViaRawChatCompletions(
|
||||
return nil, fmt.Errorf("convert responses to chat completions: %w", err)
|
||||
}
|
||||
|
||||
billingModel := resolveOpenAIForwardModel(account, originalModel, "")
|
||||
upstreamModel := normalizeOpenAIModelForUpstream(account, billingModel)
|
||||
if err := validateGPT61CompatRequest(body, upstreamModel); err != nil {
|
||||
writeOpenAIResponsesFallbackError(c, http.StatusBadRequest, "invalid_request_error", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
if openai.RequiresResponsesForToolCalls(upstreamModel) && len(effectiveTools) > 0 {
|
||||
err := fmt.Errorf("%s requires Responses for tool calls; this account only supports Chat Completions", normalizeKnownOpenAICodexModel(upstreamModel))
|
||||
writeOpenAIResponsesFallbackError(c, http.StatusBadRequest, "invalid_request_error", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
reasoningEffort := extractOpenAIReasoningEffortFromBody(body, upstreamModel, billingModel, originalModel)
|
||||
// 国产模型默认 effort 补充:需要 mappedModel 判定,推迟到 billingModel 算出之后。
|
||||
reasoningEffort = ApplyThinkingEnabledFallback(reasoningEffort, body, billingModel)
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
//go:build unit
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestResponsesSolToolsCapabilityFailover(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
for _, tools := range []struct{ name, fields string }{
|
||||
{"function", `"input":"hello","tools":[{"type":"function","name":"lookup","parameters":{"type":"object"}}]`},
|
||||
{"custom", `"input":"hello","tools":[{"type":"custom","name":"exec"}]`},
|
||||
{"namespace", `"input":"hello","tools":[{"type":"namespace","name":"shell","tools":[{"type":"function","name":"pwd","parameters":{"type":"object"}}]}]`},
|
||||
{"additional", `"input":[{"type":"additional_tools","tools":[{"type":"function","name":"lookup","parameters":{"type":"object"}}]},{"role":"user","content":"hello"}]`},
|
||||
{"native", `"input":"hello","tools":[{"type":"computer_use_preview","display_width":1024,"display_height":768,"environment":"browser"}]`},
|
||||
} {
|
||||
for _, stream := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("%s/stream=%t", tools.name, stream), func(t *testing.T) {
|
||||
body := fmt.Sprintf(`{"model":"public-alias","stream":%t,%s}`, stream, tools.fields)
|
||||
c, rec := newSolToolsFallbackContext(body)
|
||||
account := forceChatResponsesFallbackAccount()
|
||||
account.Credentials["model_mapping"] = map[string]any{"public-alias": "gpt-6.1-sol"}
|
||||
upstream := &httpUpstreamRecorder{}
|
||||
svc := &OpenAIGatewayService{
|
||||
cfg: rawChatCompletionsTestConfig(), accountRepo: &accountRepoStub{}, httpUpstream: upstream,
|
||||
}
|
||||
|
||||
result, err := svc.forwardResponsesViaRawChatCompletions(context.Background(), c, account, []byte(body), time.Now())
|
||||
|
||||
require.Nil(t, result)
|
||||
var failover *UpstreamFailoverError
|
||||
require.ErrorAs(t, err, &failover)
|
||||
require.True(t, failover.ShouldRetryNextAccount())
|
||||
require.False(t, failover.RetryableOnSameAccount)
|
||||
require.False(t, failover.ShouldReportAccountScheduleFailure())
|
||||
_, _, healthFailure := classifyOpenAIAPIKeyHealthFailure(failover)
|
||||
require.False(t, healthFailure)
|
||||
require.False(t, c.Writer.Written(), "another account must still be able to answer")
|
||||
require.Empty(t, rec.Body.String())
|
||||
require.Empty(t, upstream.requests, "the incompatible account must never be called")
|
||||
require.Equal(t, "gpt-6.1-sol", account.Credentials["model_mapping"].(map[string]any)["public-alias"])
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponsesInvalidReasoningDoesNotFailover(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
for _, tc := range []struct{ model, effort string }{
|
||||
{"gpt-6.1-sol", "none"},
|
||||
{"gpt-6.1-terra", "minimal"},
|
||||
} {
|
||||
t.Run(tc.model, func(t *testing.T) {
|
||||
body := fmt.Sprintf(`{"model":"public-alias","input":"hello","reasoning":{"effort":%q},"tools":[{"type":"function","name":"lookup","parameters":{"type":"object"}}]}`, tc.effort)
|
||||
c, rec := newSolToolsFallbackContext(body)
|
||||
account := forceChatResponsesFallbackAccount()
|
||||
account.Credentials["model_mapping"] = map[string]any{"public-alias": tc.model}
|
||||
upstream := &httpUpstreamRecorder{}
|
||||
svc := &OpenAIGatewayService{cfg: rawChatCompletionsTestConfig(), accountRepo: &accountRepoStub{}, httpUpstream: upstream}
|
||||
|
||||
_, err := svc.forwardResponsesViaRawChatCompletions(context.Background(), c, account, []byte(body), time.Now())
|
||||
|
||||
var failover *UpstreamFailoverError
|
||||
require.ErrorContains(t, err, tc.model+" does not support reasoning effort")
|
||||
require.False(t, errors.As(err, &failover))
|
||||
require.Equal(t, http.StatusBadRequest, rec.Code)
|
||||
require.Empty(t, upstream.requests)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponsesTerraToolsCapabilityFailover(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
body := "{\"model\":\"public-alias\",\"input\":\"hello\",\"tools\":[{\"type\":\"function\",\"name\":\"lookup\",\"parameters\":{\"type\":\"object\"}}]}"
|
||||
c, rec := newSolToolsFallbackContext(body)
|
||||
account := forceChatResponsesFallbackAccount()
|
||||
account.Credentials["model_mapping"] = map[string]any{"public-alias": "gpt-6.1-terra"}
|
||||
upstream := &httpUpstreamRecorder{}
|
||||
svc := &OpenAIGatewayService{
|
||||
cfg: rawChatCompletionsTestConfig(), accountRepo: &accountRepoStub{}, httpUpstream: upstream,
|
||||
}
|
||||
|
||||
_, err := svc.forwardResponsesViaRawChatCompletions(context.Background(), c, account, []byte(body), time.Now())
|
||||
|
||||
var failover *UpstreamFailoverError
|
||||
require.ErrorAs(t, err, &failover)
|
||||
require.Equal(t, OpenAIResponsesToolsUnsupportedReason, failover.Reason)
|
||||
require.True(t, failover.ShouldRetryNextAccount())
|
||||
require.False(t, failover.ShouldReportAccountScheduleFailure())
|
||||
require.Contains(t, failover.ClientMessage, "gpt-6.1-terra")
|
||||
require.False(t, c.Writer.Written())
|
||||
require.Empty(t, rec.Body.String())
|
||||
require.Empty(t, upstream.requests)
|
||||
}
|
||||
|
||||
func TestResponsesSolToolsWithoutSelectorStillReturns400(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
body := `{"model":"gpt-6.1-sol","input":"hello","tools":[{"type":"function","name":"lookup","parameters":{"type":"object"}}]}`
|
||||
c, rec := newSolToolsFallbackContext(body)
|
||||
upstream := &httpUpstreamRecorder{}
|
||||
svc := &OpenAIGatewayService{cfg: rawChatCompletionsTestConfig(), httpUpstream: upstream}
|
||||
|
||||
result, err := svc.forwardResponsesViaRawChatCompletions(context.Background(), c, forceChatResponsesFallbackAccount(), []byte(body), time.Now())
|
||||
|
||||
var failover *UpstreamFailoverError
|
||||
require.Nil(t, result)
|
||||
require.Error(t, err)
|
||||
require.False(t, errors.As(err, &failover))
|
||||
require.Equal(t, http.StatusBadRequest, rec.Code)
|
||||
require.Contains(t, rec.Body.String(), "gpt-6.1-sol requires Responses for tool calls")
|
||||
require.Empty(t, upstream.requests)
|
||||
}
|
||||
|
||||
func newSolToolsFallbackContext(body string) (*gin.Context, *httptest.ResponseRecorder) {
|
||||
rec := httptest.NewRecorder()
|
||||
c, _ := gin.CreateTestContext(rec)
|
||||
c.Request = httptest.NewRequest(http.MethodPost, "/v1/responses", strings.NewReader(body))
|
||||
return c, rec
|
||||
}
|
||||
Reference in new issue
Block a user