Skip to content

Commit

Permalink
[feat] fine tunning 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jainefer committed Feb 18, 2024
1 parent 2a1dd03 commit 3bcba04
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 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
21 changes: 20 additions & 1 deletion 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 Down Expand Up @@ -45,7 +46,7 @@ export const chatGPTCall = async (scriptText) => {

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 +206,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 3bcba04

Please sign in to comment.