Skip to content

Commit 698eab8

Browse files
committed
Fix maven dependency scope issue
1 parent bf2ce11 commit 698eab8

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

sample-code/spring-app/pom.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@
191191
<artifactId>jackson-module-jsonSchema</artifactId>
192192
<version>2.18.2</version>
193193
</dependency>
194-
<dependency>
195-
<groupId>io.vavr</groupId>
196-
<artifactId>vavr</artifactId>
197-
</dependency>
198194
</dependencies>
199195

200196
<build>
@@ -229,20 +225,6 @@
229225
<skipAddThirdParty>true</skipAddThirdParty>
230226
</configuration>
231227
</plugin>
232-
<plugin>
233-
<groupId>org.apache.maven.plugins</groupId>
234-
<artifactId>maven-dependency-plugin</artifactId>
235-
<executions>
236-
<execution>
237-
<id>analyze</id>
238-
<configuration>
239-
<ignoredDependencies>
240-
<ignoredDependency>com.fasterxml.jackson.core:jackson-core</ignoredDependency>
241-
</ignoredDependencies>
242-
</configuration>
243-
</execution>
244-
</executions>
245-
</plugin>
246228
</plugins>
247229
</build>
248230
</project>

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import static com.sap.ai.sdk.foundationmodels.openai.OpenAiModel.TEXT_EMBEDDING_3_SMALL;
66
import static com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionTool.ToolType.FUNCTION;
77

8+
import com.fasterxml.jackson.core.JsonProcessingException;
9+
import com.fasterxml.jackson.core.type.TypeReference;
10+
import com.fasterxml.jackson.databind.JsonMappingException;
811
import com.fasterxml.jackson.databind.ObjectMapper;
912
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator;
1013
import com.sap.ai.sdk.core.AiCoreService;
@@ -17,7 +20,6 @@
1720
import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatMessage;
1821
import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiEmbeddingOutput;
1922
import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiEmbeddingParameters;
20-
import io.vavr.control.Try;
2123
import java.util.ArrayList;
2224
import java.util.List;
2325
import java.util.Map;
@@ -128,13 +130,14 @@ public OpenAiChatCompletionOutput chatCompletionTools(final int months) {
128130
public OpenAiChatCompletionOutput chatCompletionToolExecution(
129131
@Nonnull final String location, @Nonnull final String unit) {
130132

131-
final var schemaMap =
132-
Try.of(() -> new JsonSchemaGenerator(JACKSON).generateSchema(WeatherMethod.Request.class))
133-
.map(schema -> JACKSON.convertValue(schema, Map.class))
134-
.getOrElseThrow(
135-
e ->
136-
new IllegalArgumentException(
137-
"Could not generate schema for WeatherMethod.Request", e));
133+
final var jsonSchemaGenerator = new JsonSchemaGenerator(JACKSON);
134+
Map<String, Object> schemaMap;
135+
try {
136+
final var schema = jsonSchemaGenerator.generateSchema(WeatherMethod.Request.class);
137+
schemaMap = JACKSON.convertValue(schema, new TypeReference<>() {});
138+
} catch (JsonMappingException e) {
139+
throw new IllegalArgumentException("Could not generate schema for WeatherMethod.Request", e);
140+
}
138141

139142
final var function =
140143
new OpenAiChatCompletionFunction()
@@ -163,7 +166,7 @@ public OpenAiChatCompletionOutput chatCompletionToolExecution(
163166
JACKSON.readValue(toolCall.getFunction().getArguments(), WeatherMethod.Request.class);
164167
final var toolResponse = new WeatherMethod().getCurrentWeather(weatherRequest);
165168
toolResponseJson = JACKSON.writeValueAsString(toolResponse);
166-
} catch (Exception e) {
169+
} catch (JsonProcessingException e) {
167170
throw new IllegalArgumentException("Error parsing tool call arguments", e);
168171
}
169172

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import static com.sap.ai.sdk.foundationmodels.openai.generated.model.ChatCompletionTool.TypeEnum.FUNCTION;
77

88
import com.fasterxml.jackson.core.JsonProcessingException;
9+
import com.fasterxml.jackson.core.type.TypeReference;
10+
import com.fasterxml.jackson.databind.JsonMappingException;
911
import com.fasterxml.jackson.databind.ObjectMapper;
1012
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator;
1113
import com.sap.ai.sdk.core.AiCoreService;
@@ -28,7 +30,6 @@
2830
import com.sap.ai.sdk.foundationmodels.openai.generated.model.CreateChatCompletionRequest;
2931
import com.sap.ai.sdk.foundationmodels.openai.generated.model.CreateChatCompletionResponse;
3032
import com.sap.ai.sdk.foundationmodels.openai.generated.model.FunctionObject;
31-
import io.vavr.control.Try;
3233
import java.util.List;
3334
import java.util.Map;
3435
import java.util.stream.Stream;
@@ -134,13 +135,14 @@ public OpenAiChatCompletionResponse chatCompletionTools(final int months) {
134135
public CreateChatCompletionResponse chatCompletionToolExecution(
135136
@Nonnull final String location, @Nonnull final String unit) {
136137

137-
final var schemaMap =
138-
Try.of(() -> new JsonSchemaGenerator(JACKSON).generateSchema(WeatherMethod.Request.class))
139-
.map(schema -> JACKSON.convertValue(schema, Map.class))
140-
.getOrElseThrow(
141-
e ->
142-
new IllegalArgumentException(
143-
"Could not generate schema for WeatherMethod.Request", e));
138+
final var jsonSchemaGenerator = new JsonSchemaGenerator(JACKSON);
139+
Map<String, Object> schemaMap;
140+
try {
141+
var schema = jsonSchemaGenerator.generateSchema(WeatherMethod.Request.class);
142+
schemaMap = JACKSON.convertValue(schema, new TypeReference<Map<String, Object>>() {});
143+
} catch (JsonMappingException e) {
144+
throw new IllegalArgumentException("Could not generate schema for WeatherMethod.Request", e);
145+
}
144146

145147
final var function =
146148
new FunctionObject()

0 commit comments

Comments
 (0)