Skip to content

Commit

Permalink
Whisper
Browse files Browse the repository at this point in the history
  • Loading branch information
redji committed Mar 28, 2024
1 parent 7643b60 commit c509e1c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
6 changes: 5 additions & 1 deletion openAPI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ export async function moderations (input) {
export async function embedding(createObject) {
return await openai.embeddings.create(createObject);
}
export async function transcript(createObject) {
return await openai.audio.transcriptions.create(createObject);
}
export default {
moderations,
chatCompletion,
embedding
embedding,
transcript
}
53 changes: 51 additions & 2 deletions prompt.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import fetch from 'node-fetch';
//import shouldStringBeAllowed from './openAPI/moderation/moderate'
import { config } from 'dotenv';
import { chatCompletion, embedding } from './openAPI/index.js';
import { chatCompletion, embedding, transcript } from './openAPI/index.js';
import { makeRequestWithDelay } from './utils/makeRequest.js';
import FormData from 'form-data';
import axios from 'axios'
import fs from 'fs';
import path from 'path';


config();
const APIKey = process.env['API_KEY'];
const audioFilePath = new URL('mateusz.mp3', import.meta.url);

let moderationAnswer = [];
let blogAnswer = [];
let liarQuestion = "";
let liarAnswer = [];
let inpromptAnswer = [];
let embeddingAnswer = [];
let whisperAnswer = [];
//helloApi
fetch('https://tasks.aidevs.pl/token/helloapi', {
method: 'POST',
Expand Down Expand Up @@ -251,4 +255,49 @@ fetch('https://tasks.aidevs.pl/token/embedding', {
console.log('Answer from API', response4);
});
})
.catch(error => console.error('Error:', error));
.catch(error => console.error('Error:', error));
//whisper
fetch('https://tasks.aidevs.pl/token/whisper', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ apikey: APIKey })
})
.then(async (response) => {
const data = await response.json();
const token = data.token;
const taskUrl = `https://tasks.aidevs.pl/task/${token}`;
const response2 = await makeRequestWithDelay(taskUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}, 10);
console.log(response2);

// Read the audio file from the file system
const audioFileData = fs.createReadStream(audioFilePath);

// Transcribe audio
transcript({
model: 'whisper-1',
file: audioFileData,
response_format: 'text'
})
.then(async (response) => {
whisperAnswer = response
const response4 = await makeRequestWithDelay(`https://tasks.aidevs.pl/answer/${token}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({answer: whisperAnswer})
}, 10);
console.log('Answer from API', response4);
})
.catch(error => {
console.error('Error transcribing audio file:', error);
});
})
.catch(error => console.error('Error:', error));

0 comments on commit c509e1c

Please sign in to comment.