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:
Jungley authored and GitHub committed 2023-03-25 11:08:03 -06:00
1 parent dd44a06213
commit 966021ed74
5 files changed
+13 -4

No files matched your search

+3
View File
@@ -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'
+2 -1
View File
@@ -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}`