Skip to content
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
19 changes: 15 additions & 4 deletions routes/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const genAI = new GoogleGenerativeAI(process.env.GENERATIVE_AI_API_KEY);

router.post("/grade", async (req, res) => {
try {
// 프론트에서 prompt(프롬프트), user_answer(유저 답변) 둘 다 받기!
const { prompt, user_answer } = req.body;

if (!prompt || !user_answer) {
Expand All @@ -16,10 +15,8 @@ router.post("/grade", async (req, res) => {
.json({ error: "prompt와 user_answer 모두 필요합니다." });
}

// 최신 모델명 사용!
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

// prompt를 해당 위치에 동적으로 삽입!
const fullPrompt = `
너는 투자 교육 서비스의 채점자야. 아래 사용자 답변이 얼마나 구체적이고 정확한지를 기준별로 100점 만점 채점해줘.
차트 기술적 분석에 비중을 두고 채점해줘.
Expand Down Expand Up @@ -52,7 +49,21 @@ router.post("/grade", async (req, res) => {
const result = await model.generateContent(fullPrompt);
const text = result.response.text();

res.json({ result: text });
// JSON 파싱
const parsed = JSON.parse(text);

// score 재계산
const { breakdown } = parsed;
const calcScore =
(breakdown.logic || 0) +
(breakdown.technical || 0) +
(breakdown.macroEconomy || 0) +
(breakdown.marketIssues || 0) +
(breakdown.quantEvidence || 0);

parsed.score = calcScore;

res.json({ result: parsed });
} catch (e) {
console.error(e);
res.status(500).json({ error: "채점 실패" });
Expand Down
3 changes: 2 additions & 1 deletion routes/ranking.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ router.post("/day", async (req, res) => {
continue;

// 5. 점수 계산
const dailyScore =
const rawScore =
100 - (Math.abs(predObj.close - priceObj.close) / priceObj.close) * 100;
const dailyScore = Math.max(0, Math.round(rawScore));
await RealScore.findOneAndUpdate(
{ user_stock_id: pred.user_stock_id, date: yesterDay },
{ $set: { score: Math.round(dailyScore) } },
Expand Down