mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-08-02 22:58:43 +08:00
chore: add openai api endpoint config field (#11)
This commit is contained in:
@ -1 +1,2 @@
|
||||
OPENAI_API_KEY=<YOUR_API_KEY>
|
||||
OPENAI_API_ENDPOINT=<YOUR_API_ENDPOINT>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { openAIApiKey } from "@/utils";
|
||||
import { openAIApiEndpoint, openAIApiKey } from "@/utils";
|
||||
import { createParser, ParsedEvent, ReconnectInterval } from "eventsource-parser";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
@ -8,7 +8,7 @@ export const config = {
|
||||
|
||||
const handler = async (req: NextRequest) => {
|
||||
const reqBody = await req.json();
|
||||
const rawRes = await fetch(`https://api.openai.com/v1/chat/completions`, {
|
||||
const rawRes = await fetch(`${openAIApiEndpoint}/v1/chat/completions`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${openAIApiKey}`,
|
||||
|
@ -1,7 +1,11 @@
|
||||
import { encode } from "@nem035/gpt-3-encoder";
|
||||
|
||||
// openAIApiKey is the API key for OpenAI API.
|
||||
export const openAIApiKey = process.env.OPENAI_API_KEY;
|
||||
|
||||
// openAIApiEndpoint is the API endpoint for OpenAI API. Defaults to https://api.openai.com.
|
||||
export const openAIApiEndpoint = process.env.OPENAI_API_ENDPOINT || "https://api.openai.com";
|
||||
|
||||
export const countTextTokens = (text: string) => {
|
||||
return encode(text).length;
|
||||
};
|
||||
|
Reference in New Issue
Block a user