diff --git a/README.md b/README.md index 6d2d886a..7ef0db24 100644 --- a/README.md +++ b/README.md @@ -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; +type User = z.infer -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: