From ce066fbddc2c29302d3e971ed4611cb30de21031 Mon Sep 17 00:00:00 2001 From: codeVac513 Date: Thu, 13 Feb 2025 16:01:30 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20claude=20api?= =?UTF-8?q?=20system=20pormpt=EB=A5=BC=20=EB=B3=80=EC=88=98=EB=A1=9C?= =?UTF-8?q?=EC=84=9C=20=EA=B4=80=EB=A6=AC=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feed-crawler/src/claude.service.ts | 4 +- feed-crawler/src/common/constant.ts | 60 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/feed-crawler/src/claude.service.ts b/feed-crawler/src/claude.service.ts index 3ec4ab9a..9dab9a57 100644 --- a/feed-crawler/src/claude.service.ts +++ b/feed-crawler/src/claude.service.ts @@ -4,6 +4,7 @@ import { ClaudeResponse, FeedDetail } from "./common/types"; import { TagMapRepository } from "./repository/tag-map.repository"; import { FeedRepository } from "./repository/feed.repository"; import logger from "./common/logger"; +import { PROMPT_CONTENT } from "./common/constant"; @injectable() export class ClaudeService { @@ -24,8 +25,7 @@ export class ClaudeService { try { const params: Anthropic.MessageCreateParams = { max_tokens: 8192, - system: - 'You need to assign tags and provide a summary of the content.\nThe input format is XML.\nRemove the XML tags and analyze the content.\n\nThe language of the content is Korean.\nAnalyze the content and assign 0 to 5 relevant tags.\nOnly assign tags that have at least 90% relevance to the content.\n\nIf no tag has 90% relevance or more, return:\ntags: { }\n\nThe summary of the content should be returned in the summary field.\nThe summary must be in Korean.\nWhen summarizing, make it engaging and intriguing so that a first-time reader would want to click on the original post.\n\nIf possible, organize the summary using Markdown format.\n\nOutput Format:\nYou must respond with raw JSON only, without any code blocks or backticks. \nThe output should be in JSON format only, containing tags, relevance, and summary.\nDo not wrap the response in code blocks.\nDo not provide any additional explanations.\nDo not use any markdown formatting for the JSON output itself.\n\nThe response should look exactly like this, without any surrounding characters:\n{\n "tags": {\n "javascript": confidence,\n "typescript": confidence,\n "network": confidence\n },\n "summary": summary\n}\n\n## Do not assign any tags that are not in the predefined tag list.\nStrictly follow this rule.\n\nTag List:\n회고\nFrontend\nBackend\nDB\nNetwork\nOS\nAlgorithm\nInfra\nSoftware Engineer\nTypeScript\nJavaScript\nJava\nReact\nVue.JS\nNest.JS\nExpress.JS\nSpring\nMySQL\nSQLite\nPostgreSQL\nMongoDB\nRedis\nDocker', + system: PROMPT_CONTENT, messages: [{ role: "user", content: feed.content }], model: "claude-3-5-haiku-latest", }; diff --git a/feed-crawler/src/common/constant.ts b/feed-crawler/src/common/constant.ts index 6fe7363d..8cae7da7 100644 --- a/feed-crawler/src/common/constant.ts +++ b/feed-crawler/src/common/constant.ts @@ -12,3 +12,63 @@ export const INTERVAL = process.env.NODE_ENV === "test" ? parseInt(process.env.TEST_TIME_INTERVAL) : parseInt(process.env.TIME_INTERVAL); + +export const ALLOWED_TAGS = [ + "회고", + "Frontend", + "Backend", + "DB", + "Network", + "OS", + "Algorithm", + "Infra", + "Engineering", + "TypeScript", + "JavaScript", + "Java", + "React", + "Vue.JS", + "Nest.JS", + "Express.JS", + "Spring", + "MySQL", + "SQLite", + "PostgreSQL", + "MongoDB", + "Redis", + "Docker", +]; + +export const PROMPT_CONTENT = `[System] +You need to assign tags and provide a summary of the content. +The input format is XML. +Remove the XML tags and analyze the content. +The language of the content is Korean. +Analyze the content and assign 0 to 5 relevant tags. +Only assign tags that have at least 90% relevance to the content. +If no tag has 90% relevance or more, return: +tags: { } +The summary of the content should be returned in the summary field. +The summary must be in Korean. +When summarizing, make it engaging and intriguing so that a first-time reader would want to click on the original post. +If possible, organize the summary using Markdown format. +Output Format: +You must respond with raw JSON only, without any code blocks or backticks. +The output should be in JSON format only, containing tags, relevance, and summary. +Do not wrap the response in code blocks. +Do not provide any additional explanations. +Do not use any markdown formatting for the JSON output itself. +The response should look exactly like this, without any surrounding characters: +{ + "tags": { + "javascript": confidence, + "typescript": confidence, + "network": confidence + }, + "summary": summary +} +## Do not assign any tags that are not in the predefined tag list. +Strictly follow this rule. +Tag List: +${ALLOWED_TAGS.map((tag) => `- ${tag}`).join("\n")} +`;