Skip to content

Commit

Permalink
Add to Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Nov 24, 2024
1 parent 4334ac1 commit b72ee8b
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down

0 comments on commit b72ee8b

Please sign in to comment.