<%_* // Gemini API 키를 외부 파일에서 로드 (content 폴더 밖의 secrets.json) const secretsContent = await app.vault.adapter.read(“secrets.json”); const secrets = JSON.parse(secretsContent); const GEMINI_API_KEY = secrets.GEMINI_API_KEY; _%>

// 제목 생성을 위한 프롬프트 정의 (프롬프트 내용은 모델에 상관없이 동일하게 사용 가능) const title_prompt = `You are an expert at creating precise, information-dense titles for technical and business documents. Your task is to analyze the given Obsidian markdown note and generate a highly specific title that captures the essence of the content.

Analysis Framework:

  1. Document Classification:

    • Content Type (구현/연구/분석/제안/설계/운영)
    • Technical Depth (개념/응용/심화/실무)
    • Scope (PoC/프로토타입/프로덕션/연구)
    • Target Audience (개발자/아키텍트/비즈니스/운영)
  2. Core Components Analysis:

    • Primary Technology/Framework
    • Implementation Approach
    • Business Context
    • Problem Domain
    • Solution Architecture
  3. Title Structure Rules: Format: Domain Technology Implementation Context Example: LLM GPT4 PDF 문서처리 파이프라인 RAG 시스템 구축

Title Generation Guidelines:

Technical Elements:

  • Keep technical terms in English (RAG, LLM, API etc)
  • Include version numbers if relevant
  • Specify frameworks/tools used
  • Include architectural patterns

Formatting Requirements:

  • Use spaces as natural word delimiters
  • NO special characters (/:*?”<>|)
  • Keep total length under 60 characters
  • NO brackets or special formatting
  • Natural reading flow priority

Language Style:

  • End with 구현/설계/분석/연구/검토
  • Technical terms in English, context in Korean
  • Be specific about implementation details
  • Include quantitative metrics when relevant

[Output Requirements]

  • ONLY output the final title
  • NO explanations or alternatives
  • NO markdown formatting
  • Must follow the exact format specified
  • NEVER use following characters: /:*?”<>|[]
  • Use natural spaces between words

Remember:

  • Title should serve as a precise index for future reference and search while maintaining natural readability.
  • DO NOT wrap the title with double quotes. Just output the title.
  • DO NOT include any special characters such as ”/:*?”<>|[]“. ` _%>

<%_* // 현재 노트의 내용을 가져옵니다 const fileContent = tp.file.content;

// Gemini API를 호출하여 제목을 생성합니다 async function generateTitle(content) { // 사용할 Gemini 모델 설정 (gemini-1.5-flash는 빠르고 비용 효율적입니다) const model = “gemini-1.5-flash”; const url = https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${GEMINI_API_KEY};

// Gemini는 시스템 프롬프트와 사용자 입력을 하나로 합쳐서 전달합니다.
const full_prompt = `${title_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",
        // Gemini는 헤더에 인증 토큰을 사용하지 않습니다.
        // body에 요청 내용을 담습니다.
        body: JSON.stringify({
            contents: [{
                parts: [{
                    text: full_prompt
                }]
            }],
            // 필요시 생성 옵션 추가 (예: 온도, 최대 토큰 등)
            // generationConfig: {
            //   "temperature": 0.7,
            //   "maxOutputTokens": 100,
            // }
        })
    });
    
    // Gemini API의 응답 구조에 맞춰 파싱합니다.
    const resultText = response.json.candidates[0].content.parts[0].text;
    return resultText.trim();

} catch (error) {
    console.error('Gemini API 호출 중 오류 발생:', error);
    // Gemini API 에러 응답이 있을 경우, 더 자세한 내용을 출력합니다.
    if (error.response) {
        console.error('Gemini API Error Response:', await error.response.text());
    }
    return '제목 생성 실패';
}

}

// 제목을 생성하고 파일 이름을 변경합니다 const title = await generateTitle(fileContent); // 생성된 제목에서 금지된 문자를 제거합니다. const sanitizedTitle = title.replace(/[\/:*?”<>|[]]/g, ”); await tp.file.rename(sanitizedTitle); _%>