🎨 兼容无返回值情况

This commit is contained in:
ronger 2023-10-08 16:26:15 +08:00
parent c493412066
commit 29fe0d2343
2 changed files with 6 additions and 3 deletions

View File

@ -328,7 +328,7 @@
<dependency> <dependency>
<groupId>com.theokanning.openai-gpt3-java</groupId> <groupId>com.theokanning.openai-gpt3-java</groupId>
<artifactId>client</artifactId> <artifactId>client</artifactId>
<version>0.14.0</version> <version>0.15.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.squareup.retrofit2</groupId> <groupId>com.squareup.retrofit2</groupId>
@ -439,7 +439,7 @@
<profileActive>dev</profileActive> <profileActive>dev</profileActive>
</properties> </properties>
<activation> <activation>
<activeByDefault>true</activeByDefault> <activeByDefault>false</activeByDefault>
</activation> </activation>
</profile> </profile>
<profile> <profile>
@ -448,7 +448,7 @@
<profileActive>prod</profileActive> <profileActive>prod</profileActive>
</properties> </properties>
<activation> <activation>
<activeByDefault>false</activeByDefault> <activeByDefault>true</activeByDefault>
</activation> </activation>
</profile> </profile>
</profiles> </profiles>

View File

@ -86,6 +86,9 @@ public class OpenAiController {
.build(); .build();
service.streamChatCompletion(completionRequest).doOnError(Throwable::printStackTrace) service.streamChatCompletion(completionRequest).doOnError(Throwable::printStackTrace)
.blockingForEach(chunk -> { .blockingForEach(chunk -> {
if (chunk.getChoices().isEmpty() || chunk.getChoices().get(0).getMessage() == null) {
return;
}
String text = chunk.getChoices().get(0).getMessage().getContent(); String text = chunk.getChoices().get(0).getMessage().getContent();
if (text == null) { if (text == null) {
return; return;