From fb66bbd6a99320c7b0484020bae2c70772c90db8 Mon Sep 17 00:00:00 2001 From: Chetan baliyan Date: Tue, 15 Aug 2023 23:29:22 +0530 Subject: [PATCH] feat: add function to get image get querys with timestamp --- src/Editing/getImageQuerys.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/Editing/getImageQuerys.ts diff --git a/src/Editing/getImageQuerys.ts b/src/Editing/getImageQuerys.ts new file mode 100644 index 0000000..78c8e8d --- /dev/null +++ b/src/Editing/getImageQuerys.ts @@ -0,0 +1,33 @@ +import { Configuration, OpenAIApi } from 'openai' +import fs from 'fs' +import { exec } from 'child_process' +import { tryy } from '../promptTemplates/image' + +const configuration = new Configuration({ + apiKey: process.env.OPENAI_API, +}) +const openai = new OpenAIApi(configuration) + +export const getImageQuerys = async () => { + return new Promise((resolve, reject) => { + fs.readFile('/home/chetan/code/ts-content-gpt/basicaudio.wav.srt', 'utf8', async function (err, data) { + if (err) throw err + const chatCompletion: any = await openai.createChatCompletion({ + model: 'gpt-3.5-turbo', + messages: [{ role: 'system', content: tryy(data) }], + }) + // console.log('chatCompletion: ', chatCompletion.data.choices[0].message) + + // console.log(JSON.stringify(chatCompletion.data.choices[0].message?.content)[0]) + + const formattedString = chatCompletion.data.choices[0].message?.content.replace(/\\/g, '') // Remove escape characters + const jsonArray = JSON.parse(formattedString) + + // console.log('jsonArray: ', jsonArray) + + if (!jsonArray || jsonArray?.length === 0) return reject('No jsonArray found') + + resolve(jsonArray) + }) + }) +}