Enhanced Ollama Connection Debugging

Debugging Improvements:
 Added detailed console logging for connection attempts
 Enhanced error reporting with error names and messages
 Added CORS headers to fetch requests
 Improved model loading with step-by-step logging
 Added basic fetch capability test in init()

 Electron Security Fix:
 Added webSecurity: false to allow localhost HTTP requests
 This should resolve any CORS/security blocking issues

 Investigation:
 Added comprehensive logging to identify connection failures
 Better error handling throughout the connection process
 Will help diagnose if issue is network, CORS, or API related
This commit is contained in:
dilgenfritz 2025-09-29 07:18:06 -05:00
parent c076a91b85
commit 5e28163f7e
2 changed files with 57 additions and 4 deletions

View File

@ -15,6 +15,17 @@ class AITaskManager {
}
async init() {
console.log('AITaskManager initializing...');
console.log('Testing basic fetch capability...');
// Test if fetch works at all
try {
const testResponse = await fetch('http://localhost:11434/api/tags');
console.log('Basic fetch test result:', testResponse.status);
} catch (testError) {
console.error('Basic fetch test failed:', testError);
}
await this.checkAvailability();
await this.loadModels();
this.loadConfig();
@ -31,35 +42,73 @@ class AITaskManager {
const response = await fetch(`${this.ollamaUrl}/api/tags`, {
method: 'GET',
signal: controller.signal
signal: controller.signal,
mode: 'cors',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
clearTimeout(timeoutId);
console.log('Response status:', response.status);
console.log('Response ok:', response.ok);
this.isAvailable = response.ok;
if (response.ok) {
const data = await response.json();
console.log('Available models from API:', data.models?.map(m => m.name));
}
console.log('Ollama connection test result:', this.isAvailable ? 'SUCCESS' : 'FAILED');
return this.isAvailable;
} catch (error) {
console.log('Ollama not available:', error.message);
console.error('Ollama connection error details:', error);
console.log('Error name:', error.name);
console.log('Error message:', error.message);
this.isAvailable = false;
return false;
}
}
async loadModels() {
if (!this.isAvailable) return [];
if (!this.isAvailable) {
console.log('Skipping model loading - Ollama not available');
return [];
}
try {
const response = await fetch(`${this.ollamaUrl}/api/tags`);
console.log('Loading models from Ollama...');
const response = await fetch(`${this.ollamaUrl}/api/tags`, {
method: 'GET',
mode: 'cors',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json();
this.availableModels = data.models || [];
console.log('Loaded models:', this.availableModels.map(m => m.name));
// Check if our preferred NSFW models are available
const modelNames = this.availableModels.map(m => m.name);
const preferredModels = ['wizardlm-uncensored:13b', 'llama3.1:8b-instruct', 'dolphin-mistral:7b', 'wizardlm-uncensored:7b', 'llama3.2'];
console.log('Checking preferred models:', preferredModels);
console.log('Available model names:', modelNames);
for (const preferred of preferredModels) {
if (modelNames.includes(preferred)) {
console.log('Found preferred model:', preferred);
this.currentModel = preferred;
break;
}
@ -68,11 +117,14 @@ class AITaskManager {
// If no preferred models found, use the first available model
if (this.availableModels.length > 0 && !modelNames.includes(this.currentModel)) {
this.currentModel = this.availableModels[0].name;
console.log('Using first available model:', this.currentModel);
}
console.log('Selected model:', this.currentModel);
return this.availableModels;
} catch (error) {
console.error('Error loading models:', error);
this.availableModels = [];
return [];
}
}

View File

@ -69,6 +69,7 @@ async function createWindow() {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
webSecurity: false, // Allow requests to localhost
preload: path.join(__dirname, 'preload.js')
},
icon: path.join(__dirname, 'assets', 'icon.png'),