Skip to content

Commit

Permalink
Fix missing API keys at build time error in chat route
Browse files Browse the repository at this point in the history
Signed-off-by: Milan Gruner <[email protected]>
  • Loading branch information
lemilonkh committed Mar 4, 2024
1 parent dbd32a8 commit c652beb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/src/app/api/v0/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ import OpenAI from "openai";
import { ChatCompletionMessageParam } from "openai/resources/chat/completions";
import { apiHandler } from "@/util/api";

const Hf = new HfInference(process.env.HUGGINGFACE_API_KEY);
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
let Hf, openai;

function setupModels() {
if (!Hf) {
Hf = new HfInference(process.env.HUGGINGFACE_API_KEY);
}
if (!openai) {
openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
}
}

// export const runtime = "edge";

Expand Down Expand Up @@ -90,6 +98,7 @@ export const POST = apiHandler(async (req: Request) => {
});
}

setupModels();
if (process.env.CHAT_PROVIDER === "openai") {
return handleOpenAIChat(messages);
} else {
Expand Down

0 comments on commit c652beb

Please sign in to comment.