diff --git a/services/openAI.js b/services/openAI.js index 022df39..edc3d2a 100644 --- a/services/openAI.js +++ b/services/openAI.js @@ -1,6 +1,7 @@ const config = require('../config') -const { AzureOpenAI } = require('openai') -const moment = require('moment') +const { AzureOpenAI } = require('openai'); +const moment = require("moment"); +const TranscriptionsService = require('../services/transcriptions') require('moment/locale/es') moment.locale('es') @@ -62,6 +63,8 @@ async function uploadFileToVectorStore(json, formattedDate, origin) { type: 'application/json', }); + await TranscriptionsService.uploadBlob(filename, json) + const files = []; for await (const file of assistantsClient.files.list()) { files.push({id: file.id, name: file.filename }); diff --git a/services/transcriptions.js b/services/transcriptions.js index 3627176..9dddc32 100644 --- a/services/transcriptions.js +++ b/services/transcriptions.js @@ -2,6 +2,7 @@ const { BlobServiceClient } = require('@azure/storage-blob'); const moment = require('moment'); const config = require('../config') const {Buffer} = require("buffer"); +const { Readable } = require('stream'); async function deleteBlobs (blobNames) { const blobServiceClient = BlobServiceClient.fromConnectionString(config.blobStorage.connectionString); @@ -16,6 +17,16 @@ async function deleteBlobs (blobNames) { } } +async function uploadBlob (filename, json){ + const blobServiceClient = BlobServiceClient.fromConnectionString(config.blobStorage.connectionString) + const containerClient = blobServiceClient.getContainerClient(config.blobStorage.containerName) + const blockBlobClient = containerClient.getBlockBlobClient(filename) + + const readableStream = Readable.from([json]) + const uploadBlobResponse = await blockBlobClient.uploadStream(readableStream) + console.log(`Upload block blob ${filename} successfully`, uploadBlobResponse.requestId) +} + async function getBlobs() { const blobServiceClient = BlobServiceClient.fromConnectionString(config.blobStorage.connectionString); const containerClient = blobServiceClient.getContainerClient(config.blobStorage.containerName); @@ -91,5 +102,6 @@ async function streamToBuffer(readableStream) { module.exports = { getBlobs, - deleteBlobs + deleteBlobs, + uploadBlob }