Skip to content

Commit 93c5ae5

Browse files
Added documentation and release notes
1 parent c71ac25 commit 93c5ae5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

docs/guides/SPRING_AI_INTEGRATION.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- [Introduction](#introduction)
66
- [Orchestration Chat Completion](#orchestration-chat-completion)
77
- [Orchestration Masking](#orchestration-masking)
8+
- [Stream chat completion](#stream-chat-completion)
9+
- [Function Calling](#function-calling)
810

911
## Introduction
1012

@@ -99,3 +101,39 @@ Flux<String> responseFlux =
99101
_Note: A Spring endpoint can return `Flux` instead of `ResponseEntity`._
100102

101103
Please find [an example in our Spring Boot application](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOrchestrationService.java).
104+
105+
## Function Calling
106+
107+
First define a function that will be called by the LLM:
108+
109+
```java
110+
public class MockWeatherService implements Function<Request, Response> {
111+
public enum Unit {C, F}
112+
public record Request(String location, Unit unit) {}
113+
public record Response(double temp, Unit unit) {}
114+
115+
public Response apply(Request request) {
116+
return new Response(30.0, Unit.C);
117+
}
118+
}
119+
```
120+
121+
Then add your function to the options:
122+
123+
```java
124+
OrchestrationChatOptions options = new OrchestrationChatOptions(config);
125+
options.setFunctionCallbacks(
126+
List.of(
127+
FunctionCallback.builder()
128+
.function(
129+
"CurrentWeather", new MockWeatherService()) // (1) function name and instance
130+
.description("Get the weather in location") // (2) function description
131+
.inputType(MockWeatherService.Request.class) // (3) function input type
132+
.build()));
133+
Prompt prompt = new Prompt("What is the weather in Potsdam and in Toulouse?", options);
134+
135+
ChatResponse response = client.call(prompt);
136+
```
137+
138+
Please find [an example in our Spring Boot application](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiOrchestrationService.java).
139+

docs/release-notes/release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
### ✨ New Functionality
1414

1515
- [Add Orchestration `LlamaGuardFilter`](../guides/ORCHESTRATION_CHAT_COMPLETION.md#chat-completion-filter).
16+
- [Add Spring AI function calling](../guides/SPRING_AI_INTEGRATION.md#function-calling).
1617

1718
### 📈 Improvements
1819

0 commit comments

Comments
 (0)