Skip to content

Commit

Permalink
Allow setting non-default OpenAI base URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manouchehri authored and jehna committed Oct 18, 2024
1 parent 1443228 commit ea566f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/commands/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export const openai = cli()
"-k, --apiKey <apiKey>",
"The OpenAI API key. Alternatively use OPENAI_API_KEY environment variable"
)
.option(
"--baseURL <baseURL>",
"The OpenAI base server URL.",
env("OPENAI_BASE_URL") ?? "https://api.openai.com/v1"
)
.option("--verbose", "Show verbose output")
.argument("input", "The input minified Javascript file")
.action(async (filename, opts) => {
Expand All @@ -23,9 +28,10 @@ export const openai = cli()
}

const apiKey = opts.apiKey ?? env("OPENAI_API_KEY");
const baseURL = opts.baseURL;
await unminify(filename, opts.outputDir, [
babel,
openaiRename({ apiKey, model: opts.model }),
openaiRename({ apiKey, baseURL, model: opts.model }),
prettier
]);
});
4 changes: 3 additions & 1 deletion src/plugins/openai/openai-rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { verbose } from "../../verbose.js";

export function openaiRename({
apiKey,
baseURL,
model
}: {
apiKey: string;
baseURL: string;
model: string;
}) {
const client = new OpenAI({ apiKey });
const client = new OpenAI({ apiKey, baseURL });

return async (code: string): Promise<string> => {
return await visitAllIdentifiers(
Expand Down

0 comments on commit ea566f3

Please sign in to comment.