-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbasic.ts
33 lines (26 loc) · 839 Bytes
/
basic.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
import 'dotenv/config'
import { RealtimeClient } from 'openai-realtime-api'
/**
* Simple Node.js demo using the `RealtimeClient` which sends a text message and
* waits for a complete response.
*/
async function main() {
const client = new RealtimeClient({
debug: false,
sessionConfig: {
instructions:
'Please follow the instructions of any query you receive.\n' +
'Be concise in your responses. Speak quickly and answer shortly.',
turn_detection: null
}
})
await client.connect()
await client.waitForSessionCreated()
const text = 'How are you?'
console.log(text)
client.sendUserMessageContent([{ type: 'input_text', text }])
const event = await client.realtime.waitForNext('response.done')
console.log(JSON.stringify(event, null, 2))
client.disconnect()
}
await main()