Skip to content

Commit a13b183

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main' into test/openai/tool-call-execute
2 parents 9ad7225 + dcc826d commit a13b183

File tree

4 files changed

+387
-275
lines changed

4 files changed

+387
-275
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,30 @@ static TemplatingModuleConfig toTemplateModuleConfig(
5151
if (config instanceof TemplateRef) {
5252
return config;
5353
}
54+
5455
val template = config instanceof Template t ? t : Template.create().template();
5556
val messages = template.getTemplate();
5657
val responseFormat = template.getResponseFormat();
5758
val messagesWithPrompt = new ArrayList<>(messages);
59+
5860
messagesWithPrompt.addAll(
5961
prompt.getMessages().stream().map(Message::createChatMessage).toList());
6062
if (messagesWithPrompt.isEmpty()) {
6163
throw new IllegalStateException(
6264
"A prompt is required. Pass at least one message or configure a template with messages or a template reference.");
6365
}
64-
return Template.create()
65-
.template(messagesWithPrompt)
66-
.tools(template.getTools())
67-
.responseFormat(responseFormat);
66+
67+
val result =
68+
Template.create()
69+
.template(messagesWithPrompt)
70+
.tools(template.getTools())
71+
.defaults(template.getDefaults())
72+
.responseFormat(responseFormat);
73+
74+
for (val customFieldName : template.getCustomFieldNames()) {
75+
result.setCustomField(customFieldName, template.getCustomField(customFieldName));
76+
}
77+
return result;
6878
}
6979

7080
@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/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)