-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4334ac1
commit b72ee8b
Showing
1 changed file
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,21 +26,37 @@ deno add jsr:@crosshatch/[email protected] | |
> Note: replace "X" with the latest beta version number. Version specificity will be unnecessary | ||
> upon the first stable release of `structured-outputs`. | ||
## Example | ||
## Example Usage | ||
|
||
### Declare Types | ||
|
||
```ts | ||
import { ResponseFormat, T } from "structured-outputs" | ||
import { T } from "structured-outputs" | ||
|
||
const Character = T.object({ | ||
name: T.string, | ||
age: T.number`Ensure between 1 and 110.`, | ||
home: T.string`The name of a fictional realm of magic and wonder.`, | ||
disposition: T.literalUnion("Optimistic", "Reserved", "Inquisitive"), | ||
}) | ||
``` | ||
|
||
### Create a `ResponseFormat` | ||
|
||
```ts | ||
// ... | ||
|
||
import { ResponseFormat } from "structured-outputs" | ||
|
||
const response_format = ResponseFormat("create_character", Character)` | ||
Create a character to be the protagonist of a children's story. | ||
` | ||
``` | ||
|
||
### Utilize The OpenAI Client | ||
|
||
```ts | ||
// ... | ||
|
||
const character = await openai.chat.completions | ||
.create({ | ||
|
@@ -49,6 +65,15 @@ const character = await openai.chat.completions | |
response_format, | ||
}) | ||
.then(response_format.parseFirstChoice) | ||
``` | ||
|
||
> Note: we chain off the resulting promise with a `then`, which applies the `ResponseFormat`'s | ||
> parser. | ||
### Utilize The Typed Object | ||
|
||
```ts | ||
// ... | ||
|
||
character satisfies { | ||
name: string | ||
|