scira-chat / lib /hf-client.ts
victor's picture
victor HF Staff
refactor: Implement lazy initialization for API clients
e569cd5
raw
history blame
494 Bytes
import OpenAI from "openai";
let hfInstance: OpenAI | null = null;
export function getHF(): OpenAI {
if (!hfInstance) {
hfInstance = new OpenAI({
apiKey: process.env.HF_TOKEN,
baseURL: "https://router.huggingface.co/v1",
});
}
return hfInstance;
}
// Export a getter that matches the original export name
export const hf = new Proxy({} as OpenAI, {
get(_target, prop, _receiver) {
const client = getHF();
return Reflect.get(client, prop, client);
}
});