<%* // Gemini API 키 설정 const GEMINI_API_KEY=“AIzaSyAUyWPGBkl9fxpAh1O4uIGU87I2dpgSYOg”%>
<%_* // 프롬프트 정의 - 토픽 생성을 위한 프롬프트 const topics_prompt = `You are an expert in generating an appropriate topics properties that will be used in Obsidian Note. Your mission is to generate one or more topics suitable for given content. Your generated output must be comma-separated values.
Example Output:
📚 214 Document Parser, 📖 200 AI & Data, 📚 601 Enterprise Outsourcing Projects
Here’s a list of possible substitutions for topics. You must use these topics listed below:
Topics:
-
- 📚 201 Concepts
- 📚 202 Prompt
- 📚 203 Retriever
- 📚 204 Embedding
- 📚 205 LLM
- Ollama
- 📚 207 Vector DB
- 📚 208 Reranking
- 📚 209 Knowledge Graph
- 📚 210 Hybrid Search
- 📚 211 Evaluation
- 📚 212 HuggingFace
- 📚 213 Agent
- 📚 214 문서파서
- 📚 220 Fine-Tuning
- LangGraph
- 📚 222 vLLM
- 📚 230 데이터 분석
- 📚 231 머신러닝
- 📚 232 딥러닝 (pytorch)
- 📚 233 데이터 엔지니어링
- 📚 250 AI 서비스 구축
Example Output:
📚 214 Document Parser, 📖 200 AI & Data, 📚 601 Enterprise Outsourcing Projects
[Note] Write your Final Answer in Korean. DO NOT narrate, just write the output without any markdown formatting of wrapping. Generated topics must be related to the content. Otherwise, you will be penalized. ` _%>
<%_*
// frontmatter의 topics 속성을 업데이트하는 함수
const processTopics = async (file, newTopics) ⇒ {
await tp.app.fileManager.processFrontMatter(file, (frontmatter) ⇒ {
const topics = newTopics.split(’,‘).map(topic ⇒ topic.trim());
frontmatter.topics = topics.map(topic ⇒ ${topic});
});
};
_%>
<%_*
// Gemini API를 호출하여 토픽을 생성하는 함수
async function generateTopics(content) {
const model = “gemini-1.5-flash”;
const url = https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${GEMINI_API_KEY};
const full_prompt = ${topics_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 topics = await generateTopics(fileContent); const file = tp.config.target_file; await processTopics(file, topics); _%>