fix: add browser environment check for local API calls

This commit is contained in:
Sujal Shah 2024-11-25 17:54:29 +05:30
parent f94165a421
commit 12dcb8deb3

View File

@ -283,6 +283,10 @@ const getOllamaBaseUrl = () => {
};
async function getOllamaModels(): Promise<ModelInfo[]> {
if (typeof window === 'undefined') {
return [];
}
try {
const baseUrl = getOllamaBaseUrl();
const response = await fetch(`${baseUrl}/api/tags`);
@ -361,6 +365,10 @@ async function getOpenRouterModels(): Promise<ModelInfo[]> {
}
async function getLMStudioModels(): Promise<ModelInfo[]> {
if (typeof window === 'undefined') {
return [];
}
try {
const baseUrl = import.meta.env.LMSTUDIO_API_BASE_URL || 'http://localhost:1234';
const response = await fetch(`${baseUrl}/v1/models`);