@@ -35,41 +35,43 @@ The good news is that Anyscale employs the same OpenAI client, and its models su
35
35
Let's explore one of the models available in Together's extensive collection!
36
36
37
37
``` ts
38
- import Instructor from " @/instructor"
38
+ import Instructor from " @instructor-ai /instructor"
39
39
import OpenAI from " openai"
40
40
import { z } from " zod"
41
41
42
- const property = z .object ({
43
- name: z .string (),
44
- value: z .string ()
45
- }).describe (" A property defined by a name and value" )
42
+ const property = z
43
+ .object ({
44
+ name: z .string (),
45
+ value: z .string (),
46
+ })
47
+ .describe (" A property defined by a name and value" );
46
48
47
49
const UserSchema = z .object ({
48
50
age: z .number (),
49
51
name: z .string (),
50
- properties: z .array (property )
52
+ properties: z .array (property ),
51
53
})
52
54
53
55
const oai = new OpenAI ({
54
- baseUrl = ' https://api.together.xyz' ,
56
+ baseURL: " https://api.together.xyz" ,
55
57
apiKey: process .env .TOGETHER_API_KEY ?? undefined ,
56
58
})
57
59
58
60
const client = Instructor ({
59
61
client: oai ,
60
- mode: " JSON_SCHEMA"
62
+ mode: " JSON_SCHEMA" ,
61
63
})
62
64
63
65
const user = await client .chat .completions .create ({
64
66
messages: [{ role: " user" , content: " Harry Potter" }],
65
67
model: " mistralai/Mixtral-8x7B-Instruct-v0.1" ,
66
68
response_model: { schema: UserSchema , name: " UserSchema" },
67
- max_retries: 3
69
+ max_retries: 3 ,
68
70
})
69
71
70
- console .log (user )
72
+ console .log (user );
71
73
/**
72
- * {
74
+ {
73
75
age: 17,
74
76
name: "Harry Potter",
75
77
properties: [
@@ -82,7 +84,7 @@ console.log(user)
82
84
}
83
85
],
84
86
}
85
- */
87
+ ** /
86
88
```
87
89
88
90
You can find more information about Togethers's output mode support [ here] ( https://docs.together.ai/docs/json-mode/ ) .
0 commit comments