-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.js
58 lines (46 loc) · 1.23 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { WatsonXAI } from "@ibm-cloud/watsonx-ai";
import wxflows from "@wxflows/sdk/watsonx";
import "dotenv/config";
(async () => {
process.env.IBM_CREDENTIALS_FILE = "./.env";
const client = WatsonXAI.newInstance({
version: "2024-05-31",
serviceUrl: process.env.WATSONX_AI_ENDPOINT,
});
const params = {
modelId: "mistralai/mistral-large",
projectId: process.env.WATSONX_AI_PROJECT_ID,
maxTokens: 100,
};
const toolClient = new wxflows({
endpoint: process.env.WXFLOWS_ENDPOINT,
apikey: process.env.WXFLOWS_APIKEY,
});
const messages = [
{
role: "user",
content: [
{
type: "text",
text: "Search information about the book escape from james patterson",
},
],
},
];
const tools = await toolClient.tools;
console.log({ tools })
const chatCompletion = await client.textChat({
messages,
tools,
...params,
});
const toolMessages = await toolClient.executeTools(chatCompletion);
console.log({ toolMessages })
const newMessages = [...messages, ...toolMessages];
const chatCompleted = await client.textChat({
messages: newMessages,
tools,
...params,
});
console.log(JSON.stringify(chatCompleted));
})();