Skip to content

Commit de2d3db

Browse files
committed
Update try catch
1 parent a15f6c2 commit de2d3db

File tree

1 file changed

+22
-12
lines changed
  • projects/admin/src/PageContainer/GradingPage

1 file changed

+22
-12
lines changed

projects/admin/src/PageContainer/GradingPage/index.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ const Answer = {
2323
false: 'WRONG_ANSWER',
2424
} as const;
2525

26+
const Word = {
27+
true: '정답',
28+
false: '오답',
29+
} as const;
30+
2631
const GradingPage: React.FC<GradingPageProps> = ({ solveId }) => {
2732
const { push } = useRouter();
2833
const [selectedAnswer, setSelectedAnswer] = useState<boolean>(true);
@@ -46,28 +51,33 @@ const GradingPage: React.FC<GradingPageProps> = ({ solveId }) => {
4651

4752
const aiScoring = async () => {
4853
await setIsLoading(true);
49-
const completion = await openai.chat.completions.create({
50-
messages: [
51-
{
52-
role: 'user',
53-
content: `문제 : ${data.title} 내용 : ${data.content} 이 문제의 답이 이게 맞아? ${data.solution} true false로 대답해줘.`,
54-
},
55-
],
56-
model: 'gpt-3.5-turbo',
57-
});
58-
59-
handleSubmit(completion.choices[0].message.content as 'true' | 'false');
54+
try {
55+
const completion = await openai.chat.completions.create({
56+
messages: [
57+
{
58+
role: 'user',
59+
content: `문제 : ${data.title} 내용 : ${data.content} 이 문제의 답이 맞는지 틀린지 알려줘. 답 : ${data.solution} 답이 오류가 없는 것 같으면 true 아니면 false로 대답해줘.`,
60+
},
61+
],
62+
model: 'gpt-3.5-turbo',
63+
});
64+
65+
const answer = completion.choices[0].message.content;
66+
handleSubmit(answer.includes('true').toString() as 'true' | 'false');
67+
} catch (error) {
68+
toast.success(error);
69+
}
6070
};
6171

6272
const handleSubmit = (answer: 'true' | 'false') => {
6373
const solveStatus = Answer[answer];
74+
toast.success(`${Word[answer]}으로 처리되었습니다.`);
6475

6576
mutate({ solveStatus: solveStatus });
6677
};
6778

6879
if (isSuccess) {
6980
push('/mission/scoring');
70-
toast.success('성공적으로 채점되었습니다.');
7181
}
7282

7383
return (

0 commit comments

Comments
 (0)