feat: Allow customization of OpenAI host with environment variable (#152)
This commit modifies the OpenAI host configuration to support customization through an environment variable. This change is particularly useful in scenarios where access to the official OpenAI host is restricted or unavailable, allowing users to configure an alternative host for their specific needs.
This commit is contained in:
parent
dd44a06213
commit
966021ed74
|
@ -1,5 +1,3 @@
|
|||
const path = require("path");
|
||||
|
||||
module.exports = {
|
||||
i18n: {
|
||||
defaultLocale: "en",
|
||||
|
|
|
@ -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<Response> => {
|
|||
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}`
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
OPENAI_API_KEY: string;
|
||||
OPENAI_API_HOST?: string;
|
||||
}
|
||||
}
|
|
@ -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'
|
|
@ -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}`
|
||||
|
|
Loading…
Reference in New Issue