From 7b0da2c58b1d5e10bb33dbcda3380c75fdbb2f43 Mon Sep 17 00:00:00 2001 From: C Mahidharah Rajendran Date: Thu, 7 Nov 2024 19:39:19 +0800 Subject: [PATCH] Update GenAI integration and fix bugs --- .../src/services/statusService.ts | 8 ++++- .../src/controllers/gptController.ts | 15 ++++---- .../question-service/src/sampleData.ts | 34 +++++++++---------- peerprep/frontend/src/styles/App.css | 1 + .../CollabServiceIntegratedView.tsx | 4 ++- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/peerprep/backend/matching-service/src/services/statusService.ts b/peerprep/backend/matching-service/src/services/statusService.ts index 1a70430e94..e23397f244 100644 --- a/peerprep/backend/matching-service/src/services/statusService.ts +++ b/peerprep/backend/matching-service/src/services/statusService.ts @@ -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) { diff --git a/peerprep/backend/question-service/src/controllers/gptController.ts b/peerprep/backend/question-service/src/controllers/gptController.ts index 832d275c19..2ec75268d7 100644 --- a/peerprep/backend/question-service/src/controllers/gptController.ts +++ b/peerprep/backend/question-service/src/controllers/gptController.ts @@ -4,24 +4,27 @@ import axios from 'axios'; export const assesCode = async (req: Request, res: Response): Promise => { 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( @@ -30,7 +33,7 @@ export const assesCode = async (req: Request, res: Response): Promise => { 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 }, diff --git a/peerprep/backend/question-service/src/sampleData.ts b/peerprep/backend/question-service/src/sampleData.ts index 046c68cea0..d8c53a250e 100644 --- a/peerprep/backend/question-service/src/sampleData.ts +++ b/peerprep/backend/question-service/src/sampleData.ts @@ -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', }, { @@ -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', }, { @@ -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', } */ @@ -65,49 +65,49 @@ 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', + categories: 'data-structures, dynamic-programming', difficulty: 'medium', }, { @@ -115,37 +115,37 @@ const sampleQuestions = [ 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', }, { title: 'Trips and Users', description: `Given table Trips with columns id, client_id, driver_id, city_id, status, request_at, and table Users with columns users_id, banned, role, write a solution to find the cancellation rate of requests with unbanned users (both client and driver must not be banned) between specific dates.`, - categories: 'Databases', + categories: 'data-structures, graphs, strings, algorithms', difficulty: 'hard', }, ]; diff --git a/peerprep/frontend/src/styles/App.css b/peerprep/frontend/src/styles/App.css index 306cb0b92a..0a70a493c8 100644 --- a/peerprep/frontend/src/styles/App.css +++ b/peerprep/frontend/src/styles/App.css @@ -698,6 +698,7 @@ input { .matching-form2 { padding: 0px; max-width: 40%; + min-width: 10%; margin: 0 auto; /* Center the form */ border-radius: 10px; /* Rounded corners for the form */ background-color: white; diff --git a/peerprep/frontend/src/views/CollabServiceViews/CollabServiceIntegratedView.tsx b/peerprep/frontend/src/views/CollabServiceViews/CollabServiceIntegratedView.tsx index 8032759d3a..20914d3597 100644 --- a/peerprep/frontend/src/views/CollabServiceViews/CollabServiceIntegratedView.tsx +++ b/peerprep/frontend/src/views/CollabServiceViews/CollabServiceIntegratedView.tsx @@ -196,7 +196,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)