You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/ORCHESTRATION_CHAT_COMPLETION.md
+11-40Lines changed: 11 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -311,20 +311,12 @@ It is possible to set the response format for the chat completion. Available opt
311
311
Setting the response format to `JSON_OBJECT` tells the AI to respond with JSON, i.e., the response from the AI will be a string consisting of a valid JSON. This does, however, not guarantee that the response adheres to a specific structure (other than being valid JSON).
312
312
313
313
```java
314
-
var template =Message.user("What is 'apple' in German?");
var configWithTemplate = llmWithImageSupportConfig.withTemplateConfig(templatingConfig);
314
+
var configWithJsonResponse = config.withJsonResponse();
322
315
323
316
var prompt =
324
317
newOrchestrationPrompt(
325
-
Message.system(
326
-
"You are a language translator. Answer using the following JSON format: {\"language\": ..., \"translation\": ...}"));
327
-
var response = client.chatCompletion(prompt, configWithTemplate).getContent();
318
+
Message.user("Some message."), Message.system("Answer using JSON."));
319
+
var response = client.chatCompletion(prompt, configWithJsonResponse).getContent();
328
320
```
329
321
Note, that it is necessary to tell the AI model to actually return a JSON object in the prompt. The result might not adhere exactly to the given JSON format, but it will be a JSON object.
330
322
@@ -334,38 +326,17 @@ Note, that it is necessary to tell the AI model to actually return a JSON object
334
326
If you want the response to not only consist of valid JSON but additionally adhere to a specific JSON schema, you can use `JSON_SCHEMA`. in order to do that, add a JSON schema to the configuration as shown below and the response will adhere to the given schema.
335
327
336
328
```java
337
-
var template =Message.user("Whats '%s' in German?".formatted(word));
338
329
var schema =
339
-
Map.of(
340
-
"type",
341
-
"object",
342
-
"properties",
343
-
Map.of(
344
-
"language", Map.of("type", "string"),
345
-
"translation", Map.of("type", "string")),
346
-
"required",
347
-
List.of("language", "translation"),
348
-
"additionalProperties",
349
-
false);
350
-
351
-
// Note, that we plan to add more convenient ways to add a JSON schema in the future.
var response = client.chatCompletion(prompt, configWithTemplate).getContent();
368
338
```
339
+
Note, that the LLM will only exactly adhere to the given schema if you use `withStrict(true)`. Not all schemas are possible for OpenAI in strict mode. See [here](https://platform.openai.com/docs/guides/structured-outputs#supported-schemas) for more information.
369
340
370
341
Please find [an example in our Spring Boot application](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OrchestrationService.java)
Copy file name to clipboardExpand all lines: docs/release-notes/release_notes.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@
12
12
13
13
### ✨ New Functionality
14
14
15
-
-
15
+
-[Add new convenient methods to set the response format for Orchestration.](https://github.com/SAP/ai-sdk-java/tree/main/docs/guides/ORCHESTRATION_CHAT_COMPLETION.md#set-a-response-format)
0 commit comments