Skip to content

Commit

Permalink
♻️ refactor: claude api system pormpt를 변수로서 관리하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeVac513 committed Feb 13, 2025
1 parent ef17ef6 commit ce066fb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
4 changes: 2 additions & 2 deletions feed-crawler/src/claude.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<float>,\n "typescript": confidence<float>,\n "network": confidence<float>\n },\n "summary": summary<string>\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",
};
Expand Down
60 changes: 60 additions & 0 deletions feed-crawler/src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>,
"typescript": confidence<float>,
"network": confidence<float>
},
"summary": summary<string>
}
## 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")}
`;

0 comments on commit ce066fb

Please sign in to comment.