@sap-ai-sdk/orchestration 1.8.1-20250217013122.0 → 1.8.1-20250218013110.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +53 -12
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -109,7 +109,6 @@ Optionally, define `model_version` (default: `latest`) and `model_params` for cu
109
109
 
110
110
  Use the orchestration client with templating to pass a prompt containing placeholders that will be replaced with input parameters during a chat completion request.
111
111
  This allows for variations in the prompt based on the input parameters.
112
- Set custom request configuration when calling `chatCompletion` function.
113
112
 
114
113
  ```ts
115
114
  import { OrchestrationClient } from '@sap-ai-sdk/orchestration';
@@ -131,26 +130,68 @@ const response = await orchestrationClient.chatCompletion({
131
130
  });
132
131
 
133
132
  const responseContent = response.getContent();
133
+ const finishReason = response.getFinishReason();
134
+ const tokenUsage = response.getTokenUsage();
134
135
  ```
135
136
 
136
- `getContent()` is a convenience method that parses the response and returns the model's output as a string.
137
+ You can use the following convenience methods for handling chat completion responses:
138
+
139
+ - `getContent()` parses the response and returns the model's output as a string.
140
+ - `getFinishReason()` retrieves the `finish_reason` explaining why chat completion request stopped.
141
+ - `getTokenUsage()` provides token usage details, including `total_tokens`, `prompt_tokens`, and `completion_tokens`.
142
+
143
+ #### Structured Outputs
144
+
145
+ Setting `response_format` under `templating` guarantees that the model's output aligns with the schema type specified by developers.
146
+ It is useful when the model is not calling a tool, but rather, responding to the user in a structured way.
137
147
 
138
- To retrieve the `finish_reason` for stopping the chat completion request, use the convenience method `getFinishReason()`:
148
+ The example below demonstrates how to use `response_format` to return a JSON Schema, with `strict: true` ensuring the outputs conform precisely to the schema.
139
149
 
140
150
  ```ts
141
- const finishReason = response.getFinishReason();
151
+ templating: {
152
+ template: [
153
+ { role: 'user', content: 'What is the capital of {{?country}}?' }
154
+ ],
155
+ response_format: {
156
+ type: 'json_schema',
157
+ json_schema: {
158
+ name: 'capital_response',
159
+ strict: true,
160
+ schema: {
161
+ type: 'object',
162
+ properties: {
163
+ country_name: {
164
+ type: "string",
165
+ description: "The name of the country provided by the user."
166
+ },
167
+ capital: {
168
+ type: "string",
169
+ description: "The capital city of the country."
170
+ }
171
+ },
172
+ required: ["country_name", "capital"]
173
+ }
174
+ }
175
+ }
176
+ }
142
177
  ```
143
178
 
144
- Use the `getTokenUsage()` convenience method to retrieve the token usage details of the chat completion request:
179
+ You can also initialize `json_schema` using a Zod schema, as shown below:
145
180
 
146
181
  ```ts
147
- const tokenUsage = response.getTokenUsage();
148
-
149
- console.log(
150
- `Total tokens consumed by the request: ${tokenUsage.total_tokens}\n` +
151
- `Input prompt tokens consumed: ${tokenUsage.prompt_tokens}\n` +
152
- `Output text completion tokens consumed: ${tokenUsage.completion_tokens}\n`
153
- );
182
+ const countryCapitalSchema = z.object({
183
+ country_name: z.string(),
184
+ capital: z.string()
185
+ }).strict();
186
+
187
+ response_format: {
188
+ type: 'json_schema',
189
+ json_schema: {
190
+ name: 'capital_response',
191
+ strict: true,
192
+ schema: zodToJsonSchema(countryCapitalSchema)
193
+ }
194
+ }
154
195
  ```
155
196
 
156
197
  ### Prompt Registry
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ai-sdk/orchestration",
3
- "version": "1.8.1-20250217013122.0",
3
+ "version": "1.8.1-20250218013110.0",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -21,8 +21,8 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "@sap-cloud-sdk/util": "^3.26.0",
24
- "@sap-ai-sdk/core": "^1.8.1-20250217013122.0",
25
- "@sap-ai-sdk/ai-api": "^1.8.1-20250217013122.0"
24
+ "@sap-ai-sdk/core": "^1.8.1-20250218013110.0",
25
+ "@sap-ai-sdk/ai-api": "^1.8.1-20250218013110.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@sap-cloud-sdk/http-client": "^3.26.0",