forked from coze-dev/coze-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflow.ts
53 lines (47 loc) · 1.35 KB
/
workflow.ts
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
import assert from 'assert';
import { RoleType } from '@coze/api';
import { client, botId, workflowId } from './client.js';
async function streamWorkflow() {
assert(botId, 'botId is required');
assert(workflowId, 'workflowId is required');
const workflow = await client.workflows.runs.stream({
workflow_id: workflowId,
parameters: { norco: 'JavaScript' },
bot_id: botId,
});
for await (const event of workflow) {
console.log('event', event);
}
}
async function nonStreamWorkflow() {
assert(botId, 'botId is required');
assert(workflowId, 'workflowId is required');
const workflow = await client.workflows.runs.create({
workflow_id: workflowId,
parameters: { norco: 'JavaScript' },
bot_id: botId,
});
console.log('workflow', workflow);
}
async function chatWorkflow() {
assert(botId, 'botId is required');
assert(workflowId, 'workflowId is required');
const workflow = await client.workflows.chat.stream({
workflow_id: workflowId,
parameters: {},
bot_id: botId,
additional_messages: [
{
role: RoleType.User,
content: 'give me a joke',
content_type: 'text',
},
],
});
for await (const event of workflow) {
console.log('event', event);
}
}
streamWorkflow().catch(console.error);
nonStreamWorkflow().catch(console.error);
chatWorkflow().catch(console.error);