diff --git a/src/main/java/org/mvnsearch/chatgpt/spring/client/ChatGPTServiceProxyFactory.java b/src/main/java/org/mvnsearch/chatgpt/spring/client/ChatGPTServiceProxyFactory.java index b477778..f4ea5fe 100644 --- a/src/main/java/org/mvnsearch/chatgpt/spring/client/ChatGPTServiceProxyFactory.java +++ b/src/main/java/org/mvnsearch/chatgpt/spring/client/ChatGPTServiceProxyFactory.java @@ -36,7 +36,6 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; -import java.util.function.Function; import java.util.stream.Stream; public class ChatGPTServiceProxyFactory { @@ -186,15 +185,14 @@ else if (!assistantMessage.isEmpty()) { request.setResponseFormat(ResponseFormat.jsonSchema(jsonSchema)); } if (isStructuredOutput) { - return chatGPTService.chat(request) - .map((Function) chatCompletionResponse -> { - try { - return chatCompletionResponse.getStructuredOutput(outputClass); - } - catch (Exception e) { - throw new RuntimeException(e); - } - }); + return chatGPTService.chat(request).handle((response, sink) -> { + try { + sink.next(response.getStructuredOutput(outputClass)); + } + catch (Exception e) { + sink.error(e); + } + }); } else { return chatGPTService.chat(request).map(ChatCompletionResponse::getReplyText);