forked from YJU-OKURA/project_minori-next-deployment-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostPrompt.ts
37 lines (35 loc) · 920 Bytes
/
postPrompt.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
34
35
36
37
const postPrompt = async (
cId: number,
id: number,
message: string,
chat: (reader: ReadableStreamDefaultReader) => void
) => {
const token = localStorage.getItem('access_token');
console.log('token:', token);
const body = {
message: message,
};
console.log('body:', body);
try {
const response = await fetch(
`http://3.38.86.236:3000/api/nest/class/${cId}/prompts/${id}`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(body),
}
);
console.log('res:', response);
const reader = response.body?.getReader();
if (!reader) {
console.error('応答ストリームがありません。');
return;
}
await chat(reader);
} catch (error) {
console.error('ストリーム処理中にエラーが発生しました:', error);
}
};
export default postPrompt;