Skip to content

Commit e923f1d

Browse files
committed
update TODO list tutorial
1 parent 27a04ba commit e923f1d

4 files changed

Lines changed: 64 additions & 59 deletions

File tree

docs/pages/tutorial-ai-todo-list-copilot/step-1-checkout-repo.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ We'll begin by checking out the base code of the todo list app. We'll start from
66

77
```shell
88
git clone -b base-start-here https://github.com/CopilotKit/example-todos-app.git
9+
cd example-todos-app
910
```
1011

1112
## Install dependencies
@@ -27,4 +28,3 @@ npm run dev
2728
You should be able to go to [http://localhost:3000](http://localhost:3000) and see the todo list app. Feel free to play around with the app to get a feel for it.
2829

2930
Now, let's start adding some AI copilot superpowers to this app.
30-

docs/pages/tutorial-ai-todo-list-copilot/step-2-setup-copilotkit.mdx

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Callout } from "nextra/components"
1+
import { Callout } from "nextra/components";
22
import { TailoredExperience, LinkToCopilotCloud } from "@/components";
33
import SelfHostingCopilotRuntimeCreateEndpoint from "@/snippets/self-hosting-copilot-runtime-create-endpoint.mdx";
44
import SelfHostingCopilotRuntimeConfigureCopilotKitProvider from "@/snippets/self-hosting-copilot-runtime-configure-copilotkit-provider.mdx";
@@ -19,61 +19,63 @@ npm install @copilotkit/react-core @copilotkit/react-ui
1919
```
2020

2121
## Setup CopilotKit
22+
2223
<TailoredExperience.Toggle />
2324

2425
<TailoredExperience.CloudContent>
2526

26-
### Configure the `<CopilotKit />` Provider
27+
### Configure the `<CopilotKit />` Provider
2728

28-
The `<CopilotKit>` provider will wrap our app. Let's add it to the `page.tsx` file.
29+
The `<CopilotKit>` provider will wrap our app. Let's add it to the `page.tsx` file.
2930

3031
<Callout type="info">
3132
<LinkToCopilotCloud>Click here to get your Copilot Cloud API key for free</LinkToCopilotCloud>. Then, replace `<your-public-api-key>` with your actual API key.
3233
</Callout>
3334

34-
```tsx filename="app/page.tsx" showLineNumbers {5,9,13}
35-
"use client";
36-
37-
import { TasksList } from "@/components/TasksList";
38-
import { TasksProvider } from "@/lib/hooks/use-tasks";
39-
import { CopilotKit } from "@copilotkit/react-core";
40-
41-
export default function Home() {
42-
return (
43-
<CopilotKit publicApiKey={"<your-public-api-key>"}>
44-
<TasksProvider>
45-
<TasksList />
46-
</TasksProvider>
47-
</CopilotKit>
48-
);
49-
}
50-
```
35+
```tsx filename="app/page.tsx" showLineNumbers {5,9,13}
36+
"use client";
37+
38+
import { TasksList } from "@/components/TasksList";
39+
import { TasksProvider } from "@/lib/hooks/use-tasks";
40+
import { CopilotKit } from "@copilotkit/react-core";
41+
42+
export default function Home() {
43+
return (
44+
<CopilotKit publicApiKey={"<your-public-api-key>"}>
45+
<TasksProvider>
46+
<TasksList />
47+
</TasksProvider>
48+
</CopilotKit>
49+
);
50+
}
51+
```
52+
5153
</TailoredExperience.CloudContent>
5254

5355
<TailoredExperience.SelfHostContent>
5456
### Step 1: Set up Copilot Runtime Endpoint
5557

56-
<SelfHostingCopilotRuntimeCreateEndpoint />
58+
<SelfHostingCopilotRuntimeCreateEndpoint />
5759

58-
### Step 2: Configure the CopilotKit Provider
60+
### Step 2: Configure the CopilotKit Provider
5961

60-
```tsx filename="app/page.tsx" showLineNumbers {5,9,13}
61-
"use client";
62+
```tsx filename="app/page.tsx" showLineNumbers {5,9,13}
63+
"use client";
6264

63-
import { TasksList } from "@/components/TasksList";
64-
import { TasksProvider } from "@/lib/hooks/use-tasks";
65-
import { CopilotKit } from "@copilotkit/react-core";
65+
import { TasksList } from "@/components/TasksList";
66+
import { TasksProvider } from "@/lib/hooks/use-tasks";
67+
import { CopilotKit } from "@copilotkit/react-core";
6668

67-
export default function Home() {
68-
return (
69-
<CopilotKit runtimeUrl={"<your-runtime-url>"}>
70-
<TasksProvider>
71-
<TasksList />
72-
</TasksProvider>
73-
</CopilotKit>
74-
);
75-
}
76-
```
69+
export default function Home() {
70+
return (
71+
<CopilotKit runtimeUrl="/api/copilotkit">
72+
<TasksProvider>
73+
<TasksList />
74+
</TasksProvider>
75+
</CopilotKit>
76+
);
77+
}
78+
```
7779

7880
</TailoredExperience.SelfHostContent>
7981

@@ -94,7 +96,7 @@ import "@copilotkit/react-ui/styles.css";
9496

9597
export default function Home() {
9698
return (
97-
<CopilotKit ...>
99+
<CopilotKit runtimeUrl="/api/copilotkit">
98100
<TasksProvider>
99101
<TasksList />
100102
</TasksProvider>
@@ -113,4 +115,3 @@ Here's what we did:
113115
Now, head back to your app and you'll find a chat popup in the bottom right corner of the page. At this point, you can start interacting with your copilot! 🎉
114116

115117
In the next step, we'll make our assistant smarter by providing it with readable state about our todo list.
116-

docs/pages/tutorial-ai-todo-list-copilot/step-4-copilot-actions.mdx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Step 4: Copilot Actions
32

43
Now it's time to make our copilot even more useful by taking actions.
@@ -13,14 +12,14 @@ Essentially, we want our copilot to be able to call the `addTask`, `setTaskStatu
1312

