Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Nov 16, 2024
2 parents bb727bb + 8062a53 commit bccb4be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 5 additions & 2 deletions services/openAI.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down Expand Up @@ -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 });
Expand Down
14 changes: 13 additions & 1 deletion services/transcriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -91,5 +102,6 @@ async function streamToBuffer(readableStream) {

module.exports = {
getBlobs,
deleteBlobs
deleteBlobs,
uploadBlob
}

0 comments on commit bccb4be

Please sign in to comment.