spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

Add Filter for Modifying Response Body in OpenAiApi#chatCompletionStream

Open chaodongyue opened this issue 1 year ago • 0 comments

Expected Behavior

The OpenAiApi#chatCompletionStream method should provide a way to filter and modify the returned body before it is processed. This would allow developers to adapt responses from API providers that claim to be OpenAI-compatible but have partial deviations.

Current Behavior

Currently, the response from chatCompletionStream is directly processed using ModelOptionsUtils.jsonToObject(content, ChatCompletionChunk.class). However, some third-party API providers do not fully adhere to OpenAI's API response format, causing deserialization failures.

Context

This issue affects users integrating with third-party APIs that claim OpenAI compatibility but have subtle differences in response formatting.

A filtering mechanism would allow developers to preprocess the response body and adjust it before it is parsed into ChatCompletionChunk.

There are currently no known workarounds other than modifying the library code itself.

chaodongyue avatar Mar 07 '25 08:03 chaodongyue