diff options
author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-08 13:47:53 -0400 |
---|---|---|
committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-08 13:47:53 -0400 |
commit | ca8a9125ee88cc633755d80ca6b3bb888a6dc7d7 (patch) | |
tree | 9d7191d3cfdfd8cae54a4d41ec2f5d8fb3103d55 /src/server/ApiManagers/AssistantManager.ts | |
parent | e297c75cdcc8bb5b1b138d1272f1f6f27b222f4c (diff) |
starting vectorstore
Diffstat (limited to 'src/server/ApiManagers/AssistantManager.ts')
-rw-r--r-- | src/server/ApiManagers/AssistantManager.ts | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/server/ApiManagers/AssistantManager.ts b/src/server/ApiManagers/AssistantManager.ts index f0ca983d7..77d8af724 100644 --- a/src/server/ApiManagers/AssistantManager.ts +++ b/src/server/ApiManagers/AssistantManager.ts @@ -147,21 +147,30 @@ export default class AssistantManager extends ApiManager { } }, }); - // register({ - // method: Method.POST, - // subscription: '/uploadPDF', - // secureHandler: async ({ req, res }) => { - // const { file_path } = req.body; - // const fullPath = path.join(publicDirectory, file_path); - // const fileData = createReadStream(fullPath); - // try { - // const response = await axios.post('http://localhost:8080/uploadPDF', { fileData }); - // res.send({ response: response }); - // } catch (error: any) { - // console.error('Error communicating with chatbot:', error); - // res.status(500).send({ error: 'Failed to communicate with the chatbot', details: error.message }); - // } - // }, - // }); + + register({ + method: Method.POST, + subscription: '/createDocument', + secureHandler: async ({ req, res }) => { + const { file_path } = req.body; + const public_path = path.join(publicDirectory, file_path); + const file_name = path.basename(file_path); + + try { + // Read file data and convert to base64 + const file_data = fs.readFileSync(public_path, { encoding: 'base64' }); + + const response = await axios.post('http://localhost:8080/createDocument', { + file_data, + file_name, + }); + + res.send({ document: response.data }); + } catch (error: any) { + console.error('Error communicating with chatbot:', error); + res.status(500).send({ error: 'Failed to communicate with the chatbot', details: error.message }); + } + }, + }); } } |