shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

[Task][AI Proxy] Establish initial layered contracts with a runnable OpenAI path

Open hengyuss opened this issue 2 months ago • 5 comments

[Task][AI Proxy] Establish initial layered contracts with a runnable OpenAI path

Parent issue: #7351

Scope update

This task now establishes the initial contracts from a minimal runnable Protocol–Provider–Transport vertical slice.

The original description attempted to define response conversion, streaming event models, usage, normalized errors, ShenYu SPI discovery, and the complete extension model before the layers had been exercised together. Those production-level capabilities are deferred to the layer-specific follow-up issues.

Goal

Introduce the smallest coherent set of ShenYu-owned models and layer contracts, then validate their boundaries with one executable path:

OpenAI Chat request
      ↓
OpenAiChat Protocol
      ↓
OpenAi Provider
      ↓
WebClientAiProxyTransport
      ↓
raw AiUpstreamResponse

AiProxyEngine coordinates this path, but the existing AiProxyPlugin execution path must remain unchanged in this task.

Scope

Initial models

  • ShenyuAiRequest and message data required by the initial request path;
  • AiUpstreamRequest containing URI, method, headers, and raw body;
  • AiUpstreamResponse containing status, headers, and a reactive raw byte stream;
  • raw JSON payload retention so unknown client fields are not lost.

Initial contracts and registries

  • AiProxyProtocol for request matching and decoding;
  • AiProxyProvider for provider-specific upstream request construction;
  • AiProxyTransport for raw reactive HTTP execution;
  • explicit Protocol and Provider registries/factories;
  • Spring-managed implementation discovery for the initial version.

The contracts do not require ShenYu SPI. Their collection-based registry constructors keep discovery separate, so SPI can be introduced later without changing the Engine contract if a concrete need is demonstrated.

Initial implementations

  • OpenAI Chat request detection, validation, and decoding;
  • OpenAI endpoint, authentication, header, and request-field adaptation;
  • WebClient-based normal and streaming raw response transport;
  • AiProxyEngine request orchestration;
  • unit tests for the vertical slice and layer boundaries.

Out of scope

  • migrating AiProxyPlugin to AiProxyEngine;
  • normalized response, stream event, token usage, finish reason, or error models;
  • Protocol response decoding or client response encoding;
  • additional Protocols or Providers;
  • retry and fallback orchestration;
  • production timeout, proxy, TLS, connection-pool, and body-limit settings;
  • mandatory ShenYu SPI discovery.

Acceptance criteria

  • [ ] Initial models are owned by ShenYu and do not expose Spring AI clients or DTOs.
  • [ ] Unknown request fields are retained when no provider transformation is required.
  • [ ] Protocol, Provider, and Transport have independent contracts.
  • [ ] OpenAI Chat requests can be decoded and converted into an OpenAI upstream request.
  • [ ] Transport returns status, headers, and a reactive raw byte body for both normal and streaming responses.
  • [ ] Upstream 4xx/5xx status and bodies are returned as AiUpstreamResponse rather than discarded.
  • [ ] AiProxyEngine delegates the constructed request to Transport.
  • [ ] Unit tests cover registry lookup, request preservation and adaptation, Engine orchestration, streaming chunks, and error response forwarding.
  • [ ] Existing AiProxyPlugin behavior and constructor remain unchanged.

hengyuss avatar Sep 30 '26 09:09 hengyuss

👋 Hello @Aias00

A new issue has been opened by @hengyuss:

  • Title: [Task][AI Proxy] Define internal models and extension contracts
  • Link: https://github.com/apache/shenyu/issues/7381

Please review when you have time. Thank you! 🙏

github-actions[bot] avatar Sep 30 '26 09:09 github-actions[bot]

I would like to contribute to this foundation task. I will first map the current AI Proxy request/response/stream/error types and ShenYu SPI conventions, then propose a minimal package and model/interface shape before making code changes. Since this is the base task for the assigned parent #7351, please let me know if you would prefer a different boundary or API direction, or if this subtask is already being handled.

sunnysabor avatar Oct 01 '26 11:10 sunnysabor

Initial code inventory: OpenAiProtocolAdapter currently lives in shenyu-plugin-ai-common and imports Spring AI’s ChatCompletionRequest; AiProxyPlugin and AiProxyExecutorService also pass Spring AI types through, and the common module pulls in Spring AI dependencies. ShenYu SPI follows @SPI / @Join with ExtensionLoader. A clean provider-neutral boundary may need either a small shenyu-plugin-ai-api module for models/contracts, or moving the OpenAI adapter into ai-proxy so ai-common can become dependency-neutral. For #7381, do maintainers prefer a new API module or the latter refactor? I’ll hold the public contract shape until there is alignment.

sunnysabor avatar Oct 01 '26 11:10 sunnysabor

After reading the acceptance criteria across #7381–#7384, I recommend a small shenyu-plugin-ai-api module under shenyu-plugin-ai for the shared models and SPI contracts. Protocol, provider, and transport implementations must all consume these contracts, while shenyu-plugin-ai-common currently contains Spring AI-dependent implementation code; placing the new API there would keep the new boundary coupled to legacy DTO dependencies. The API module can depend only on ShenYu common/SPI primitives and JDK/Reactor types as needed, while retaining unknown payload data with Jackson JsonNode/raw JSON. I will prepare the contract-only change on that basis, without migrating the existing proxy path; please redirect me if maintainers prefer another module boundary.

sunnysabor avatar Oct 01 '26 11:10 sunnysabor

Completed by merged PR #7543, which explicitly imported the layered foundation from #7531 at source head 9b367b740d63ac71ac4aec51534547e15cce51a8. The merged implementation includes the ShenYu-owned request/upstream models, independent Protocol/Provider/Transport contracts and registries, the OpenAI Chat vertical slice, reactive raw responses, Engine delegation, and associated tests. #7531 is now closed as superseded because it has no remaining diff against master.

hengyuss avatar Oct 11 '26 09:10 hengyuss