Skip to content

Commit c225e9c

Browse files
authored
Merge branch 'main' into orchestration/minor-syntax
2 parents 42a53f1 + dcc826d commit c225e9c

File tree

5 files changed

+388
-277
lines changed

5 files changed

+388
-277
lines changed

orchestration/src/main/java/com/sap/ai/sdk/orchestration/ConfigToRequestTransformer.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,29 @@ static TemplatingModuleConfig toTemplateModuleConfig(
5555
if (config instanceof TemplateRef) {
5656
return config;
5757
}
58+
5859
val template = config instanceof Template t ? t : Template.create().template();
5960
val messages = template.getTemplate();
6061
val messagesWithPrompt = new ArrayList<>(messages);
62+
6163
messagesWithPrompt.addAll(
6264
prompt.getMessages().stream().map(Message::createChatMessage).toList());
6365
if (messagesWithPrompt.isEmpty()) {
6466
throw new IllegalStateException(
6567
"A prompt is required. Pass at least one message or configure a template with messages or a template reference.");
6668
}
6769

68-
return Template.create()
69-
.template(messagesWithPrompt)
70-
.tools(template.getTools())
71-
.responseFormat(template.getResponseFormat());
70+
val result =
71+
Template.create()
72+
.template(messagesWithPrompt)
73+
.tools(template.getTools())
74+
.defaults(template.getDefaults())
75+
.responseFormat(template.getResponseFormat());
76+
77+
for (val customFieldName : template.getCustomFieldNames()) {
78+
result.setCustomField(customFieldName, template.getCustomField(customFieldName));
79+
}
80+
return result;
7281
}
7382

7483
@Nonnull

orchestration/src/test/java/com/sap/ai/sdk/orchestration/ConfigToRequestTransformerTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ void testMergingTemplateConfig() {
6262
List.of(
6363
systemMessage.createChatMessage(),
6464
userMessage.createChatMessage(),
65-
userMessage2.createChatMessage()));
65+
userMessage2.createChatMessage()))
66+
.defaults(Map.of("city", "Paris"));
67+
expected.setCustomField("country", "France");
6668

6769
var prompt = new OrchestrationPrompt(userMessage2);
6870
var templateConfig =
6971
Template.create()
70-
.template(List.of(systemMessage.createChatMessage(), userMessage.createChatMessage()));
72+
.template(List.of(systemMessage.createChatMessage(), userMessage.createChatMessage()))
73+
.defaults(Map.of("city", "Paris"));
74+
templateConfig.setCustomField("country", "France");
7175
var actual = ConfigToRequestTransformer.toTemplateModuleConfig(prompt, templateConfig);
7276

7377
assertThat(actual).isEqualTo(expected);

sample-code/spring-app/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
</developers>
3434
<properties>
3535
<project.rootdir>${project.basedir}/../../</project.rootdir>
36-
<spring-boot.version>3.4.1</spring-boot.version>
37-
<logback.version>1.5.17</logback.version>
36+
<spring-boot.version>3.4.3</spring-boot.version>
37+
<logback.version>1.5.18</logback.version>
3838
<cf-logging.version>3.8.4</cf-logging.version>
3939
<!-- Skip end-to-end tests by default, can be overridden with -DskipTests=false -->
4040
<skipTests>true</skipTests>

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,30 @@ Object messagesHistory(
8383
return response.getContent();
8484
}
8585

86+
@GetMapping("/image")
87+
@Nonnull
88+
Object imageInput(@RequestParam(value = "format", required = false) final String format) {
89+
final var response =
90+
service.imageInput(
91+
"https://upload.wikimedia.org/wikipedia/commons/thumb/5/59/SAP_2011_logo.svg/440px-SAP_2011_logo.svg.png");
92+
if ("json".equals(format)) {
93+
return response;
94+
}
95+
return response.getContent();
96+
}
97+
98+
@GetMapping("/multiString")
99+
@Nonnull
100+
Object multiStringInput(@RequestParam(value = "format", required = false) final String format) {
101+
final var response =
102+
service.multiStringInput(
103+
List.of("What is the capital of France?", "What is Chess about?", "What is 2+2?"));
104+
if ("json".equals(format)) {
105+
return response;
106+
}
107+
return response.getContent();
108+
}
109+
86110
@GetMapping("/inputFiltering/{policy}")
87111
@Nonnull
88112
Object inputFiltering(
@@ -203,30 +227,6 @@ Object groundingHelpSapCom(
203227
return response.getContent();
204228
}
205229

206-
@GetMapping("/image")
207-
@Nonnull
208-
Object imageInput(@RequestParam(value = "format", required = false) final String format) {
209-
final var response =
210-
service.imageInput(
211-
"https://upload.wikimedia.org/wikipedia/commons/thumb/5/59/SAP_2011_logo.svg/440px-SAP_2011_logo.svg.png");
212-
if ("json".equals(format)) {
213-
return response;
214-
}
215-
return response.getContent();
216-
}
217-
218-
@GetMapping("/multiString")
219-
@Nonnull
220-
Object multiStringInput(@RequestParam(value = "format", required = false) final String format) {
221-
final var response =
222-
service.multiStringInput(
223-
List.of("What is the capital of France?", "What is Chess about?", "What is 2+2?"));
224-
if ("json".equals(format)) {
225-
return response;
226-
}
227-
return response.getContent();
228-
}
229-
230230
@GetMapping("/responseFormatJsonSchema")
231231
@Nonnull
232232
Object responseFormatJsonSchema(

0 commit comments

Comments
 (0)