Skip to content

Commit

Permalink
Merge pull request #210 from teamViNO/feature/video
Browse files Browse the repository at this point in the history
Feature/video
  • Loading branch information
jainefer authored Feb 19, 2024
2 parents cab6d8d + 30f845b commit 5aaefb8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"multer-s3": "^2.10.0",
"mysql2": "^3.7.0",
"nodemailer": "^6.9.8",
"openai": "^4.26.0",
"openai": "^4.28.0",
"redis": "^4.6.12",
"solapi": "^5.2.4",
"swagger-cli": "^4.0.4",
Expand Down
7 changes: 4 additions & 3 deletions src/controllers/summary.controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// src/controllers/summary.controller.js
import { getSummary, getTitle } from '../services/chatGPT.service.js';
import { fineTunningData, getSummary, getTitle } from '../services/chatGPT.service.js';
import { readFileFromObjectStorage } from '../services/storage.service.js';
import { getScriptFileName } from '../services/storage.service.js';
import { chatGPTCall } from '../services/chatGPT.service.js';
Expand Down Expand Up @@ -43,6 +43,7 @@ export const summary = async (req, res) => {
})
}
console.log("시간데이터 있는 데이터",timeStampData);
// const tempResult=await fineTunningData(JSON.stringify(timeStampData));
console.log(scriptText);

const summaryResult = await getSummary(scriptText);
Expand All @@ -54,12 +55,12 @@ export const summary = async (req, res) => {
console.log("summary json 데이터",summaryData);
//gpt 데이터
const gptResponse = await chatGPTCall(scriptText);

console.log("gpt받아온 데이터",gptResponse);
const startIndex = gptResponse.indexOf('{'); // 첫 번째 '{'의 인덱스 찾기
const trimmedResponse = gptResponse.substring(startIndex);
const gptData=JSON.parse(trimmedResponse);

console.log(gptResponse);


//유튜브 제목 요약
const titleData=await getTitle(videoTitle);
Expand Down
50 changes: 21 additions & 29 deletions src/services/chatGPT.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// src/services/chatGPTService.js
import axios from 'axios';
import dotenv from 'dotenv';
import OpenAI from 'openai';

dotenv.config();

Expand All @@ -13,39 +14,12 @@ export const chatGPTCall = async (scriptText) => {
// ChatGPT에 전달할 프롬프트를 구성합니다.
const system_prompt =
`Step 1. Look at the example Json given with the original script and give it to me in json. "subheading" is to break up the paragraphs of the given script according to the subtopics. The name of subheading is the title of the subtopic, and subheading.content should keep the original script divided according to the subtopic. subheading.name and subheading.content should be different. Add the contents in subheading together and we need to divide them so that the original script comes out. This subheading should be able to be at least 1 to highest 10 and contain all of the divided scripts. "tag" is the keyword for the overall scripts. Please indicate at least 2 to 5. The result should be in Korean. You need to have the above conditions and give them to the Json example below
{
"subheading": [
{
"name": "Subtitle 1",
"start_time": "script1 start time,"
"end_time": "script 1 end time",
"content": "script 1"
},{
"name": "Subtitle 2",
"start_time": "script2 start time,"
"end_time": "script 2 end time",
"content": "script 2"
}
],
"tag": [
{
"name": "Tag 1"
},
{
"name": "Tag 2"
},
{
"name": "Tag 3"
}
]
}
{"subheading": [{"name": "Subtitle 1","start_time": "script1 start time,""end_time": "script 1 end time","content": "script 1"},{"name": "Subtitle 2","start_time": "script2 start time","end_time": "script 2 end time","content": "script 2"}],"tag": [{"name": "Tag 1"},{"name": "Tag 2"},{"name": "Tag 3"}]}
`;

const prompt = `Run this script from step 1 , Make sure to fulfill the condition given to the system promport. original script: ${scriptText}\n ` ;


console.log("프롬프트",prompt);
const response = await axios.post(
OPENAI_API_URL,
{
Expand Down Expand Up @@ -205,3 +179,21 @@ export const getSummary = async (scriptText) => {
throw error;
}
};

export const fineTunningData = async (script)=>{
try {

const openai = new OpenAI({
apiKey: OPENAI_API_KEY
})

const result= await openai.completions.create({
prompt: script,
model:"ft:davinci-002:personal::8sC2Qcki",
max_tokens :8000
})
console.log("스크립트",result);
} catch (error) {
console.log(error);
}
}

0 comments on commit 5aaefb8

Please sign in to comment.