(text, isMCQ, isMultipleChoice, config)
| 1299 | |
| 1300 | // Function to query custom AI API |
| 1301 | async function queryCustomAPI(text, isMCQ, isMultipleChoice, config) { |
| 1302 | const { aiProvider, customEndpoint, apiKey, modelName } = config; |
| 1303 | |
| 1304 | // Construct the prompt based on query type |
| 1305 | let prompt = text; |
| 1306 | if (isMCQ) { |
| 1307 | if (isMultipleChoice) { |
| 1308 | prompt += "\nIMPORTANT: This is a MULTIPLE CHOICE question where MULTIPLE options can be correct. Analyze the question carefully and provide ALL correct options.\n\nFormat your response EXACTLY like this:\n- If options are A, B, C and A and C are correct: 'A. [text of option A], C. [text of option C]'\n- If options are 1, 2, 3 and 1 and 3 are correct: '1. [text of option 1], 3. [text of option 3]'\n- If only one option is correct, provide just that one: 'B. [text of option B]'\n\nDO NOT include explanations, reasoning, or anything else. ONLY the correct option(s) in the exact format shown above, separated by commas if multiple.\nIf this is not an MCQ question, simply respond with 'Not an MCQ'"; |
| 1309 | } else { |
| 1310 | prompt += "\nIMPORTANT: This is a SINGLE CHOICE question where ONLY ONE option is correct. Analyze the question carefully and provide the single correct option.\n\nFormat your response EXACTLY like this:\n- If options are A, B, C: 'A. [text of option A]' or 'C. [text of option C]'\n- If options are 1, 2, 3: '1. [text of option 1]' or '3. [text of option 3]'\n\nDO NOT include explanations, reasoning, or anything else. ONLY the single correct answer in the exact format shown above.\nIf this is not an MCQ question, simply respond with 'Not an MCQ'"; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | try { |
| 1315 | let apiUrl, requestBody, headers; |
| 1316 | |
| 1317 | // Configure API call based on provider |
| 1318 | switch (aiProvider) { |
| 1319 | case 'openai': |
| 1320 | apiUrl = 'https://api.openai.com/v1/chat/completions'; |
| 1321 | headers = { |
| 1322 | 'Content-Type': 'application/json', |
| 1323 | 'Authorization': `Bearer ${apiKey}` |
| 1324 | }; |
| 1325 | requestBody = { |
| 1326 | model: modelName || 'gpt-4o-mini', |
| 1327 | messages: [{ role: 'user', content: prompt }], |
| 1328 | temperature: 0.7 |
| 1329 | }; |
| 1330 | break; |
| 1331 | |
| 1332 | case 'anthropic': |
| 1333 | apiUrl = 'https://api.anthropic.com/v1/messages'; |
| 1334 | headers = { |
| 1335 | 'Content-Type': 'application/json', |
| 1336 | 'x-api-key': apiKey, |
| 1337 | 'anthropic-version': '2023-06-01' |
| 1338 | }; |
| 1339 | requestBody = { |
| 1340 | model: modelName || 'claude-3-5-sonnet-20241022', |
| 1341 | max_tokens: 4096, |
| 1342 | messages: [{ role: 'user', content: prompt }] |
| 1343 | }; |
| 1344 | break; |
| 1345 | |
| 1346 | case 'google': |
| 1347 | const googleModel = modelName || 'gemini-2.5-flash'; |
| 1348 | apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/${googleModel}:generateContent?key=${apiKey}`; |
| 1349 | headers = { |
| 1350 | 'Content-Type': 'application/json' |
| 1351 | }; |
| 1352 | requestBody = { |
| 1353 | contents: [{ parts: [{ text: prompt }] }] |
| 1354 | }; |
| 1355 | break; |
| 1356 | |
| 1357 | case 'deepseek': |
| 1358 | apiUrl = 'https://api.deepseek.com/v1/chat/completions'; |
no outgoing calls
no test coverage detected