Skip to content

Commit

Permalink
Api to update prompt_history
Browse files Browse the repository at this point in the history
  • Loading branch information
Amruth-Vamshi committed Nov 9, 2023
1 parent c516356 commit 733b534
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/modules/pdf/pdf.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export class PDFController {
message: `${error.message}`
}
}

}

@Post('create-or-update-employee')
Expand Down Expand Up @@ -255,4 +254,56 @@ export class PDFController {
}
return "Error Occurred, Unable to add employee data";
}

@Post('addSimilarQuestions')
@UseInterceptors(
FastifyFileInterceptor('file', {
storage: diskStorage({
destination: './files',
filename: editFileName,
}),
fileFilter: csvFileFilter,
})
)
async addSimilarQuestions(@UploadedFile() file: Express.Multer.File, @Body() body: any){
const csvFilePath = path.join(__dirname, `../../../files/${file.filename}`);
let data = await this.pdfService.processCSV(csvFilePath)
await unlink(csvFilePath)
try {
for(let i=0;i<data.length;i++){
let embedding = (await this.aiToolsService.getEmbedding(data[i].queryInEnglish))[0];
let prompt = await this.prisma.prompt_history.upsert({
where: {
queryInEnglish: data[i].queryInEnglish
},
create:{
responseTime: 0,
queryInEnglish: data[i].queryInEnglish,
responseInEnglish: data[i].responseInEnglish,
timesUsed: 0
},
update:{
responseTime: 0,
queryInEnglish: data[i].queryInEnglish,
responseInEnglish: data[i].responseInEnglish,
timesUsed: 0
}
})
await this.prisma.$queryRawUnsafe(
`UPDATE prompt_history
SET "embedding" = '[${embedding
.map((x) => `${x}`)
.join(",")}]'
WHERE "id" = ${prompt.id}`
);
}
return {
message: `Questions uploaded successfully.`
}
} catch (error) {
return {
message: `${error.message}`
}
}
}
}

0 comments on commit 733b534

Please sign in to comment.