I’m not sure what happened, but I launched the dev version and it suddenly started working. I did add in some of what you said so maybe it was that. I dont know. Thanks either way! Have literally spent days trying to get ollama to work and started to believe everyone was lying lol.
UPDATE:
I think I figured out what’s causing all of the issues here. I decided to manually debug it by going to the file you mentioned earlier: /app/utils/constants.ts and then go to the getOllamaModels() function. I am like 90% sure this is the cause. I copy pasted the portion that returns a value, but I put it above as a console.log. Purely for debugging reasons right? Well it turns out that fixed it. I asked Cursor why that might be happening and it said that this function is causing a race condition where the models are not loaded yet because it’s asynchronous and so it uses the default model of claude sonnet 3.5. I changed it to this (per cursor’s instructions) and it’s working fine now.
Original:
async function getOllamaModels(): Promise<ModelInfo[]> {
try {
const baseUrl = getOllamaBaseUrl();
const response = await fetch(`${baseUrl}/api/tags`);
const data = (await response.json()) as OllamaApiResponse;
return data.models.map((model: OllamaModel) => ({
name: model.name,
label: `${model.name} (${model.details.parameter_size})`,
provider: 'Ollama',
maxTokenAllowed: 8000,
}));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return [];
}
}
With console.log:
async function getOllamaModels(): Promise<ModelInfo[]> {
try {
const baseUrl = getOllamaBaseUrl();
const response = await fetch(`${baseUrl}/api/tags`);
const data = (await response.json()) as OllamaApiResponse;
console.log(data.models.map((model: OllamaModel) => ({
name: model.name,
label: `${model.name} (${model.details.parameter_size})`,
provider: 'Ollama',
maxTokenAllowed: 8000,
})));
return data.models.map((model: OllamaModel) => ({
name: model.name,
label: `${model.name} (${model.details.parameter_size})`,
provider: 'Ollama',
maxTokenAllowed: 8000,
}));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return [];
}
}
Cursor-Proposed Fix:
async function getOllamaModels(): Promise<ModelInfo[]> {
try {
const baseUrl = getOllamaBaseUrl();
const response = await fetch(`${baseUrl}/api/tags`);
const data = (await response.json()) as OllamaApiResponse;
// Ensure data is fully resolved before mapping
const models = await Promise.resolve(data.models);
// Filter out potentially problematic models and ensure proper formatting
return models
.filter(model => {
// Skip models that might cause GGML assertion errors
const skipPatterns = ['vision', 'multimodal'];
return !skipPatterns.some(pattern => model.name.toLowerCase().includes(pattern));
})
.map((model: OllamaModel) => ({
name: model.name,
label: `${model.name} (${model.details.parameter_size || 'Unknown size'})`,
provider: 'Ollama',
maxTokenAllowed: 8000,
}));
} catch (e) {
console.warn('Failed to fetch Ollama models:', e);
return [];
}
}
If someone with more experience wants to chime in, please do so!