Skip to content

Commit c53b04e

Browse files
committed
CI
1 parent 3038eb3 commit c53b04e

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
import static lombok.AccessLevel.NONE;
55
import static lombok.AccessLevel.PACKAGE;
66

7-
import com.fasterxml.jackson.core.JsonProcessingException;
87
import com.google.common.annotations.Beta;
98
import com.sap.ai.sdk.foundationmodels.openai.generated.model.CompletionUsage;
109
import com.sap.ai.sdk.foundationmodels.openai.generated.model.CreateChatCompletionResponse;
1110
import com.sap.ai.sdk.foundationmodels.openai.generated.model.CreateChatCompletionResponseChoicesInner;
12-
import java.util.ArrayList;
1311
import java.util.List;
1412
import java.util.Objects;
1513
import javax.annotation.Nonnull;
@@ -98,6 +96,4 @@ public OpenAiAssistantMessage getMessage() {
9896

9997
return new OpenAiAssistantMessage(new OpenAiMessageContent(contentItems), openAiToolCalls);
10098
}
101-
102-
10399
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
import lombok.AllArgsConstructor;
1919
import lombok.Data;
2020
import lombok.Getter;
21-
import lombok.Setter;
2221
import lombok.experimental.Accessors;
2322

2423
/**
2524
* Represents an OpenAI function tool that can be used to define a function call in an OpenAI Chat
2625
* Completion request. This tool generates a JSON schema based on the provided class representing
2726
* the function's request structure.
2827
*
28+
* @param <I> the type of the input argument for the function
2929
* @see <a href="https://platform.openai.com/docs/guides/gpt/function-calling"/>OpenAI Function
3030
* @since 1.7.0
3131
*/
@@ -43,13 +43,13 @@ public class OpenAiTool<I> {
4343
@Nonnull Class<I> requestClass;
4444

4545
/** An optional description of the function. */
46-
@Setter @Nullable String description;
46+
@Nullable String description;
4747

4848
/** An optional flag indicating whether the function parameters should be treated strictly. */
49-
@Setter @Nullable Boolean strict;
49+
@Nullable Boolean strict;
5050

5151
/** The function to be called. */
52-
@Setter @Nullable Function<I, ?> function;
52+
@Nullable Function<I, ?> function;
5353

5454
/**
5555
* Constructs an {@code OpenAiFunctionTool} with the specified name and a model class that
@@ -70,11 +70,6 @@ Object execute(@Nonnull final I argument) {
7070
return getFunction().apply(argument);
7171
}
7272

73-
public OpenAiTool<I> setCallback(Function<I, ?> function) {
74-
this.function = function;
75-
return this;
76-
}
77-
7873
ChatCompletionTool createChatCompletionTool() {
7974
final var objectMapper = new ObjectMapper();
8075
JsonSchema schema = null;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class OpenAiToolExecutor {
3131
*/
3232
@Nonnull
3333
public static List<OpenAiToolMessage> executeTools(
34-
List<OpenAiTool<?>> tools, List<OpenAiToolCall> toolCalls) {
34+
@Nonnull final List<OpenAiTool<?>> tools, @Nonnull final List<OpenAiToolCall> toolCalls) {
3535

3636
final var toolMap = tools.stream().collect(Collectors.toMap(OpenAiTool::getName, tool -> tool));
3737

@@ -41,15 +41,17 @@ public static List<OpenAiToolMessage> executeTools(
4141
.filter(functionCall -> toolMap.containsKey(functionCall.getName()))
4242
.map(
4343
functionCall -> {
44-
var tool = toolMap.get(functionCall.getName());
45-
var result = executeFunction(tool, functionCall);
44+
final var tool = toolMap.get(functionCall.getName());
45+
final var result = executeFunction(tool, functionCall);
4646
return OpenAiMessage.tool(serializeObject(result), functionCall.getId());
4747
})
4848
.toList();
4949
}
5050

51-
private static <I> Object executeFunction(OpenAiTool<I> tool, OpenAiFunctionCall toolCall) {
52-
I arguments = toolCall.getArgumentsAsObject(tool);
51+
@Nonnull
52+
private static <I> Object executeFunction(
53+
@Nonnull final OpenAiTool<I> tool, @Nonnull final OpenAiFunctionCall toolCall) {
54+
final I arguments = toolCall.getArgumentsAsObject(tool);
5355
return tool.execute(arguments);
5456
}
5557

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,12 @@ record DummyRequest(String param1, int param2) {}
145145
assertThat(toolA.getFunction().getParameters())
146146
.isEqualTo(
147147
Map.of(
148-
"id", "urn:jsonschema:com:sap:ai:sdk:foundationmodels:openai:OpenAiTool:1",
148+
"id",
149+
"urn:jsonschema:com:sap:ai:sdk:foundationmodels:openai:OpenAiChatCompletionRequestTest:1DummyRequest",
149150
"properties",
150151
Map.of(
151-
"type",
152-
Map.of(
153-
"id", "urn:jsonschema:java:lang:reflect:Type",
154-
"properties", Map.of("typeName", Map.of("type", "string")),
155-
"type", "object")),
152+
"param1", Map.of("type", "string"),
153+
"param2", Map.of("type", "integer")),
156154
"type", "object"));
157155
}
158156
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public OpenAiChatCompletionResponse chatCompletionToolExecution(
103103
List.of(
104104
new OpenAiTool<>("weather", WeatherMethod.Request.class)
105105
.setDescription("Get the weather for the given location")
106-
.setCallback(WeatherMethod::getCurrentWeather));
106+
.setFunction(WeatherMethod::getCurrentWeather));
107107

108108
// 2. Assistant calls the function
109109
final var request = new OpenAiChatCompletionRequest(messages).withOpenAiTools(tools);

0 commit comments

Comments
 (0)