mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-09-24 16:46:05 +08:00
chore: update env variables in readme
This commit is contained in:
@ -1,2 +1,3 @@
|
|||||||
|
# Do not share your OpenAI API key with anyone! It should remain a secret.
|
||||||
OPENAI_API_KEY=<YOUR_API_KEY>
|
OPENAI_API_KEY=<YOUR_API_KEY>
|
||||||
OPENAI_API_ENDPOINT=<YOUR_API_ENDPOINT>
|
OPENAI_API_ENDPOINT=<YOUR_API_ENDPOINT>
|
||||||
|
10
README.md
10
README.md
@ -36,9 +36,15 @@ SQL Chat is built by Next.js, it supports following databases and will add more
|
|||||||
|
|
||||||
## Local Development
|
## Local Development
|
||||||
|
|
||||||
1. Create a `.env` file in the root directory with your `OPENAI_API_KEY`;
|
1. Make a copy of the example environment variables file;
|
||||||
|
|
||||||
2. Install dependencies and start the dev server;
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Add your [API key](https://platform.openai.com/account/api-keys) and OpenAI API Endpoint(optional) to the newly created `.env` file;
|
||||||
|
|
||||||
|
3. Install dependencies and start the dev server;
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm i && pnpm dev
|
pnpm i && pnpm dev
|
||||||
|
@ -6,9 +6,11 @@ export const config = {
|
|||||||
runtime: "edge",
|
runtime: "edge",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const apiEndpoint = new URL(`${openAIApiEndpoint}/v1/chat/completions`);
|
||||||
|
|
||||||
const handler = async (req: NextRequest) => {
|
const handler = async (req: NextRequest) => {
|
||||||
const reqBody = await req.json();
|
const reqBody = await req.json();
|
||||||
const rawRes = await fetch(`${openAIApiEndpoint}/v1/chat/completions`, {
|
const res = await fetch(apiEndpoint, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${openAIApiKey}`,
|
Authorization: `Bearer ${openAIApiKey}`,
|
||||||
@ -23,10 +25,10 @@ const handler = async (req: NextRequest) => {
|
|||||||
stream: true,
|
stream: true,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
if (!rawRes.ok) {
|
if (!res.ok) {
|
||||||
return new Response(rawRes.body, {
|
return new Response(res.body, {
|
||||||
status: rawRes.status,
|
status: res.status,
|
||||||
statusText: rawRes.statusText,
|
statusText: res.statusText,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ const handler = async (req: NextRequest) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const parser = createParser(streamParser);
|
const parser = createParser(streamParser);
|
||||||
for await (const chunk of rawRes.body as any) {
|
for await (const chunk of res.body as any) {
|
||||||
parser.feed(decoder.decode(chunk));
|
parser.feed(decoder.decode(chunk));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user