Skip to content

Commit

Permalink
Merge branch 'dev' into testcase-title
Browse files Browse the repository at this point in the history
  • Loading branch information
bhnuka authored Nov 9, 2024
2 parents 434b107 + bd5ebe9 commit 02383a6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ export const updateStatus = async (userId: string) => {
try {
const status = await getStatus(userId);
if (status.includes("request pending")) {
findMatchInQueue(userId);
try {
// Find match
await findMatchInQueue(userId);
} catch (error) {
console.error('Error in updateStatus:', error);
//throw new Error("Failed to update the status of the user's match request");
}
}
return status;
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@ import axios from 'axios';
export const assesCode = async (req: Request, res: Response): Promise<void> => {
console.log('assesCode controller activated');
try {
const { currentCode } = req.body;
const { codeDetails } = req.body;

if (!currentCode) {
if (!codeDetails) {
res.status(400).json({ error: 'Code content is required' });
return;
}

const instructionalPrompt =
"Analyze the following code snippet, focusing on its efficiency and style. Determine the correctness of the code, given the language specified. Your response should include:" + "\n" +
"Analyze the following: 1: Question, and its 2: Description, and 3: The code attempt. " + "\n" +
"Asses the code, focusing on its efficiency and style. Determine the correctness of the code, given the language and question specified. " +
"Your response should include:" + "\n" +
"\n" +
"\t1. Time Complexity – Provide the Big-O notation." + "\n" +
"\t2. Space Complexity – Provide the Big-O notation." + "\n" +
"\t3. Code Style – Briefly assess readability, naming conventions, and formatting." + "\n" +
"\t4. Optimization Hints – Suggest improvements if the time or space complexity could be reduced." + "\n" +
"\t5. General Comments – Summarize any other relevant observations (e.g., potential edge cases, overall structure)." + "\n" +
"\t5. General Comments – Summarize any other relevant observations and asses correctness to question requirements " +
"(e.g., potential edge cases, overall structure)." + "\n" +
"\n" +
"Keep each response concise but comprehensive.";
//console.log('Submitting code to OpenAI API:', instructionalPrompt, currentCode);
console.log('Submitting code to OpenAI API:', instructionalPrompt, codeDetails);

// API request to OpenAI for code assessment
const response = await axios.post(
Expand All @@ -30,7 +33,7 @@ export const assesCode = async (req: Request, res: Response): Promise<void> => {
model: 'gpt-4',
messages: [
{ role: 'system', content: "You are a coding assistant." },
{ role: 'user', content: `${instructionalPrompt}\n\nCode:\n${currentCode}` }
{ role: 'user', content: `${instructionalPrompt}\n\n${codeDetails}` }
],
temperature: 0
},
Expand Down
37 changes: 21 additions & 16 deletions peerprep/backend/question-service/src/sampleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Question from './models/questionModel';
questionId: 6,
title: 'Implement Stack using Queues',
description: `Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty).`,
categories: 'Data Structures',
categories: 'data-structures',
difficulty: 'easy',
},
{
Expand All @@ -20,7 +20,7 @@ import Question from './models/questionModel';
questionId: 12,
title: 'Rotate Image',
description: `You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).`,
categories: 'Arrays, Algorithms',
categories: 'Arrays, algorithms',
difficulty: 'medium',
},
{
Expand All @@ -45,7 +45,7 @@ import Question from './models/questionModel';
- '*' matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).`,
categories: 'Strings, Algorithms',
categories: 'Strings, algorithms',
difficulty: 'hard',
}
*/
Expand All @@ -65,77 +65,82 @@ const sampleQuestions = [
Constraints:
1 <= s.length <= 105
s[i] is a printable ascii character.`,
categories: 'Strings, Algorithms',
categories: 'strings, algorithms',
difficulty: 'easy',
},
{
title: 'Linked List Cycle Detection',
description: `Implement a function to detect if a linked list contains a cycle.`,
categories: 'Data Structures, Algorithms',
categories: 'data-structures, algorithms',
difficulty: 'easy',
},
{
title: 'Roman to Integer',
description: `Given a roman numeral, convert it to an integer.`,
categories: 'Algorithms',
categories: 'algorithms',
difficulty: 'easy',
},
{
title: 'Add Binary',
description: `Given two binary strings a and b, return their sum as a binary string.`,
categories: 'Bit Manipulation, Algorithms',
categories: 'algorithms',
difficulty: 'easy',
},
{
title: 'Fibonacci Number',
description: `The Fibonacci numbers, commonly denoted F(n) form a sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, F(0) = 0, F(1) = 1 F(n) = F(n - 1) + F(n - 2), for n > 1. Given n, calculate F(n).`,
categories: 'Recursion, Algorithms',
categories: 'algorithms',
difficulty: 'easy',
},
{
title: 'Repeated DNA Sequences',
description: `Given a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.`,
categories: 'Algorithms, Bit Manipulation',
categories: 'algorithms, graphs',
difficulty: 'medium',
},
{
title: 'Course Schedule',
description: `There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai. Return true if you can finish all courses.`,
categories: 'Data Structures, Algorithms',
categories: 'data-structures, algorithms',
difficulty: 'medium',
},
{
title: 'LRU Cache Design',
description: `Design and implement an LRU (Least Recently Used) cache.`,
categories: 'data-structures, dynamic-programming',
difficulty: 'medium',
},
{
title: 'Longest Common Subsequence',
description: `Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.
A subsequence of a string is a new string generated from the original string with some characters deleted without changing the relative order of the remaining characters.`,
categories: 'Strings, Algorithms',
categories: 'strings, algorithms',
difficulty: 'medium',
},
{
title: 'Validate Binary Search Tree',
description: `Given the root of a binary tree, determine if it is a valid binary search tree (BST).`,
categories: 'Data Structures, Algorithms',
categories: 'data-structures, algorithms',
difficulty: 'medium',
},
{
title: 'Sliding Window Maximum',
description: `You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position, return the maximum sliding window.`,
categories: 'Arrays, Algorithms',
categories: 'graphs, algorithms',
difficulty: 'hard',
},
{
title: 'N-Queen Problem',
description: `The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle.`,
categories: 'Algorithms',
categories: 'algorithms',
difficulty: 'hard',
},
{
title: 'Serialize and Deserialize a Binary Tree',
description: `Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection. Design an algorithm to serialize and deserialize a binary tree.`,
categories: 'Data Structures, Algorithms',
categories: 'data-structures, algorithms',
difficulty: 'hard',
}
];

// Create a helper function to simulate the Express request-response cycle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ const CollaborationServiceIntegratedView: React.FC = () => {
}

const currentCode = yText.toString();
const inputString = "LANGUAGE SPECIFIED IS: " + syntaxFullLang + "\n" + currentCode;
const questionInput = "1: Question - " + questionTitle + "\n" + "2: Description" + questionDescription + "\n";
const codeAttempt = "3: Code attempt in - " + syntaxFullLang + "\n" + currentCode;
const inputString = questionInput + codeAttempt;
const responseContent = await assesCode(inputString);
//setCommentOutput(responseContent);
setOutput(responseContent)
Expand Down

0 comments on commit 02383a6

Please sign in to comment.