forked from openai/openai-assistants-quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
warnings.tsx
47 lines (40 loc) · 1.23 KB
/
warnings.tsx
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
"use client";
import React, { useState } from "react";
import styles from "./warnings.module.css";
import { assistantId } from "../assistant-config";
const Warnings = () => {
const [loading, setLoading] = useState(false);
const [newAssistantId, setNewAssistantId] = useState("");
const fetchAssistantId = async () => {
setLoading(true);
const response = await fetch("/api/assistants", { method: "POST" });
const data = await response.json();
setNewAssistantId(data.assistantId);
setLoading(false);
};
return (
<>
{!assistantId && (
<div className={styles.container}>
<h1>Start by creating your assistant</h1>
<div className={styles.message}>
Create an assistant and set its ID in{" "}
<span>app/assistant-config.ts</span>
</div>
{!newAssistantId ? (
<button
onClick={fetchAssistantId}
disabled={loading}
className={styles.button}
>
{loading ? "Loading..." : "Create Assistant"}
</button>
) : (
<div className={styles.result}>{newAssistantId}</div>
)}
</div>
)}
</>
);
};
export default Warnings;