Skip to content

Commit 3e69967

Browse files
committed
Fix tests
1 parent ca7fc25 commit 3e69967

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionRequest.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -301,29 +301,16 @@ public OpenAiChatCompletionRequest withToolChoice(@Nonnull final OpenAiToolChoic
301301
* @return the CreateChatCompletionRequest
302302
*/
303303
CreateChatCompletionRequest createCreateChatCompletionRequest() {
304-
final var toolsCombined = new ArrayList<ChatCompletionTool>();
305-
if (this.tools != null) {
306-
toolsCombined.addAll(this.tools);
307-
}
308-
if (this.toolsExecutable != null) {
309-
for (final OpenAiTool tool : this.toolsExecutable) {
310-
toolsCombined.add(tool.createChatCompletionTool());
311-
}
312-
}
313-
314304
final var request = new CreateChatCompletionRequest();
315-
for (final OpenAiMessage message : this.messages) {
316-
request.addMessagesItem(OpenAiUtils.createChatCompletionRequestMessage(message));
317-
}
318-
if (this.stop != null) {
319-
request.stop(CreateChatCompletionRequestAllOfStop.create(this.stop));
320-
}
321-
if (!toolsCombined.isEmpty()) {
322-
request.tools(toolsCombined);
323-
}
305+
this.messages.forEach(
306+
message ->
307+
request.addMessagesItem(OpenAiUtils.createChatCompletionRequestMessage(message)));
308+
309+
request.stop(this.stop != null ? CreateChatCompletionRequestAllOfStop.create(this.stop) : null);
324310

325311
request.temperature(this.temperature);
326312
request.topP(this.topP);
313+
327314
request.stream(null);
328315
request.maxTokens(this.maxTokens);
329316
request.maxCompletionTokens(this.maxCompletionTokens);
@@ -338,9 +325,24 @@ CreateChatCompletionRequest createCreateChatCompletionRequest() {
338325
request.seed(this.seed);
339326
request.streamOptions(this.streamOptions);
340327
request.responseFormat(this.responseFormat);
328+
request.tools(getChatCompletionTools());
341329
request.toolChoice(this.toolChoice);
342330
request.functionCall(null);
343331
request.functions(null);
344332
return request;
345333
}
334+
335+
@Nullable
336+
private List<ChatCompletionTool> getChatCompletionTools() {
337+
final var toolsCombined = new ArrayList<ChatCompletionTool>();
338+
if (this.tools != null) {
339+
toolsCombined.addAll(this.tools);
340+
}
341+
if (this.toolsExecutable != null) {
342+
for (final OpenAiTool tool : this.toolsExecutable) {
343+
toolsCombined.add(tool.createChatCompletionTool());
344+
}
345+
}
346+
return toolsCombined.isEmpty() ? null : toolsCombined;
347+
}
346348
}

0 commit comments

Comments
 (0)