-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
44 lines (37 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import OpenAI from "openai";
import wxflows from "@wxflows/sdk/openai";
import "dotenv/config";
(async () => {
const client = new OpenAI({
apiKey: process.env.OPENAI_APIKEY,
});
const toolClient = new wxflows({
endpoint: process.env.WXFLOWS_ENDPOINT,
apikey: process.env.WXFLOWS_APIKEY,
});
const messages = [
{
role: "system",
content:
"When using a GraphQL tool inly use fields that are available for the tool response type, dont try and use fields from other response types",
},
{
role: "user",
content: "Search information about the book escape from james patterson",
},
];
const tools = await toolClient.tools;
const chatCompletion = await client.chat.completions.create({
messages,
model: "gpt-4",
tools,
});
const toolMessages = await toolClient.executeTools(chatCompletion);
const newMessages = [...messages, ...toolMessages];
const chatCompleted = await client.chat.completions.create({
messages: newMessages,
model: "gpt-4",
tools,
});
console.log(JSON.stringify(chatCompleted));
})();