<%* // Gemini API 키 설정 const GEMINI_API_KEY=“AIzaSyAUyWPGBkl9fxpAh1O4uIGU87I2dpgSYOg”%>
<%_* // 태그 생성을 위한 프롬프트 정의 const tag_prompt = `You are an expert at generating precise, SEO-optimized tags for technical and business documentation. Your task is to analyze the given content and create highly searchable tags that capture core concepts and technical elements.
Analysis Framework:
- Technical Classification:
- Primary Technologies (프레임워크/라이브러리/도구)
- Technical Concepts (알고리즘/아키텍처/패턴)
- Implementation Details (구현방식/메서드/기술스택)
- Domain Specifics (분야/산업/적용영역)
- Contextual Analysis:
- Business Value (ROI/성과/효율)
- Use Cases (활용사례/적용방안)
- Problem Domains (해결과제/니즈)
- Target Users (사용자/클라이언트)
- Tag Selection Criteria: Must Meet ALL Conditions:
- Explicitly appears in content
- Highly specific (no general terms)
- Technical precision
- Search optimization value
- Clear relation to core topic
Tag Generation Rules:
Technical Requirements:
- Keep technical terms in English (#RAG, LLM etc)
- Include version numbers when specific
- Use established technical terminology
- Maintain technical accuracy
Tag Structure:
- 1-10 tags only
- NO spaces within tags
- Korean preferred except for technical terms
- Compound words allowed for precision
- Follow established tech community conventions
Exclusion Rules:
- NO general/vague terms
- NO marketing buzzwords
- NO compound tags mixing Korean/English
- NO tags not present in content
- NO subjective descriptors
Quality Checks:
- Verify each tag appears in content
- Ensure searchability
- Check technical accuracy
- Validate specificity
- Confirm relevance
[Output Requirements]
- ONLY comma-separated tags
- Each tag starts with #
- NO explanations or alternatives
- Single line output
- NO markdown formatting
Example format: #RAG, 문서처리, 파이프라인, LangChain, 성능최적화
Remember:
- Tags must be precise, present in content, and highly searchable while maintaining technical accuracy.
- Generate maximum 10 tags. ` _%>
<%_*
// frontmatter의 tags 속성을 업데이트하는 함수
const processTags = async (file, newTags) ⇒ {
await tp.app.fileManager.processFrontMatter(file, (frontmatter) ⇒ {
const tags = newTags.split(’,‘).map(tag ⇒ tag.trim());
frontmatter.tags = tags.map(tag ⇒ ${tag});
});
};
_%>
<%_*
// Gemini API를 호출하여 태그를 생성하는 함수
async function generateTags(content) {
const model = “gemini-1.5-flash”;
const url = https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${GEMINI_API_KEY};
const full_prompt = ${tag_prompt}\n\nHere is the content of the note:\n${content};
try {
const response = await tp.obsidian.requestUrl({
method: "POST",
url: url,
contentType: "application/json",
body: JSON.stringify({
contents: [{ parts: [{ text: full_prompt }] }]
})
});
const resultText = response.json.candidates[0].content.parts[0].text;
return resultText.trim();
} catch (error)
{
console.error('Gemini API 호출 중 오류 발생:', error);
if (error.response) {
console.error('Gemini API Error Response:', await error.response.text());
}
return '태그 생성 실패';
}
}
// 현재 노트의 내용을 가져옵니다 const fileContent = tp.file.content;
// 태그를 생성하고 파일에 적용 const tags = await generateTags(fileContent); const file = tp.config.target_file; await processTags(file, tags); _%>