Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/webtoon db #10

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"development": {
"username": "root",
"password": "37",
"database": "goorm",
"host": "34.64.161.162",
"dialect": "mysql"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
32 changes: 29 additions & 3 deletions controller/chatGpt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require('dotenv').config();
const fs = require('fs').promises;
// const { Models } = require('openai/resources');
const crawlControl = require("../crawling_kakao");
const apiKey = process.env.OPENAI_API_KEY;
const apiKey = process.env.OPENAI_API_KEY;
const models = require('../models');
// const feedbackModel = require('../models/feedback');

const chatGpiApi = async (req, res) => {

Expand Down Expand Up @@ -43,7 +46,7 @@ const chatGpiApi = async (req, res) => {

// 결과에서 comments 필드를 추출하여 message에 할당
const query_comments = crawlResult.comments.map((comment, index) => `comment ${index + 1}: ${comment}`).join('\n');
console.log(query_comments);
// console.log(query_comments);

const message = prompt + query_comments;
// 죄종 버전은 원샷 추가하기
Expand All @@ -70,13 +73,36 @@ const chatGpiApi = async (req, res) => {
const responseData = await response.json(); // 응답 데이터 가져오기
console.log(responseData)
const contentOnly = responseData.choices[0].message.content;

const gptFeedback = {
title: crawlResult.title,
contentNum: crawlResult.number,
subtitle: crawlResult.subtitle,
feedback: contentOnly
};
res.json(gptFeedback); // 클라이언트에 응답 반환

// 웹툰 생성
const createdWebtoon = await models.webtoon.create({
webtoon_title: crawlResult.title
});

// 생성된 웹툰의 ID 가져오기
const webtoonId = createdWebtoon.id;

// 데이터베이스에 저장
models.feedback.create({
link: url, // 링크
feedback: contentOnly, // 필터링된 댓글
subtitle: crawlResult.subtitle, // 소제목
webtoon_id: webtoonId // 웹툰 ID 추가
});

models.webtoon.create({
webtoon_title: crawlResult.title
});

// 클라이언트에 응답 반환
res.json(gptFeedback);

} catch (error) {
console.error('Error:', error);
Expand Down
2 changes: 2 additions & 0 deletions models/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = (sequelize, DataTypes) => {
}, {
sequelize,
modelName: 'feedback',
tableName: 'feedbacks',
timestamps: false
});
return feedback;
};
2 changes: 2 additions & 0 deletions models/webtoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module.exports = (sequelize, DataTypes) => {
}, {
sequelize,
modelName: 'webtoon',
tableName: 'webtoons',
timestamps: false
});
return webtoon;
};
Loading
Loading