-
Notifications
You must be signed in to change notification settings - Fork 0
/
vg-streaming-example.ts
51 lines (40 loc) · 1.41 KB
/
vg-streaming-example.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
interface EWSInteractModel {
agentId: string,
convoId: string,
bucket: "voiceglow-eu" | '(default)', // (default) is na region.
prompt?: string, // question for the ai
disableUiEngine?: boolean, // force disable ui engine
disableRecordHistory?: boolean, // force disable record history
agentData?: ChatRuntime, // optional replace agent variables on request
}
export interface EWSChunkModel {
type: 'chunk' | 'metadata',
chunk: string,
chunkIndex: number,
ui_engine?: boolean,
metadata?: EWSChunkMetadataModel
}
const ws = new WebSocket(`wss://vg-ws-edge.moeaymandev.workers.dev/ws`); //REPLACE WITH LIVE ONE..
ws.onopen = () => {
const interactObject: EWSInteractModel = {
agentId: "v72km4duyj1v4xg",
convoId: "anything_idk",
bucket: "voiceglow-eu", // can be either "voiceglow-eu" or "(default)" -> NA region
prompt: "Hi!!",
};
// init interact
ws.send(JSON.stringify(interactObject));
};
// listen for the stream
ws.onmessage = (event) => {
const eventData: EWSChunkModel = JSON.parse(event.data);
if (eventData.type === "chunk") {
console.log(`UIEngineEnabled: ${eventData.ui_engine} | Chunk: ${eventData.chunk}`)
console.log(eventData.chunk)
}
if (eventData.type === 'metadata') {
console.log("metadata chunk");
console.log(eventData.metadata);
return;
}
};