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
|
# Sentry Auth Token
|
||||||
.sentryclirc
|
.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 { env } from "~/env.mjs";
|
||||||
|
|
||||||
import { default as OriginalOpenAI } from "openai";
|
// TODO: use local dependency
|
||||||
// import { OpenAI } from "openpipe";
|
// 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
|
try {
|
||||||
// export const openai = env.OPENPIPE_API_KEY
|
// Allow developers to override the config with a local file
|
||||||
// ? new OpenAI.OpenAI(openAIConfig)
|
const jsonData = fs.readFileSync(
|
||||||
// : new OriginalOpenAI(openAIConfig);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user