Allow custom config file (#143)
* Allow custom config file * Temporarily remove dependency on local openpipe
This commit is contained in:
3
app/.gitignore
vendored
3
app/.gitignore
vendored
@@ -44,3 +44,6 @@ yarn-error.log*
|
||||
|
||||
# Sentry Auth Token
|
||||
.sentryclirc
|
||||
|
||||
# custom openai intialization
|
||||
src/server/utils/openaiCustomConfig.json
|
||||
|
||||
@@ -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;
|
||||
|
||||
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
|
||||
// export const openai = env.OPENPIPE_API_KEY
|
||||
// ? new OpenAI.OpenAI(openAIConfig)
|
||||
// : new OriginalOpenAI(openAIConfig);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user