Skip to content

Added MCQs solving functionality. #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ dist
**/.idea
scripts/
**/scripts/
scripts/manual-notarize.js
scripts/manual-notarize.js
autorun.bat
skibidi.vbs
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Changes I have done :
> - Changed Prompting for solving MCQs of topics related to OS,DBMS,Programming(even Syntax-based too)
> - Renders based on whether the question is a Coding problem or an MCQ (for MCQ it gives correct answer and explanation too)
# CodeInterviewAssist

> ## ⚠️ IMPORTANT NOTICE TO THE COMMUNITY ⚠️
Expand Down
3 changes: 3 additions & 0 deletions autorun.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
cd C:\Users\asmit\Downloads\interviewCoder\interview
stealth-run.bat
205 changes: 195 additions & 10 deletions electron/ProcessingHelper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// ProcessingHelper.ts
// ProcessingHelper.ts - UPDATED VERSION with Enhanced MCQ Detection
import fs from "node:fs"
import path from "node:path"

Check failure on line 3 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'path' is defined but never used

Check failure on line 3 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'path' is defined but never used

Check failure on line 3 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

'path' is defined but never used
import { ScreenshotHelper } from "./ScreenshotHelper"
import { IProcessingHelperDeps } from "./main"
import * as axios from "axios"
import { app, BrowserWindow, dialog } from "electron"

Check failure on line 7 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'dialog' is defined but never used

Check failure on line 7 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'app' is defined but never used

Check failure on line 7 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'dialog' is defined but never used

Check failure on line 7 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'app' is defined but never used

Check failure on line 7 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

'dialog' is defined but never used

Check failure on line 7 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

