Skip to content

Commit acf6674

Browse files
Raderluojun96
andauthored
feat: support reasoning in responses chat adapter (#1241)
Co-authored-by: Jun Luo <luojun96@live.cn>
1 parent e52e76a commit acf6674

20 files changed

Lines changed: 2978 additions & 64 deletions

.specs/aigateway-responses-api/aigateway_responses_api_v1.md

Lines changed: 572 additions & 0 deletions
Large diffs are not rendered by default.

.specs/aigateway-responses-api/responses-api-test-guide.md

Lines changed: 1116 additions & 0 deletions
Large diffs are not rendered by default.

aigateway/component/openai.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ func dbUpstreamsToConfigs(dbUpstreams []database.Upstream) []commontypes.Upstrea
813813
HealthCheckEnabled: u.HealthCheckEnabled,
814814
CircuitBreakerEnabled: u.CircuitBreakerEnabled,
815815
Tags: u.Tags,
816+
Metadata: u.Metadata,
816817
LimitPolicy: u.LimitPolicy,
817818
}
818819
// Carry health/circuit state from DB so the proxy path can use

aigateway/component/openai_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,3 +1484,23 @@ func TestOpenAIComponentImpl_RecordUsage_ExternalModel(t *testing.T) {
14841484
})
14851485
}
14861486
}
1487+
1488+
func TestDbUpstreamsToConfigsMetadataPassthrough(t *testing.T) {
1489+
metadata := map[string]any{
1490+
"responses": map[string]any{
1491+
"chat_adapter": map[string]any{
1492+
"reasoning_request": map[string]any{
1493+
"enabled": true,
1494+
},
1495+
},
1496+
},
1497+
}
1498+
result := dbUpstreamsToConfigs([]database.Upstream{{
1499+
ID: 1,
1500+
URL: "http://upstream.example.com/v1/chat/completions",
1501+
Enabled: true,
1502+
Metadata: metadata,
1503+
}})
1504+
require.Len(t, result, 1)
1505+
require.Equal(t, metadata, result[0].Metadata)
1506+
}

aigateway/handler/openai_responses_adapter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (h *OpenAIHandlerImpl) executeAdapterResponses(c *gin.Context, req *types.R
1616
writeResponsesError(c, http.StatusBadRequest, adapterErrorCode(err), "invalid_request_error", err.Error())
1717
return
1818
}
19-
chatReq, err := responsesToChatRequest(c.Request.Context(), req, modelTarget.ModelName)
19+
chatReq, err := responsesToChatRequest(c.Request.Context(), req, modelTarget.ModelName, modelTarget.Upstream.Metadata)
2020
if err != nil {
2121
writeResponsesError(c, http.StatusBadRequest, adapterErrorCode(err), "invalid_request_error", err.Error())
2222
return

0 commit comments

Comments
 (0)