Skip to content

Commit

Permalink
update seeding/caching function to allow for multiple users on the fl…
Browse files Browse the repository at this point in the history
…y.io server
  • Loading branch information
aliiyuu committed Aug 22, 2024
1 parent 07f3c35 commit 18ca7c3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions frontend/src/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,13 @@ export async function fetchChatGPTResponse(userInput) {
const ec2 = "https://18.226.98.245:443";
const local = "http://localhost:3000";
const apiURL = "https://syntaxsorcerer-backend.fly.dev";
const codebasePath = "../../codebases";

const response = await fetch(`${apiURL}/api/chatgpt`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ prompt: userInput, codebasePath }),
body: JSON.stringify({ prompt: userInput }),
});

const botMessage = await response.json();
Expand Down
6 changes: 2 additions & 4 deletions server/controllers/deleteCodebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@ const fs = require("fs");
const fsp = require("fs/promises");
const path = require("path");
const pinecone = require('../config/pineconeConfig/pineconeInit');
const seed = require('../config/seedConfig');

const deleteCodebase = async (req, res) => {
const codebasePath = path.join(
path.resolve(__dirname, "../../"),
"codebases",
`codebases${seed}`
);

if (!fs.existsSync(codebasePath)) {
return res.status(400).json({ error: "No codebase currently cached" });
}

try {
const files = await fsp.readdir(codebasePath);
await fsp.rm(codebasePath, { recursive: true, force: true });

// Delete everything from the Pinecone namespace
const index = "syntaxsorcerer";
const namespace = "codebase"; // Default for our project
await pinecone.deleteVectorsFromNamespace();


Expand Down
5 changes: 3 additions & 2 deletions server/controllers/downloadCodebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const AdmZip = require("adm-zip");
const fs = require("fs");
const path = require("path");
const processFile = require('../database/processFile');
const seed = require('../config/seedConfig');

// Endpoint to download and cache a codebase
const downloadCodebase = async (req, res) => {
Expand All @@ -11,7 +12,7 @@ const downloadCodebase = async (req, res) => {
// Print an error message if the codebase already exists
const codebasePath = path.join(
path.resolve(__dirname, "../../"),
"codebases"
`codebases${seed}`
);
if (fs.existsSync(codebasePath)) {
return res.status(400).json({ error: "Codebase already cached; please delete it if you want to upload a new one" });
Expand All @@ -31,7 +32,7 @@ const downloadCodebase = async (req, res) => {
const zip = new AdmZip(response.data);
const extractPath = path.join(
path.resolve(__dirname, "../../"), // Navigate to the root directory and add the codebases directory
"codebases",
`codebases${seed}`,
path.basename(url, ".zip"),
);
zip.extractAllTo(extractPath, true);
Expand Down
5 changes: 3 additions & 2 deletions server/controllers/pineconeQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ const {generateEmbeddings, processAndUpdateDictionary} = require("../database/e
const fs = require("fs");
const path = require("path");
const readCodeFromFile = require('../database/readCodeFromFile');
const seed = require('../config/seedConfig');

const getPineconeResponse = async (req, res) => {
const userInput = req.body.prompt;

// Print an error message if the codebase doesn't exist
const codebasePath = path.join(
path.resolve(__dirname, "../../"),
"codebases"
`codebases${seed}`
);
if (!fs.existsSync(codebasePath)) {
return res.json({ text: "You haven't uploaded a codebase yet! Please try again." });
}

shortPath = "../codebases/";
shortPath = `../codebases${seed}/`;

if (!userInput) {
return res.status(400).json({ error: "Input is required" });
Expand Down

0 comments on commit 18ca7c3

Please sign in to comment.