Skip to content

Commit 9ef8e6f

Browse files
committed
CI
1 parent 1662ae7 commit 9ef8e6f

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

sample-code/spring-app/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,18 @@
160160
</exclusion>
161161
</exclusions>
162162
</dependency>
163+
163164
<!-- scope "provided" -->
164165
<dependency>
165166
<groupId>org.projectlombok</groupId>
166167
<artifactId>lombok</artifactId>
167168
<scope>provided</scope>
168169
</dependency>
170+
<dependency>
171+
<groupId>com.fasterxml.jackson.core</groupId>
172+
<artifactId>jackson-core</artifactId>
173+
<scope>provided</scope>
174+
</dependency>
169175
<!-- scope "test" -->
170176
<dependency>
171177
<groupId>org.junit.jupiter</groupId>
@@ -181,6 +187,7 @@
181187
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
182188
<artifactId>cloudplatform-connectivity</artifactId>
183189
</dependency>
190+
184191
</dependencies>
185192

186193
<build>

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OpenAiService.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public long execute() {
127127
return fib(N);
128128
}
129129

130-
private static long fib(int n) {
130+
private static long fib(final int n) {
131131
if (n < 2) {
132132
return n;
133133
}
@@ -154,29 +154,31 @@ private static long fib(int n) {
154154
.setTools(List.of(tool))
155155
.setToolChoiceFunction("fibonacci");
156156

157-
OpenAiClient client = OpenAiClient.forModel(GPT_4O_MINI);
158-
var initialResponse = client.chatCompletion(request);
157+
final var client = OpenAiClient.forModel(GPT_4O_MINI);
158+
final var initialResponse = client.chatCompletion(request);
159159

160-
var toolCall = initialResponse.getChoices().get(0).getMessage().getToolCalls().get(0);
160+
final var toolCall = initialResponse.getChoices().get(0).getMessage().getToolCalls().get(0);
161161
String toolResponse;
162162
try {
163-
var fibonacci =
163+
final var fibonacci =
164164
new ObjectMapper().readValue(toolCall.getFunction().getArguments(), Fibonacci.class);
165165
toolResponse = String.valueOf(fibonacci.execute());
166166
} catch (Exception e) {
167167
throw new IllegalArgumentException("Error parsing tool call arguments", e);
168168
}
169169

170-
var assistantMessage = initialResponse.getChoices().get(0).getMessage();
170+
final var assistantMessage = initialResponse.getChoices().get(0).getMessage();
171171
messages.add(assistantMessage);
172172

173-
var toolMessage =
173+
final var toolMessage =
174174
new OpenAiChatMessage.OpenAiChatToolMessage()
175175
.setToolCallId(toolCall.getId())
176176
.setContent(toolResponse);
177177
messages.add(toolMessage);
178178

179-
var finalRequest = new OpenAiChatCompletionParameters().addMessages(messages.toArray(OpenAiChatMessage[]::new));
179+
final var finalRequest =
180+
new OpenAiChatCompletionParameters()
181+
.addMessages(messages.toArray(OpenAiChatMessage[]::new));
180182

181183
return client.chatCompletion(finalRequest);
182184
}

sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/services/OpenAiServiceV2.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ private static long fib(int n) {
167167

168168
OpenAiClient client = OpenAiClient.forModel(GPT_4O_MINI);
169169

170-
var initialResponse = client.chatCompletion(request);
170+
final var initialResponse = client.chatCompletion(request);
171171

172-
var toolCall = initialResponse.getChoices().get(0).getMessage().getToolCalls().get(0);
172+
final var toolCall = initialResponse.getChoices().get(0).getMessage().getToolCalls().get(0);
173173
String toolResponseContent;
174174
try {
175175
var fibonacci =
@@ -179,7 +179,7 @@ private static long fib(int n) {
179179
throw new IllegalArgumentException("Error parsing tool call arguments", e);
180180
}
181181

182-
var assistantMessage =
182+
final var assistantMessage =
183183
new ChatCompletionRequestAssistantMessage()
184184
.role(ChatCompletionRequestAssistantMessage.RoleEnum.ASSISTANT)
185185
.content(
@@ -188,7 +188,7 @@ private static long fib(int n) {
188188
.toolCalls(List.of(toolCall));
189189
request.addMessagesItem(assistantMessage);
190190

191-
var toolMessage =
191+
final var toolMessage =
192192
new ChatCompletionRequestToolMessage()
193193
.role(ChatCompletionRequestToolMessage.RoleEnum.TOOL)
194194
.content(ChatCompletionRequestToolMessageContent.create(toolResponseContent))

0 commit comments

Comments
 (0)