Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 259a13a

Browse files
committed
error on empty input
1 parent 65a52e0 commit 259a13a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pages/api/generate.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@ export default async function (req, res) {
1515
return;
1616
}
1717

18+
const animal = req.body.animal || '';
19+
if (animal.trim().length === 0) {
20+
res.status(400).json({
21+
error: {
22+
message: "Please enter a valid animal",
23+
}
24+
});
25+
return;
26+
}
27+
1828
try {
1929
const completion = await openai.createCompletion({
2030
model: "text-davinci-003",
21-
prompt: generatePrompt(req.body.animal),
31+
prompt: generatePrompt(animal),
2232
temperature: 0.6,
2333
});
2434
res.status(200).json({ result: completion.data.choices[0].text });

pages/index.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
border: 1px solid #10a37f;
4747
border-radius: 4px;
4848
margin-bottom: 24px;
49+
outline-color: #10a37f;
4950
}
5051
.main ::placeholder {
5152
color: #8e8ea0;

0 commit comments

Comments
 (0)