Allow custom config file (#143)

* Allow custom config file

* Temporarily remove dependency on local openpipe
This commit is contained in:
arcticfly
2023-08-11 23:07:04 -07:00
committed by GitHub
parent 3e02bcf9b8
commit de9be8c7ce
2 changed files with 23 additions and 7 deletions

3
app/.gitignore vendored
View File

@@ -44,3 +44,6 @@ yarn-error.log*
# Sentry Auth Token
.sentryclirc
# custom openai intialization
src/server/utils/openaiCustomConfig.json

View File

@@ -1,13 +1,26 @@
import { type ClientOptions, default as OriginalOpenAI } from "openai";
import fs from "fs";
import path from "path";
import { env } from "~/env.mjs";
import { default as OriginalOpenAI } from "openai";
// TODO: use local dependency
// import { OpenAI } from "openpipe";
const openAIConfig = { apiKey: env.OPENAI_API_KEY ?? "dummy-key" };
let config: ClientOptions;
// Set a dummy key so it doesn't fail at build time
// export const openai = env.OPENPIPE_API_KEY
// ? new OpenAI.OpenAI(openAIConfig)
// : new OriginalOpenAI(openAIConfig);
try {
// Allow developers to override the config with a local file
const jsonData = fs.readFileSync(
path.join(path.dirname(import.meta.url).replace("file://", ""), "./openaiCustomConfig.json"),
"utf8",
);
config = JSON.parse(jsonData.toString());
} catch (error) {
// Set a dummy key so it doesn't fail at build time
config = { apiKey: env.OPENAI_API_KEY ?? "dummy-key" };
}
export const openai = new OriginalOpenAI(openAIConfig);
// export const openai = env.OPENPIPE_API_KEY ? new OpenAI.OpenAI(config) : new OriginalOpenAI(config);
export const openai = new OriginalOpenAI(config);