1413
The [`useCopilotAction`](/reference/hooks/useCopilotAction) hook makes actions available to our copilot. Let's implement it in the [`lib/hooks/use-tasks.tsx`](https://github.com/CopilotKit/example-todos-app/blob/base-start-here/lib/hooks/use-tasks.tsx) file.
1514

16-
```tsx filename="libs/hooks/use-tasks.tsx" showLineNumbers {8-22,24-38,40-61}
15+
```tsx filename="libs/hooks/use-tasks.tsx" showLineNumbers {3-3,8-22,24-38,40-61}
1716
// ... the rest of the file
1817

19-
import { useCopilotReadable, useCopilotAction } from "@copilotkit/react";
18+
import { useCopilotReadable, useCopilotAction } from "@copilotkit/react-core";
2019

2120
export const TasksProvider = ({ children }: { children: ReactNode }) => {
2221
const [tasks, setTasks] = useState<Task[]>(defaultTasks);
23-
22+
2423
useCopilotAction({
2524
name: "addTask",
2625
description: "Adds a task to the todo list",
@@ -34,7 +33,7 @@ export const TasksProvider = ({ children }: { children: ReactNode }) => {
3433
],
3534
handler: ({ title }) => {
3635
addTask(title);
37-
}
36+
},
3837
});
3938

4039
useCopilotAction({
@@ -50,7 +49,7 @@ export const TasksProvider = ({ children }: { children: ReactNode }) => {
5049
],
5150
handler: ({ id }) => {
5251
deleteTask(id);
53-
}
52+
},
5453
});
5554

5655
useCopilotAction({
@@ -73,17 +72,15 @@ export const TasksProvider = ({ children }: { children: ReactNode }) => {
7372
],
7473
handler: ({ id, status }) => {
7574
setTaskStatus(id, status);
76-
}
75+
},
7776
});
7877

