Skip to content

Commit

Permalink
Update generate.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
babaohuang committed Dec 14, 2023
1 parent cfda886 commit 307bc22
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pages/api/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export const post: APIRoute = async(context) => {

console.log('Received messages:', messages);

// 验证 messages 是否为数组
if (!Array.isArray(messages)) {
console.error('Expected messages to be an array, but received:', messages);
return new Response(JSON.stringify({
error: {
message: 'The messages field must be an array.',
},
}), { status: 400 });
}


const initOptions = generatePayload(messages)

const response = await fetch(`${baseUrl}?key=${apiKey}`, initOptions).catch((err: Error) => {
Expand Down

0 comments on commit 307bc22

Please sign in to comment.