'app' is defined but never used
import { OpenAI } from "openai"
import { configHelper } from "./ConfigHelper"
import Anthropic from '@anthropic-ai/sdk';
Expand All @@ -31,7 +31,7 @@
finishReason: string;
}>;
}
interface AnthropicMessage {

Check failure on line 34 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

'AnthropicMessage' is defined but never used

Check failure on line 34 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

'AnthropicMessage' is defined but never used

Check failure on line 34 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

'AnthropicMessage' is defined but never used
role: 'user' | 'assistant';
content: Array<{
type: 'text' | 'image';
Expand All @@ -56,7 +56,7 @@

constructor(deps: IProcessingHelperDeps) {
this.deps = deps
this.screenshotHelper = deps.getScreenshotHelper()

Check failure on line 59 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

Type 'ScreenshotHelper | null' is not assignable to type 'ScreenshotHelper'.

// Initialize AI client based on config
this.initializeAIClient();
Expand Down Expand Up @@ -286,7 +286,7 @@
throw new Error("Failed to load screenshot data");
}

const result = await this.processScreenshotsHelper(validScreenshots, signal)

Check failure on line 289 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

Argument of type '({ path: string; preview: string; data: string; } | null)[]' is not assignable to parameter of type '{ path: string; data: string; }[]'.

if (!result.success) {
console.log("Processing failed:", result.error)
Expand All @@ -313,7 +313,7 @@
result.data
)
this.deps.setView("solutions")
} catch (error: any) {

Check failure on line 316 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

Unexpected any. Specify a different type

Check failure on line 316 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

Unexpected any. Specify a different type

Check failure on line 316 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

Unexpected any. Specify a different type
mainWindow.webContents.send(
this.deps.PROCESSING_EVENTS.INITIAL_SOLUTION_ERROR,
error
Expand Down Expand Up @@ -400,11 +400,11 @@

console.log(
"Combined screenshots for processing:",
validScreenshots.map((s) => s.path)

Check failure on line 403 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

's' is possibly 'null'.
)

const result = await this.processExtraScreenshotsHelper(
validScreenshots,

Check failure on line 407 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

Argument of type '({ path: string; preview: string; data: string; } | null)[]' is not assignable to parameter of type '{ path: string; data: string; }[]'.
signal
)

Expand All @@ -420,7 +420,7 @@
result.error
)
}
} catch (error: any) {

Check failure on line 423 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

Unexpected any. Specify a different type

Check failure on line 423 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

Unexpected any. Specify a different type

Check failure on line 423 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

Unexpected any. Specify a different type
if (axios.isCancel(error)) {
mainWindow.webContents.send(
this.deps.PROCESSING_EVENTS.DEBUG_ERROR,
Expand Down Expand Up @@ -477,14 +477,14 @@
const messages = [
{
role: "system" as const,
content: "You are a coding challenge interpreter. Analyze the screenshot of the coding problem and extract all relevant information. Return the information in JSON format with these fields: problem_statement, constraints, example_input, example_output. Just return the structured JSON without any other text."
content: "You are an intelligent assistant that analyzes screenshots and determines if they contain coding problems or Multiple Choice Questions (MCQs).\n\n**IMPORTANT: Look carefully at the image content, including any code snippets, formatted text, or structured questions.**\n\n**If it's a CODING PROBLEM (like LeetCode, programming challenges):**\nReturn JSON format: {\"problem_statement\": \"...\", \"constraints\": \"...\", \"example_input\": \"...\", \"example_output\": \"...\"}\n\n**If it's an MCQ (Multiple Choice Question) - this includes:**\n- Questions with options A, B, C, D (even if formatted/colored)\n- Code-based MCQs with syntax highlighting\n- Questions asking \"What will be the output?\"\n- Questions about programming concepts, syntax, or theory\n- SQL queries asking \"What will this query do?\"\n- Java code asking \"What is the output?\"\n\nReturn in this EXACT format:\nMCQ_ANSWER: [A/B/C/D]\nEXPLANATION: [Detailed explanation of why this answer is correct, including step-by-step code analysis if applicable]\n\n**If it's neither:**\nReturn: UNSUPPORTED_FORMAT"
},
{
role: "user" as const,
content: [
{
type: "text" as const,
text: `Extract the coding problem details from these screenshots. Return in JSON format. Preferred coding language we gonna use for this problem is ${language}.`
text: `Analyze this screenshot. If it's a coding problem, return JSON format. If it's an MCQ about computer science topics (including code-based questions asking \"What will be the output?\" or \"What will this query do?\"), provide the MCQ answer and explanation as specified.`

Check failure on line 487 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest

Unnecessary escape character: \"

Check failure on line 487 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest

Unnecessary escape character: \"

Check failure on line 487 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

Unnecessary escape character: \"
},
...imageDataList.map(data => ({
type: "image_url" as const,
Expand All @@ -505,7 +505,68 @@
// Parse the response
try {
const responseText = extractionResponse.choices[0].message.content;
// Handle when OpenAI might wrap the JSON in markdown code blocks

// Enhanced MCQ detection function
const isMCQResponse = (text: string): boolean => {
if (text.includes('MCQ_ANSWER:')) return true;

const mcqIndicators = [
'what will be the output',
'which of the following',
'what is the result',
'what will this query do',
'what does the following'
];

const lowerText = text.toLowerCase();
return mcqIndicators.some(indicator => lowerText.includes(indicator));
};

// Check if it's an MCQ response
if (isMCQResponse(responseText)) {

Check failure on line 526 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

Argument of type 'string | null' is not assignable to parameter of type 'string'.
let answerMatch = responseText.match(/MCQ_ANSWER:\s*([A-D])/i);

Check failure on line 527 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

'responseText' is possibly 'null'.

if (!answerMatch) {
answerMatch = responseText.match(/(?:answer\s*(?:is\s*)?):?\s*([A-D])/i);

Check failure on line 530 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

'responseText' is possibly 'null'.
}

let explanationMatch = responseText.match(/EXPLANATION:\s*(.*)/is);

Check failure on line 533 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

'responseText' is possibly 'null'.
if (!explanationMatch) {
explanationMatch = [null, responseText];

Check failure on line 535 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

Type 'string | null' is not assignable to type 'string'.

Check failure on line 535 in electron/ProcessingHelper.ts

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest

Type 'null' is not assignable to type 'string'.
}

const mcqResult = {
isMCQ: true,
answer: answerMatch ? answerMatch[1].toUpperCase() : 'Unknown',
explanation: explanationMatch ? explanationMatch[1].trim() : responseText.trim(),
fullResponse: responseText
};

// Update progress and send MCQ result to frontend
if (mainWindow) {
mainWindow.webContents.send("processing-status", {
message: "MCQ answered successfully",
progress: 100
});

mainWindow.webContents.send(
this.deps.PROCESSING_EVENTS.SOLUTION_SUCCESS,
mcqResult
);
}

return { success: true, data: mcqResult };
}

// Handle unsupported format
if (responseText.includes('UNSUPPORTED_FORMAT')) {
return {
success: false,
error: "This appears to be neither a coding problem nor a supported MCQ. Please try a clearer screenshot."
};
}

// Handle as coding problem (existing logic)
const jsonText = responseText.replace(/```json|```/g, '').trim();
problemInfo = JSON.parse(jsonText);
} catch (error) {
Expand All @@ -525,13 +586,44 @@
}

try {
// Create Gemini message structure
// Enhanced Gemini prompt for better code-based MCQ detection
const geminiMessages: GeminiMessage[] = [
{
role: "user",
parts: [
{
text: `You are a coding challenge interpreter. Analyze the screenshots of the coding problem and extract all relevant information. Return the information in JSON format with these fields: problem_statement, constraints, example_input, example_output. Just return the structured JSON without any other text. Preferred coding language we gonna use for this problem is ${language}.`
text: `You are an intelligent assistant that analyzes screenshots and determines if they contain coding problems or Multiple Choice Questions (MCQs).

**IMPORTANT: Look carefully at the image content, including any code snippets, formatted text, or structured questions.**

**If it's a CODING PROBLEM (like LeetCode, programming challenges):**
Return JSON format: {"problem_statement": "...", "constraints": "...", "example_input": "...", "example_output": "..."}
Preferred coding language: ${language}

**If it's an MCQ (Multiple Choice Question) - this includes:**
- Questions with options A, B, C, D (even if formatted/colored)
- Code-based MCQs with syntax highlighting
- Questions asking "What will be the output?"
- Questions about programming concepts, syntax, or theory
- SQL queries asking "What will this query do?"
- Java code asking "What is the output?"
- Any question with lettered options asking about code behavior

Return in this EXACT format:
MCQ_ANSWER: [A/B/C/D]
EXPLANATION: [Detailed explanation of why this answer is correct, including step-by-step code analysis if applicable]

**Examples of MCQs to detect:**
- "What will be the output of this Java code?"
- "Which SQL query will do X?"
- "What will the following SQL query do?"
- "What is the result of this code snippet?"
- Any question with lettered options (A, B, C, D)

**If it's neither:**
Return: UNSUPPORTED_FORMAT

Analyze this screenshot carefully and respond appropriately:`
},
...imageDataList.map(data => ({
inlineData: {
Expand Down Expand Up @@ -563,10 +655,103 @@
}

const responseText = responseData.candidates[0].content.parts[0].text;

// Enhanced MCQ detection function
// Enhanced MCQ detection function
const isMCQResponse = (text: string): boolean => {
if (text.includes('MCQ_ANSWER:')) return true;

const mcqIndicators = [
'what will be the output',
'which of the following',
'what is the result',
'what will this query do',
'what does the following',
'the correct answer is',
'answer is'
];

const lowerText = text.toLowerCase();
return mcqIndicators.some(indicator => lowerText.includes(indicator));
};

// Check if it's an MCQ response
if (isMCQResponse(responseText)) {
// Try multiple patterns to extract the answer
let answerMatch = responseText.match(/MCQ_ANSWER:\s*([A-D])/i);

if (!answerMatch) {
// Try "Answer: B" pattern
answerMatch = responseText.match(/(?:answer\s*(?:is\s*)?):?\s*([A-D])/i);
}

if (!answerMatch) {
// Try "The answer is B" pattern
answerMatch = responseText.match(/(?:the\s+answer\s+is\s+)([A-D])/i);
}

if (!answerMatch) {
// Try "Correct answer: B" pattern
answerMatch = responseText.match(/(?:correct\s+answer\s*:?\s*)([A-D])/i);
}

if (!answerMatch) {
// Try standalone letter pattern (look for isolated A, B, C, or D)
answerMatch = responseText.match(/\b([A-D])\b/);
}

// Try multiple explanation patterns
let explanationMatch = responseText.match(/EXPLANATION:\s*(.*)/is);
if (!explanationMatch) {
explanationMatch = responseText.match(/(?:explanation|because|reason):\s*(.*)/is);
}
if (!explanationMatch) {
// If no explicit explanation found, use the full response
explanationMatch = [null, responseText];
}

const mcqResult = {
isMCQ: true,
answer: answerMatch ? answerMatch[1].toUpperCase() : 'Unknown',
explanation: explanationMatch ? explanationMatch[1].trim() : responseText.trim(),
fullResponse: responseText
};


if (mainWindow) {
mainWindow.webContents.send("processing-status", {
message: "MCQ answered successfully",
progress: 100
});

mainWindow.webContents.send(
this.deps.PROCESSING_EVENTS.SOLUTION_SUCCESS,
mcqResult
);
}

return { success: true, data: mcqResult };
}

// Handle unsupported format
if (responseText.includes('UNSUPPORTED_FORMAT')) {
return {
success: false,
error: "This appears to be neither a coding problem nor a supported MCQ. Please try a clearer screenshot."
};
}

// Handle when Gemini might wrap the JSON in markdown code blocks
const jsonText = responseText.replace(/```json|```/g, '').trim();
problemInfo = JSON.parse(jsonText);
// Handle as coding problem (existing logic)
try {
const jsonText = responseText.replace(/```json|```/g, '').trim();
problemInfo = JSON.parse(jsonText);
} catch (parseError) {
console.error("Error parsing JSON from Gemini response:", parseError);
return {
success: false,
error: "Failed to parse problem information. Please try again or use clearer screenshots."
};
}
} catch (error) {
console.error("Error using Gemini API:", error);
return {
Expand Down Expand Up @@ -1314,4 +1499,4 @@
mainWindow.webContents.send(this.deps.PROCESSING_EVENTS.NO_SCREENSHOTS)
}
}
}
}
Loading
Loading