Skip to content

Commit

Permalink
Update together.md to fix example code errors (#185)
Browse files Browse the repository at this point in the history
Co-authored-by: Dimitri Kennedy <[email protected]>
  • Loading branch information
dwcarr and roodboi authored Oct 19, 2024
1 parent 1ff06f6 commit c810a5c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions docs/blog/posts/together.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,43 @@ The good news is that Anyscale employs the same OpenAI client, and its models su
Let's explore one of the models available in Together's extensive collection!

```ts
import Instructor from "@/instructor"
import Instructor from "@instructor-ai/instructor"
import OpenAI from "openai"
import { z } from "zod"

const property = z.object({
name: z.string(),
value: z.string()
}).describe("A property defined by a name and value")
const property = z
.object({
name: z.string(),
value: z.string(),
})
.describe("A property defined by a name and value");

const UserSchema = z.object({
age: z.number(),
name: z.string(),
properties: z.array(property)
properties: z.array(property),
})

const oai = new OpenAI({
baseUrl='https://api.together.xyz',
baseURL: "https://api.together.xyz",
apiKey: process.env.TOGETHER_API_KEY ?? undefined,
})

const client = Instructor({
client: oai,
mode: "JSON_SCHEMA"
mode: "JSON_SCHEMA",
})

const user = await client.chat.completions.create({
messages: [{ role: "user", content: "Harry Potter" }],
model: "mistralai/Mixtral-8x7B-Instruct-v0.1",
response_model: { schema: UserSchema, name: "UserSchema" },
max_retries: 3
max_retries: 3,
})

console.log(user)
console.log(user);
/**
* {
{
age: 17,
name: "Harry Potter",
properties: [
Expand All @@ -82,7 +84,7 @@ console.log(user)
}
],
}
*/
**/
```

You can find more information about Togethers's output mode support [here](https://docs.together.ai/docs/json-mode/).

0 comments on commit c810a5c

Please sign in to comment.