-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add function to get image get querys with timestamp
- Loading branch information
1 parent
e447a2b
commit fb66bbd
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
}) | ||
} |