Skip to content

Commit 93ec019

Browse files
committed
fix: prevent NPE
fix: do not use java21 features
1 parent 92b9422 commit 93ec019

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

model-providers/google/gemini/gemini-common/runtime/src/main/java/io/quarkiverse/langchain4j/gemini/common/GenerateContentResponseHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ public static String getText(GenerateContentResponse response) {
2020
}
2121

2222
StringBuilder text = new StringBuilder();
23-
List<GenerateContentResponse.Candidate.Part> parts = response.candidates().get(0).content().parts();
24-
if (parts != null && !parts.isEmpty()) {
25-
for (GenerateContentResponse.Candidate.Part part : parts) {
26-
text.append(part.text());
23+
if (response.candidates() != null && !response.candidates().isEmpty()) {
24+
if (response.candidates().get(0).content() != null) {
25+
List<GenerateContentResponse.Candidate.Part> parts = response.candidates().get(0).content().parts();
26+
if (parts != null && !parts.isEmpty()) {
27+
for (GenerateContentResponse.Candidate.Part part : parts) {
28+
text.append(part.text());
29+
}
30+
}
2731
}
2832
}
2933
return text.toString();

0 commit comments

Comments
 (0)