diff --git a/next-i18next.config.js b/next-i18next.config.js index 224b276..1c44b8a 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -1,5 +1,3 @@ -const path = require("path"); - module.exports = { i18n: { defaultLocale: "en", diff --git a/pages/api/models.ts b/pages/api/models.ts index 839f6aa..7f441ad 100644 --- a/pages/api/models.ts +++ b/pages/api/models.ts @@ -1,4 +1,5 @@ import { OpenAIModel, OpenAIModelID, OpenAIModels } from "@/types"; +import { OPENAI_API_HOST } from "@/utils/app/const"; export const config = { runtime: "edge" @@ -10,7 +11,7 @@ const handler = async (req: Request): Promise => { key: string; }; - const response = await fetch("https://api.openai.com/v1/models", { + const response = await fetch(`${OPENAI_API_HOST}/v1/models`, { headers: { "Content-Type": "application/json", Authorization: `Bearer ${key ? key : process.env.OPENAI_API_KEY}` diff --git a/types/env.d.ts b/types/env.d.ts new file mode 100644 index 0000000..b816009 --- /dev/null +++ b/types/env.d.ts @@ -0,0 +1,6 @@ +namespace NodeJS { + interface ProcessEnv { + OPENAI_API_KEY: string; + OPENAI_API_HOST?: string; + } +} diff --git a/utils/app/const.ts b/utils/app/const.ts index badac76..0b40c68 100644 --- a/utils/app/const.ts +++ b/utils/app/const.ts @@ -1 +1,4 @@ export const DEFAULT_SYSTEM_PROMPT = "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown."; + + +export const OPENAI_API_HOST = process.env.OPENAI_API_HOST || 'https://api.openai.com' \ No newline at end of file diff --git a/utils/server/index.ts b/utils/server/index.ts index 9c44d5a..b25cf4a 100644 --- a/utils/server/index.ts +++ b/utils/server/index.ts @@ -1,8 +1,9 @@ import { Message, OpenAIModel } from "@/types"; import { createParser, ParsedEvent, ReconnectInterval } from "eventsource-parser"; +import { OPENAI_API_HOST } from "../app/const"; export const OpenAIStream = async (model: OpenAIModel, systemPrompt: string, key: string, messages: Message[]) => { - const res = await fetch("https://api.openai.com/v1/chat/completions", { + const res = await fetch(`${OPENAI_API_HOST}/v1/chat/completions`, { headers: { "Content-Type": "application/json", Authorization: `Bearer ${key ? key : process.env.OPENAI_API_KEY}`