Skip to content

Commit 7d1ba19

Browse files
Green
1 parent 83491e4 commit 7d1ba19

File tree

5 files changed

+69
-37
lines changed

5 files changed

+69
-37
lines changed

orchestration/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
</developers>
3232
<properties>
3333
<project.rootdir>${project.basedir}/../</project.rootdir>
34-
<coverage.complexity>77%</coverage.complexity>
35-
<coverage.line>92%</coverage.line>
36-
<coverage.instruction>92%</coverage.instruction>
37-
<coverage.branch>70%</coverage.branch>
34+
<coverage.complexity>80%</coverage.complexity>
35+
<coverage.line>93%</coverage.line>
36+
<coverage.instruction>93%</coverage.instruction>
37+
<coverage.branch>73%</coverage.branch>
3838
<coverage.method>92%</coverage.method>
3939
<coverage.class>100%</coverage.class>
4040
</properties>

orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class OrchestrationChatOptions implements FunctionCallingOptions {
4949

5050
private List<FunctionCallback> functionCallbacks;
5151

52-
private Map<String, Object> toolContext;
52+
private Map<String, Object> toolContext = Map.of();
5353

5454
/**
5555
* Returns the model to use for the chat.
@@ -208,29 +208,23 @@ public void setFunctionCallbacks(@Nonnull final List<FunctionCallback> functionC
208208

209209
@Override
210210
public void setFunctions(@Nonnull final Set<String> functionNames) {
211-
this.functions = functionNames;
212-
val template =
213-
Objects.requireNonNullElse(
214-
(Template) config.getTemplateConfig(), Template.create().template());
215-
val tools =
216-
functionNames.stream()
217-
.map(
218-
functionName ->
219-
ChatCompletionTool.create()
220-
.type(TypeEnum.FUNCTION)
221-
.function(FunctionObject.create().name(functionName)))
222-
.toList();
223-
config = config.withTemplateConfig(template.tools(tools));
224-
}
225-
226-
@Nonnull
227-
@Override
228-
public Map<String, Object> getToolContext() {
229-
return toolContext;
211+
// val template =
212+
// Objects.requireNonNullElse(
213+
// (Template) config.getTemplateConfig(), Template.create().template());
214+
// val tools =
215+
// functionNames.stream()
216+
// .map(
217+
// functionName ->
218+
// ChatCompletionTool.create()
219+
// .type(TypeEnum.FUNCTION)
220+
// .function(FunctionObject.create().name(functionName)))
221+
// .toList();
222+
// config = config.withTemplateConfig(template.tools(tools));
223+
throw new UnsupportedOperationException("Not implemented yet");
230224
}
231225

232226
@Override
233227
public void setToolContext(@Nonnull final Map<String, Object> toolContext) {
234-
this.toolContext = toolContext;
228+
throw new UnsupportedOperationException("Not implemented yet");
235229
}
236230
}
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
11
package com.sap.ai.sdk.orchestration.spring;
22

3+
import javax.annotation.Nonnull;
34
import java.util.function.Function;
45

6+
/** Function for tool calls in Spring AI */
57
public class MockWeatherService
68
implements Function<MockWeatherService.Request, MockWeatherService.Response> {
79

10+
/** Unit of temperature */
811
public enum Unit {
12+
/** Celsius */
913
C,
14+
/** Fahrenheit */
1015
F
1116
}
1217

18+
/**
19+
* Request for the weather
20+
*
21+
* @param location the city
22+
* @param unit the unit of temperature
23+
*/
1324
public record Request(String location, Unit unit) {}
1425

26+
/**
27+
* Response for the weather
28+
*
29+
* @param temp the temperature
30+
* @param unit the unit of temperature
31+
*/
1532
public record Response(double temp, Unit unit) {}
1633

17-
public Response apply(Request request) {
34+
/**
35+
* Apply the function
36+
*
37+
* @param request the request
38+
* @return the response
39+
*/
40+
@Nonnull
41+
public Response apply(@Nonnull Request request) {
1842
return new Response(30.0, Unit.C);
1943
}
2044
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
import com.sap.cloud.sdk.cloudplatform.thread.ThreadContextExecutors;
66
import java.util.concurrent.Executor;
7-
import java.util.function.Function;
87
import javax.annotation.Nonnull;
9-
import org.springframework.context.annotation.Bean;
108
import org.springframework.context.annotation.Configuration;
11-
import org.springframework.context.annotation.Description;
129
import org.springframework.scheduling.annotation.Async;
1310
import org.springframework.scheduling.annotation.AsyncConfigurer;
1411
import org.springframework.scheduling.annotation.EnableAsync;
@@ -26,11 +23,4 @@ public class AsynchronousConfiguration implements AsyncConfigurer {
2623
public Executor getAsyncExecutor() {
2724
return ThreadContextExecutors.getExecutor();
2825
}
29-
30-
@Bean
31-
// GPT uses the description
32-
@Description("Get the weather in location")
33-
public Function<String, String> getWeather() {
34-
return location -> "The weather is sunny in " + location;
35-
}
3626
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,43 @@
33
import com.sap.ai.sdk.app.services.MockWeatherService.Request;
44
import com.sap.ai.sdk.app.services.MockWeatherService.Response;
55
import java.util.function.Function;
6+
import javax.annotation.Nonnull;
67

8+
/** Function for tool calls in Spring AI */
79
public class MockWeatherService implements Function<Request, Response> {
810

11+
/** Unit of temperature */
912
public enum Unit {
13+
/** Celsius */
1014
C,
15+
/** Fahrenheit */
1116
F
1217
}
1318

19+
/**
20+
* Request for the weather
21+
*
22+
* @param location the city
23+
* @param unit the unit of temperature
24+
*/
1425
public record Request(String location, Unit unit) {}
1526

27+
/**
28+
* Response for the weather
29+
*
30+
* @param temp the temperature
31+
* @param unit the unit of temperature
32+
*/
1633
public record Response(double temp, Unit unit) {}
1734

18-
public Response apply(Request request) {
35+
/**
36+
* Apply the function
37+
*
38+
* @param request the request
39+
* @return the response
40+
*/
41+
@Nonnull
42+
public Response apply(@Nonnull Request request) {
1943
return new Response(30.0, Unit.C);
2044
}
2145
}

0 commit comments

Comments
 (0)