7978
// ... the rest of the file
80-
}
79+
};
8180
```
8281

8382
The `useCopilotAction` hook is a powerful hook that allows us to register actions with our copilot. It takes an object with the following properties:
8483

85-
86-
8784
- `name` is the name of the action.
8885
- `description` is a description of the action. It's important to choose a good description so that our copilot can choose the right action.
8986
- `parameters` is an array of parameters that the action takes. It follows the [JSON Schema](https://json-schema.org/) format.
@@ -101,4 +98,3 @@ Now, head back to the app and ask your pilot to do any of the following:
10198
- etc.
10299

103100
Your copilot is now more helpful than ever 💪
104-

docs/snippets/self-hosting-copilot-runtime-create-endpoint.mdx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ Copilot Runtime is designed to run as a handler for HTTP endpoints (typically `/
1212
<Tabs.Tab>
1313
Create a new route to handle the `/api/copilotkit` endpoint.
1414

15-
```ts showLineNumbers filename="app/copilotkit/route.ts"
15+
```ts showLineNumbers filename="app/api/copilotkit/route.ts"
1616
import {
1717
CopilotRuntime,
1818
OpenAIAdapter,
1919
copilotRuntimeNextJSAppRouterEndpoint,
2020
} from "@copilotkit/runtime";
2121
import OpenAI from "openai";
22+
import { NextRequest } from "next/server";
2223

2324
const openai = new OpenAI();
2425
const serviceAdapter = new OpenAIAdapter({ openai });
@@ -37,6 +38,7 @@ Copilot Runtime is designed to run as a handler for HTTP endpoints (typically `/
3738
```
3839

3940
Your Copilot Runtime endpoint should be available at `http://localhost:{port}/api/copilotkit`.
41+
4042
</Tabs.Tab>
4143
<Tabs.Tab>
4244
Create a new route to handle the `/api/copilotkit` endpoint:
@@ -67,6 +69,7 @@ Copilot Runtime is designed to run as a handler for HTTP endpoints (typically `/
6769
```
6870

6971
Your Copilot Runtime endpoint should be available at `http://localhost:{port}/api/copilotkit`.
72+
7073
</Tabs.Tab>
7174
<Tabs.Tab>
7275
Create a new Express.js app and set up the Copilot Runtime handler:
@@ -97,6 +100,7 @@ Copilot Runtime is designed to run as a handler for HTTP endpoints (typically `/
97100
```
98101

99102
Your Copilot Runtime endpoint should be available at `http://localhost:4000/copilotkit`.
103+
100104
</Tabs.Tab>
101105
<Tabs.Tab>
102106
Set up a simple Node.js HTTP server and use the Copilot Runtime to handle requests:
@@ -126,27 +130,31 @@ Copilot Runtime is designed to run as a handler for HTTP endpoints (typically `/
126130
```
127131

128132
Your Copilot Runtime endpoint should be available at `http://localhost:4000/copilotkit`.
133+
129134
</Tabs.Tab>
130135
<Tabs.Tab>
131136
```ts showLineNumbers filename="copilotkit.controller.ts"
132137
import { All, Controller, Req, Res } from "@nestjs/common";
133138
import { AppService } from "./app.service";
134139
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/backend";
135140

136-
@Controller()
137-
export class AppController {
138-
constructor(private readonly appService: AppService) {}
141+
@Controller()
142+
export class AppController {
143+
constructor(private readonly appService: AppService) {}
139144

140145
@All("/copilotkit")
141146
copilotkit(@Req() req: Request, @Res() res: Response) {
142147
const copilotKit = new CopilotRuntime();
143148
const openaiAdapter = new OpenAIAdapter();
144149
copilotKit.streamHttpServerResponse(req, res, openaiAdapter);
145150
}
146-
}
147-
```
148151

149-
Your Copilot Runtime endpoint should be available at `http://localhost:{port}/copilotkit`.
150-
</Tabs.Tab>
152+
}
153+
154+
```
155+
156+
Your Copilot Runtime endpoint should be available at `http://localhost:{port}/copilotkit`.
157+
</Tabs.Tab>
151158
</Tabs>
152159

160+
```

0 commit comments

Comments
 (0)