eye-gu opened a new pull request, #6341: URL: https://github.com/apache/shenyu/pull/6341
<!-- Describe your PR here; e.g. Fixes #issueNo --> close #6340 Refactors the `ai-proxy` plugin to call upstream providers via `OpenAiApi` directly instead of Spring AI's `ChatClient`, ensuring responses conform to the standard OpenAI Chat Completions API format. ## Changes - **New:** `OpenAiProtocolAdapter` — parses raw request JSON into `ChatCompletionRequest`, preserving all fields (including `reasoning_content`) that Spring AI's `createRequest()` would lose. Also resolves `stream` flag from client request with admin config as fallback, and converts `max_completion_tokens` → `max_tokens` for compatibility. - **New:** `UpstreamErrorLogger` — shared utility to extract `WebClientResponseException` details for upstream error logging. - **Removed:** `ChatClientCache` — no longer needed since `OpenAiApi` instances are lightweight and stateless. - **Removed:** `FallbackStrategy` / `SimpleModelFallbackStrategy` — fallback is now handled inline with `OpenAiApi` directly. - **Removed:** `AiModelFactoryRegistry` dependency from the plugin — `OpenAiApi` is constructed directly from `AiCommonConfig` (baseUrl + apiKey). - **Streaming:** now emits `ChatCompletionChunk` SSE events + `data: [DONE]` terminator. - **Non-streaming:** returns `ChatCompletion` JSON directly. - **Retry:** non-streaming calls now use `Retry.backoff(3, 1s)` instead of `Retry.max(1)`. ## Testing - `OpenAiProtocolAdapterTest` — covers stream resolution, request parsing, field preservation, and fallback config merging. - Updated `AiProxyPluginTest`, `AiProxyExecutorServiceTest`, `CommonAiProxyApiKeyDataSubscriberTest` to match the new API. <!-- Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request. --> Make sure that: - [ ] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [ ] You submit test cases (unit or integration tests) that back your changes. - [ ] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
