-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_raw.js
37 lines (30 loc) · 1.11 KB
/
index_raw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { Configuration, OpenAIApi } = require("openai");
const ytb_prompt = require("./ytb_prompt");
const getSubtitles = require("youtube-captions-scraper").getSubtitles;
require("dotenv").config();
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
getSubtitles({
videoID: "IG0J_ynkemI", // youtube video id
lang: "en", // default: `en`
}).then(function (captions) {
// let result = captions.map(
// ({ start, text }) => `${text} (start time: ${start})`
// );
let result = captions.map(({ text }) => text).join(" ");
// call(result);
console.log(result);
});
async function call(prompt) {
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "resume the following youtube video text transcription: " + prompt,
max_tokens: 14000,
temperature: 0,
});
//console.log the resul from the response object
//trimStart() is used only for styling purpose to remove the default initial spaces from the text response
console.log(response.data.choices[0].text.trimStart());
}