-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from CS3219-AY2425S1/collab-bug-fixes
Collab Bug Fixes
- Loading branch information
Showing
12 changed files
with
154 additions
and
97 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.env | ||
|
||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
peerprep/backend/collab-service/src/controller/gptController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const axios = require('axios'); | ||
|
||
const assessCode = async (req, res) => { | ||
console.log('assessCode controller activated'); | ||
try { | ||
const { codeDetails } = req.body; | ||
if (!codeDetails) { | ||
res.status(400).json({ error: 'Code content is required' }); | ||
return; | ||
} | ||
|
||
const instructionalPrompt = | ||
"Analyze the following: 1: Question, and its 2: Description, and 3: The code attempt. " + "\n" + | ||
"Assess 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 and assess 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, codeDetails); | ||
|
||
// API request to OpenAI for code assessment | ||
const response = await axios.post( | ||
'https://api.openai.com/v1/chat/completions', | ||
{ | ||
model: 'gpt-4', | ||
messages: [ | ||
{ role: 'system', content: "You are a coding assistant." }, | ||
{ role: 'user', content: `${instructionalPrompt}\n\n${codeDetails}` } | ||
], | ||
temperature: 0 | ||
}, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` | ||
} | ||
} | ||
); | ||
|
||
const feedback = response.data.choices[0].message.content; | ||
res.json({ feedback }); | ||
} catch (error) { | ||
console.error('Error in assessCode controller:', error); | ||
res.status(500).json({ error: 'Failed to process code assessment' }); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
assessCode | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { Router } = require('express'); | ||
const { assessCode } = require('../controller/gptController'); | ||
|
||
const router = Router(); | ||
|
||
// Route for handling code assessment with GPT | ||
router.post('/gpt/assess', assessCode); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
peerprep/backend/question-service/src/controllers/gptController.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.