import { t } from "@lingui/macro"; | |
import { OpenAI } from "openai"; | |
import { useOpenAiStore } from "@/client/stores/openai"; | |
export const openai = () => { | |
const { apiKey, baseURL } = useOpenAiStore.getState(); | |
if (!apiKey) { | |
throw new Error( | |
t`Your OpenAI API Key has not been set yet. Please go to your account settings to enable OpenAI Integration.`, | |
); | |
} | |
if (baseURL) { | |
return new OpenAI({ | |
apiKey, | |
baseURL, | |
dangerouslyAllowBrowser: true, | |
}); | |
} | |
return new OpenAI({ | |
apiKey, | |
dangerouslyAllowBrowser: true, | |
}); | |
}; | |