Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update together.md to fix example code errors #185

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/).
Loading