Get simple explanations and ask follow-up questions about topics using OpenAI’s GPT models
The AI tab provides intelligent, conversational explanations using OpenAI’s GPT models. It offers two main features: simplified explanations and an interactive Q&A chat interface.
The AI tab requires an OpenAI API key. Users must add their own API key in the extension settings to use this feature.
// From content.js:916systemContent = `You are a helpful assistant that explains topics in simple, plain language. Respond in ${lang}. Keep your explanation to 2-3 short sentences that anyone can understand. Avoid jargon.`;
// From content.js:1251-1332async function handleAIQuestion() { // Add user message to conversation aiConversation.push({ role: 'user', content: question }); // Build messages for API const messages = [{ role: 'system', content: systemPrompt }]; // Add conversation history for (const msg of aiConversation) { if (msg.role === 'user' || msg.role === 'assistant') { messages.push({ role: msg.role, content: msg.content }); } } // Send to OpenAI const response = await chrome.runtime.sendMessage({ action: 'callOpenAI', messages: messages, language: currentLanguage }); aiConversation.push({ role: 'assistant', content: response.data }); aiExchangeCount++;}
System Prompt for Chat:
// From content.js:918-919systemContent = `You are a helpful assistant that answers questions about topics. Respond in ${lang}. Keep answers concise (2-4 sentences). Be accurate and helpful.`;
// From content.js:1001-1027function renderAINoKey(contentArea) { const text = document.createElement('p'); text.textContent = currentLanguage === 'ar' ? 'أضف مفتاح OpenAI API في إعدادات الإضافة لاستخدام ميزات الذكاء الاصطناعي.' : 'Add your OpenAI API key in the extension settings to use AI features.'; const hint = document.createElement('div'); hint.textContent = currentLanguage === 'ar' ? 'انقر على أيقونة الإضافة → أدخل مفتاح API' : 'Click the extension icon → Enter your API key';}
// From content.js:1334-1364function handleAIError(errorMsg, chatArea) { if (errorMsg === 'NO_API_KEY') { displayMsg = 'No API key set. Add one in extension settings.'; } else if (errorMsg === 'INVALID_API_KEY') { displayMsg = 'Invalid API key. Please check your key in settings.'; } else if (errorMsg === 'RATE_LIMITED') { displayMsg = 'Too many requests. Please wait a moment.'; } else if (errorMsg === 'INSUFFICIENT_QUOTA') { displayMsg = 'Insufficient OpenAI quota. Please check your account.'; }}
// From background.js:274-296if (!response.ok) { const status = response.status; if (status === 401) { throw new Error('INVALID_API_KEY'); } else if (status === 429) { throw new Error('RATE_LIMITED'); } else if (status === 402) { throw new Error('INSUFFICIENT_QUOTA'); } else if (status === 400) { throw new Error(`INVALID_REQUEST: ${errorDetail}`); }}
401 - Invalid API Key
The OpenAI API key is incorrect or revoked. User needs to update the key in extension settings.
429 - Rate Limited
Too many requests sent to OpenAI API. User should wait before trying again.
402 - Insufficient Quota
The OpenAI account has exhausted its API credits or quota. User needs to add credits to their OpenAI account.
400 - Invalid Request
The request format was incorrect. This usually indicates a bug in the extension.