Skip to content

Commit

Permalink
Merge pull request #19 from jxnl/clean-up-readme
Browse files Browse the repository at this point in the history
fix readme
  • Loading branch information
jxnl authored Jan 2, 2024
2 parents 3893e1a + c8ee6f7 commit 7e63838
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,32 @@ import OpenAI from "openai";

const UserSchema = z.object({
age: z.number(),
name: z.string().refine((name) => name.includes(" "), {
message: "Name must contain a space",
}),
});
name: z.string().refine(name => name.includes(" "), {
message: "Name must contain a space"
})
})

type User = z.infer<typeof UserSchema>;
type User = z.infer<typeof UserSchema>

const client = instruct.patch({
client: OpenAI(process.env.OPENAI_API_KEY, process.env.OPENAI_ORG_ID),
mode: instruct.MODES.TOOLS,
});
const oai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY ?? undefined,
organization: process.env.OPENAI_ORG_ID ?? undefined
})

const client = Instructor({
client: oai,
mode: "FUNCTIONS" // or TOOLS or MD_JSON or JSON_SCHEMA or JSON
})

const user: User = await client.chat.completions.create({
messages: [{ role: "user", content: "Jason Liu is 30 years old" }],
model: "gpt-3.5-turbo",
response_model: UserSchema,
max_retries: 3,
});
max_retries: 3
})

assert(user.age === 30)
assert(user.name === "Jason Liu")
```

Or if it makes more sense to you, you can use the builder pattern:
Expand Down

0 comments on commit 7e63838

Please sign in to comment.