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: README.md
+38
Original file line number
Diff line number
Diff line change
@@ -173,6 +173,38 @@ console.log(await promptWithCalculator("What is 2 + 2?"));
173
173
174
174
We'll likely explore more specific APIs for tool- and function-calling in the future; follow along in [issue #7](https://github.com/webmachinelearning/prompt-api/issues/7).
175
175
176
+
### Structured output or JSON output
177
+
178
+
To help with programmatic processing of language model responses, the prompt API supports structured outputs defined by a JSON schema.
// Prompt the model and wait for the json response to come back.
197
+
constresult=awaitsession.prompt("Summarize this feedback into a rating between 0-5: "+
198
+
"The food was delicious, service was excellent, will recommend.",
199
+
{responseJSONSchema : responseJSONSchemaObj}
200
+
);
201
+
console.log(result);
202
+
```
203
+
204
+
The `responseJSONSchema` option for `prompt()` and `promptStreaming()` can also accept a JSON schema directly as a JavaScript object. This is particularly useful for cases where the schema is not reused for other prompts.
205
+
206
+
While processing the JSON schema, in cases where the user agent detects unsupported schema a `"NotSupportedError"``DOMException`, will be raised with appropriate error message. The result value returned is a string, that can be parsed with `JSON.parse()`. If the user agent is unable to produce a response that is compliant with the schema, a `"SyntaxError"``DOMException` will be raised.
207
+
176
208
### Configuration of per-session parameters
177
209
178
210
In addition to the `systemPrompt` and `initialPrompts` options shown above, the currently-configurable model parameters are [temperature](https://huggingface.co/blog/how-to-generate#sampling) and [top-K](https://huggingface.co/blog/how-to-generate#top-k-sampling). The `params()` API gives the default and maximum values for these parameters.
0 commit comments