-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor existing backend code, optimize display for smaller screens
- Loading branch information
Showing
8 changed files
with
132 additions
and
85 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const OpenAI = require("openai"); | ||
require("dotenv").config(); | ||
|
||
// Initialize OpenAI with the API key | ||
const openai = new OpenAI({ | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
|
||
module.exports = openai; |
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,41 @@ | ||
const axios = require("axios"); | ||
const AdmZip = require("adm-zip"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
// Endpoint to download and cache a codebase | ||
const downloadCodebase = async (req, res) => { | ||
const { url } = req.body; | ||
|
||
if (!url) { | ||
return res.status(400).json({ error: "URL is required" }); | ||
} | ||
|
||
try { | ||
const response = await axios({ | ||
url, | ||
method: "GET", | ||
responseType: "arraybuffer", | ||
}); | ||
|
||
const zip = new AdmZip(response.data); | ||
const extractPath = path.join( | ||
path.resolve(__dirname, "../../"), // Navigate to the root directory and add the codebases directory | ||
"codebases", | ||
path.basename(url, ".zip"), | ||
); | ||
zip.extractAllTo(extractPath, true); | ||
|
||
res.json({ | ||
message: "Codebase downloaded and extracted", | ||
path: extractPath, | ||
}); | ||
} catch (error) { | ||
console.error("Error downloading codebase:", error); | ||
res.status(500).json({ error: "Failed to download codebase" }); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
downloadCodebase | ||
}; |
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,36 @@ | ||
const openai = require("../config/openaiConfig"); | ||
|
||
// Send a request to the ChatGPT API | ||
const getChatGPTResponse = async (req, res) => { | ||
const userInput = req.body.prompt; | ||
|
||
if (!userInput) { | ||
return res.status(400).json({ error: "Prompt is required" }); | ||
} | ||
|
||
if (!process.env.OPENAI_API_KEY) { | ||
return res.status(500).json({ error: "API key is missing" }); | ||
} | ||
|
||
try { | ||
const response = await openai.chat.completions.create({ | ||
model: "gpt-3.5-turbo", // Updated model name | ||
messages: [{ role: "user", content: userInput }], | ||
max_tokens: 150, | ||
}); | ||
|
||
const data = response.choices; | ||
if (data && data.length > 0) { | ||
res.json({ text: data[0].message.content.trim() }); | ||
} else { | ||
res.status(500).json({ error: "Invalid response from API" }); | ||
} | ||
} catch (error) { | ||
console.error("Error:", error); | ||
res.status(500).json({ error: "Something went wrong" }); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getChatGPTResponse | ||
}; |
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 express = require("express"); | ||
const { downloadCodebase } = require("../controllers/downloadCodebase"); | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/download", downloadCodebase); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const express = require("express"); | ||
const { getChatGPTResponse } = require("../controllers/gptController"); | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/chatgpt", getChatGPTResponse); | ||
|
||
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