mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-09-25 17:15:19 +08:00
fix: correct response message
This commit is contained in:
@ -1,4 +1,8 @@
|
|||||||
import { createParser, ParsedEvent, ReconnectInterval } from "eventsource-parser";
|
import {
|
||||||
|
createParser,
|
||||||
|
ParsedEvent,
|
||||||
|
ReconnectInterval,
|
||||||
|
} from "eventsource-parser";
|
||||||
import { NextRequest } from "next/server";
|
import { NextRequest } from "next/server";
|
||||||
import { API_KEY } from "@/env";
|
import { API_KEY } from "@/env";
|
||||||
import { openAIApiEndpoint, openAIApiKey, gpt35 } from "@/utils";
|
import { openAIApiEndpoint, openAIApiKey, gpt35 } from "@/utils";
|
||||||
@ -17,9 +21,19 @@ const handler = async (req: NextRequest) => {
|
|||||||
if (API_KEY) {
|
if (API_KEY) {
|
||||||
const auth = req.headers.get("Authorization");
|
const auth = req.headers.get("Authorization");
|
||||||
if (!auth || auth !== `Bearer ${API_KEY}`) {
|
if (!auth || auth !== `Bearer ${API_KEY}`) {
|
||||||
return new Response("Unauthorized", {
|
return new Response(
|
||||||
status: 401,
|
JSON.stringify({
|
||||||
});
|
error: {
|
||||||
|
message: "Unauthorized.",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
status: 401,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +45,8 @@ const handler = async (req: NextRequest) => {
|
|||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
error: {
|
error: {
|
||||||
message: "OpenAI API Key is missing. You can supply your own key via Settings.",
|
message:
|
||||||
|
"OpenAI API Key is missing. You can supply your own key via Settings.",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
@ -43,7 +58,9 @@ const handler = async (req: NextRequest) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiEndpoint = getApiEndpoint(openAIApiConfig?.endpoint || openAIApiEndpoint);
|
const apiEndpoint = getApiEndpoint(
|
||||||
|
openAIApiConfig?.endpoint || openAIApiEndpoint
|
||||||
|
);
|
||||||
const res = await fetch(apiEndpoint, {
|
const res = await fetch(apiEndpoint, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
Reference in New Issue
Block a user