Skip to content

Commit

Permalink
chore: add exception for structured output
Browse files Browse the repository at this point in the history
  • Loading branch information
linux-china committed Aug 9, 2024
1 parent 7a815ff commit 37b4763
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -186,15 +185,14 @@ else if (!assistantMessage.isEmpty()) {
request.setResponseFormat(ResponseFormat.jsonSchema(jsonSchema));
}
if (isStructuredOutput) {
return chatGPTService.chat(request)
.map((Function<ChatCompletionResponse, Object>) 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);
Expand Down

0 comments on commit 37b4763

Please sign in to comment.