forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
56 lines (55 loc) · 1.6 KB
/
Copy pathpage.tsx
File metadata and controls
56 lines (55 loc) · 1.6 KB
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
54
55
56
"use client";
import { useCopilotAction } from "@copilotkit/react-core";
import { CopilotPopup } from "@copilotkit/react-ui";
import { useState } from "react";
export default function YourApp() {
useCopilotAction({
name: "RequestAssistance",
parameters: [
{
name: "request",
type: "string",
},
],
renderAndWait: ({ args, status, handler }) => {
const [response, setResponse] = useState("");
return (
<div className="p-4 bg-gray-100 rounded shadow-md">
<p className="mb-2 text-gray-700">{args.request}</p>
<div className="flex items-center space-x-2">
<input
type="text"
className="flex-grow p-2 border border-gray-300 rounded"
placeholder="Your response..."
style={{ maxWidth: "calc(100% - 100px)" }}
value={response}
onChange={(e) => setResponse(e.target.value)}
/>
{status === "executing" && (
<button
className="px-4 py-2 text-white bg-blue-500 rounded hover:bg-blue-600"
onClick={() => handler(response)}
>
Submit
</button>
)}
</div>
</div>
);
},
});
return (
<>
<CopilotPopup
instructions={
"You are assisting the user as best as you can. Answer in the best way possible given the data you have."
}
defaultOpen={true}
labels={{
title: "Popup Assistant",
initial: "Need any help?",
}}
/>
</>
);
}