fix: update response body type

This commit is contained in:
Steven
2023-05-09 00:37:32 +08:00
parent fdda5ca142
commit 4323b19562

View File

@ -28,14 +28,19 @@ const handler = async (req: NextRequest) => {
const apiKey = openAIApiConfig?.key || openAIApiKey; const apiKey = openAIApiConfig?.key || openAIApiKey;
if (!apiKey) { if (!apiKey) {
const stream = new ReadableStream({ return new Response(
async start(controller) { JSON.stringify({
controller.error(new Error("OpenAI API Key is missing. You can supply your own key via Settings.")); error: {
}, message: "OpenAI API Key is missing. You can supply your own key via Settings.",
}); },
return new Response(stream, { }),
status: 401, {
}); headers: {
"Content-Type": "application/json",
},
status: 401,
}
);
} }
const apiEndpoint = getApiEndpoint(openAIApiConfig?.endpoint || openAIApiEndpoint); const apiEndpoint = getApiEndpoint(openAIApiConfig?.endpoint || openAIApiEndpoint);