Skip to content

Commit 86085f1

Browse files
authored
Update getting-started.mdx
1 parent b06c9d0 commit 86085f1

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

src/content/docs/realtime/agents/getting-started.mdx

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description: Deploy your first Realtime Agent using the CLI.
1111

1212
import { Render, PackageManagers, WranglerConfig, TypeScriptExample } from "~/components";
1313

14-
This guide will instruct you through setting up and deploying your first Realtime Agents project. You will use [Workers](/workers/), the [Realtime Agents SDK](TODO), a Workers AI binding, and a large language model (LLM) to deploy your first AI-powered application on the Cloudflare global network.
14+
This guide will instruct you through setting up and deploying your first Realtime Agents project. You will use [Workers](/workers/), the Realtime Agents SDK, a Workers AI binding, and a large language model (LLM) to deploy your first AI-powered application on the Cloudflare global network.
1515

1616
<Render file="prereqs" product="workers" />
1717

@@ -76,9 +76,9 @@ Update the `index.ts` file in your `hello-agent` application directory with the
7676
<TypeScriptExample filename="index.ts">
7777

7878
```ts
79-
import { DeepgramSTT, TextProcessor, Meeting, ElevenLabsTTS, ArtificialObject } from '@cloudflare/realtime-agents';
79+
import { DeepgramSTT, TextComponent, RealtimeKitTransport, ElevenLabsTTS, ArtificialObject } from '@cloudflare/realtime-agents';
8080

81-
class MyTextProcessor extends TextProcessor {
81+
class MyTextProcessor extends TextComponent {
8282
env: Env;
8383

8484
constructor(env: Env) {
@@ -90,7 +90,7 @@ class MyTextProcessor extends TextProcessor {
9090
const { response } = await this.env.AI.run('@cf/meta/llama-3.1-8b-instruct', {
9191
prompt: text,
9292
});
93-
reply(response);
93+
reply(response!);
9494
}
9595
}
9696

@@ -99,11 +99,11 @@ export class RoomObject extends ArtificialObject<Env> {
9999
super(ctx, env);
100100
}
101101

102-
async init(meetingId: string, authToken: string, workerUrl: string) {
102+
async init(meetingId: string, authToken: string, workerUrl: string, accountId: string, apiToken: string) {
103103
// Construct your text processor for generating responses to text
104104
const textProcessor = new MyTextProcessor(this.env);
105105
// Construct a Meeting object to join the RTK meeting
106-
const meeting = await Meeting.init(meetingId, authToken, [
106+
const meeting = new RealtimeKitTransport(meetingId, authToken, [
107107
{
108108
media_kind: 'audio',
109109
stream_kind: 'webcam',
@@ -118,6 +118,8 @@ export class RoomObject extends ArtificialObject<Env> {
118118
[meeting, new DeepgramSTT(this.env.DEEPGRAM_API_KEY), textProcessor, new ElevenLabsTTS(this.env.ELEVENLABS_API_KEY), meeting],
119119
meetingId,
120120
workerUrl,
121+
accountId,
122+
apiToken,
121123
);
122124

123125
// The RTK meeting object is accessible to us, so we can register handlers
@@ -165,7 +167,7 @@ export default {
165167
}
166168

167169
// We just need the part after `Bearer `
168-
await stub.init(meetingId, authHeader.split(' ')[1], url.host);
170+
await stub.init(meetingId, authHeader.split(' ')[1], url.host, env.ACCOUNT_ID, env.API_TOKEN);
169171

170172
return new Response(null, { status: 200 });
171173
case '/deinit':
@@ -189,9 +191,33 @@ The Realtime Agents SDK provides several elements that work together to create a
189191

190192
- `ElevenLabsTTS`: Converts the generated responses to audio to be spoken in the meeting
191193

192-
We use all of these elements together to create a simple chatbot-like pipeline. As a pre-requisite, we require the meeting ID to be joined along with an authorization token for joining the meeting, which is passed during the worker invocation
194+
We use all of these elements together to create a simple chatbot-like pipeline. As a pre-requisite, we require the meeting ID to be joined along with an authorization token for joining the meeting, which is passed during the worker invocation. Additionally, our class must extend `ArtificialObject` as it contains certain internal logic to handle interactions with our pipeline backend
193195

194-
Additionally, our class must extend `ArtificialObject` as it contains certain internal logic to handle interactions with our pipeline backend
196+
In `wrangler.jsonc`, append the following fields to enable the [Node.js Compatibility](https://developers.cloudflare.com/workers/runtime-apis/nodejs/) flag and create our Durable Object:
197+
198+
```json
199+
"compatibility_flags": ["nodejs_compat"],
200+
"migrations": [
201+
{
202+
"new_sqlite_classes": ["RoomObject"],
203+
"tag": "v1",
204+
},
205+
],
206+
"durable_objects": {
207+
"bindings": [
208+
{
209+
"class_name": "RoomObject",
210+
"name": "ROOM_OBJECT",
211+
},
212+
],
213+
},
214+
```
215+
216+
You must also setup a few [secrets](https://developers.cloudflare.com/workers/configuration/secrets/):
217+
218+
- `ACCOUNT_ID`: Your Cloudflare account ID
219+
- `API_TOKEN`: Cloudflare API token scoped for `Admin` access to `Realtime`
220+
- `ELEVENLABS_API_KEY`, `DEEPGRAM_API_KEY`: ElevenLabs & Deepgram API keys
195221

196222
## 5. Deploy your AI Worker
197223

0 commit comments

Comments
 (0)