Skip to content

Commit 95409ae

Browse files
authored
Change tool_calls to camelCase (#176)
Co-authored-by: Jonas Israel <[email protected]>
1 parent 6bf9b60 commit 95409ae

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class OpenAiChatAssistantMessage implements OpenAiChatMessage {
250250
/** The tool calls generated by the model, such as function calls. */
251251
@JsonProperty("tool_calls")
252252
@Getter(onMethod_ = @Nullable)
253-
private List<OpenAiChatToolCall> tool_calls;
253+
private List<OpenAiChatToolCall> toolCalls;
254254

255255
// TODO: add context
256256
// https://github.com/Azure/azure-rest-api-specs/blob/07d286359f828bbc7901e86288a5d62b48ae2052/specification/cognitiveservices/data-plane/AzureOpenAI/inference/stable/2024-02-01/inference.json#L1599
@@ -264,12 +264,11 @@ void addDelta(@Nonnull final OpenAiChatAssistantMessage delta) {
264264
content += delta.getContent();
265265
}
266266

267-
if (delta.getTool_calls() != null) {
268-
if (tool_calls == null) {
269-
tool_calls = new ArrayList<>();
267+
if (delta.getToolCalls() != null) {
268+
if (toolCalls == null) {
269+
toolCalls = new ArrayList<>();
270270
}
271-
// TODO: camel case
272-
tool_calls.addAll(delta.getTool_calls());
271+
toolCalls.addAll(delta.getToolCalls());
273272
}
274273
}
275274
}

foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void chatCompletion(@Nonnull final Callable<OpenAiChatCompletionOutput> request)
241241
.isEqualTo(
242242
"I'm an AI and cannot answer that question as beauty is subjective and varies from person to person.");
243243
assertThat(choice.getMessage().getRole()).isEqualTo("assistant");
244-
assertThat(choice.getMessage().getTool_calls()).isNull();
244+
assertThat(choice.getMessage().getToolCalls()).isNull();
245245

246246
OpenAiContentFilterPromptResults contentFilterResults = choice.getContentFilterResults();
247247
assertThat(contentFilterResults).isNotNull();
@@ -492,7 +492,7 @@ void streamChatCompletionDeltas() throws IOException {
492492
// the role is only defined in delta 1, but it defaults to "assistant" for all deltas
493493
assertThat(choices2.getMessage().getRole()).isEqualTo("assistant");
494494
assertThat(choices2.getMessage().getContent()).isEqualTo("Sure");
495-
assertThat(choices2.getMessage().getTool_calls()).isNull();
495+
assertThat(choices2.getMessage().getToolCalls()).isNull();
496496
final var filter2 = choices2.getContentFilterResults();
497497
assertFilter(filter2);
498498

@@ -505,7 +505,7 @@ void streamChatCompletionDeltas() throws IOException {
505505
// the role is only defined in delta 1, but it defaults to "assistant" for all deltas
506506
assertThat(delta4Choice.getMessage().getRole()).isEqualTo("assistant");
507507
assertThat(delta4Choice.getMessage().getContent()).isNull();
508-
assertThat(delta4Choice.getMessage().getTool_calls()).isNull();
508+
assertThat(delta4Choice.getMessage().getToolCalls()).isNull();
509509
assertThat(totalOutput.getChoices()).hasSize(1);
510510
final var choice = totalOutput.getChoices().get(0);
511511
assertThat(choice.getFinishReason()).isEqualTo("stop");
@@ -514,7 +514,7 @@ void streamChatCompletionDeltas() throws IOException {
514514
assertThat(choice.getMessage()).isNotNull();
515515
assertThat(choice.getMessage().getRole()).isEqualTo("assistant");
516516
assertThat(choice.getMessage().getContent()).isEqualTo("Sure!");
517-
assertThat(choice.getMessage().getTool_calls()).isNull();
517+
assertThat(choice.getMessage().getToolCalls()).isNull();
518518
assertThat(totalOutput.getId()).isEqualTo("chatcmpl-A16EvnkgEm6AdxY0NoOmGPjsJucQ1");
519519
assertThat(totalOutput.getCreated()).isEqualTo(1724825677);
520520
assertThat(totalOutput.getModel()).isEqualTo("gpt-35-turbo");

sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OpenAiTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void chatCompletionTools() {
6868

6969
final var message = completion.getChoices().get(0).getMessage();
7070
assertThat(message.getRole()).isEqualTo("assistant");
71-
assertThat(message.getTool_calls()).isNotNull();
72-
assertThat(message.getTool_calls().get(0).getFunction().getName()).isEqualTo("fibonacci");
71+
assertThat(message.getToolCalls()).isNotNull();
72+
assertThat(message.getToolCalls().get(0).getFunction().getName()).isEqualTo("fibonacci");
7373
}
7474

7575
@Test

0 commit comments

Comments
 (0)