From 923d98cae9daa9e53f18a184515ddc256b54c473 Mon Sep 17 00:00:00 2001 From: duanfuxiang Date: Thu, 3 Jul 2025 10:10:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=9A=E4=B8=AA=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=8F=90=E7=A4=BA=EF=BC=8C=E6=B7=BB=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AF=AD=E8=A8=80=E5=93=8D=E5=BA=94=E8=A6=81=E6=B1=82?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=88=A0=E9=99=A4=E4=B8=8D=E5=86=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E7=AE=80=E6=B4=81=E5=AF=86=E9=9B=86=E6=91=98?= =?UTF-8?q?=E8=A6=81=E6=8F=90=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/prompts/transformations/analyze-paper.ts | 5 ++++- .../transformations/concise-dense-summary.ts | 13 ------------- src/core/prompts/transformations/dense-summary.ts | 3 ++- .../prompts/transformations/hierarchical-summary.ts | 4 +++- src/core/prompts/transformations/key-insights.ts | 5 ++++- src/core/prompts/transformations/reflections.ts | 5 ++++- src/core/prompts/transformations/simple-summary.ts | 5 ++++- .../prompts/transformations/table-of-contents.ts | 5 ++++- src/core/transformations/trans-engine.ts | 13 +++---------- 9 files changed, 28 insertions(+), 30 deletions(-) delete mode 100644 src/core/prompts/transformations/concise-dense-summary.ts diff --git a/src/core/prompts/transformations/analyze-paper.ts b/src/core/prompts/transformations/analyze-paper.ts index 6170847..a43ef5d 100644 --- a/src/core/prompts/transformations/analyze-paper.ts +++ b/src/core/prompts/transformations/analyze-paper.ts @@ -31,6 +31,9 @@ You are an insightful and analytical reader of academic papers, extracting the k - Avoid starting each bullet point with the same word to maintain variety. - Use clear and concise language that conveys the key ideas effectively. - Do not include warnings, disclaimers, or personal opinions. -- Output only the requested sections with their respective labels.`; +- Output only the requested sections with their respective labels. + +You MUST respond in the {userLanguage} language. +`; export const ANALYZE_PAPER_DESCRIPTION = "Analyses a technical/scientific paper"; diff --git a/src/core/prompts/transformations/concise-dense-summary.ts b/src/core/prompts/transformations/concise-dense-summary.ts deleted file mode 100644 index f77d6f7..0000000 --- a/src/core/prompts/transformations/concise-dense-summary.ts +++ /dev/null @@ -1,13 +0,0 @@ -export const CONCISE_DENSE_SUMMARY_PROMPT = `# MISSION -You are a Sparse Priming Representation (SPR) writer. Your goal is to render the user's input as an extremely concise and distilled SPR. - -# THEORY -LLMs are a kind of deep neural network. They have been demonstrated to embed knowledge, abilities, and concepts, ranging from reasoning to planning, and even to theory of mind. These are called latent abilities and latent content, collectively referred to as latent space. The latent space of an LLM can be activated with the correct series of words as inputs, which will create a useful internal state of the neural network. You need to provide the most potent and succinct cues to prime another model effectively. Less is more. - -# METHODOLOGY -Render the input as a distilled list of the **most critical** assertions, concepts, and associations. The idea is to capture the absolute essence with minimal words. Use complete sentences. - -**!! CRITICAL INSTRUCTION !!** -**Your output MUST BE EXTREMELY CONCISE. Aim for a dense paragraph of no more than 3-5 sentences OR a bulleted list of 3-5 key points. Focus only on the highest-level insights and most essential concepts.**`; - -export const CONCISE_DENSE_SUMMARY_DESCRIPTION = "Creates an extremely concise, rich summary of the content focusing on the most essential concepts"; diff --git a/src/core/prompts/transformations/dense-summary.ts b/src/core/prompts/transformations/dense-summary.ts index 017646d..24ddb23 100644 --- a/src/core/prompts/transformations/dense-summary.ts +++ b/src/core/prompts/transformations/dense-summary.ts @@ -8,6 +8,7 @@ LLMs are a kind of deep neural network. They have been demonstrated to embed kno Render the input as a distilled list of the **most critical** assertions, concepts, and associations. The idea is to capture the absolute essence with minimal words. Use complete sentences. **!! CRITICAL INSTRUCTION !!** -**Your output MUST BE EXTREMELY CONCISE. Aim for a dense paragraph of no more than 3-5 sentences OR a bulleted list of 3-5 key points. Focus only on the highest-level insights and most essential concepts.**`; +**Your output MUST BE EXTREMELY CONCISE. Aim for a dense paragraph of no more than 3-5 sentences OR a bulleted list of 3-5 key points. Focus only on the highest-level insights and most essential concepts.** +You MUST respond in the {userLanguage} language.`; export const DENSE_SUMMARY_DESCRIPTION = "Creates an extremely concise, rich summary of the content focusing on the most essential concepts"; diff --git a/src/core/prompts/transformations/hierarchical-summary.ts b/src/core/prompts/transformations/hierarchical-summary.ts index d64f8a2..71a1ce5 100644 --- a/src/core/prompts/transformations/hierarchical-summary.ts +++ b/src/core/prompts/transformations/hierarchical-summary.ts @@ -9,6 +9,8 @@ You are an expert knowledge architect responsible for creating hierarchical summ 5. **Focus on Relationships**: Highlight how the different pieces of content relate to each other and what they collectively achieve or represent. **!! CRITICAL INSTRUCTION !!** -**Your output MUST BE CONCISE. Aim for 2-4 sentences that capture the essence and purpose of this directory as a cohesive unit. Focus on the highest-level insights and connections.**`; +**Your output MUST BE CONCISE. Aim for 2-4 sentences that capture the essence and purpose of this directory as a cohesive unit. Focus on the highest-level insights and connections.** +You MUST respond in the {userLanguage} language. +`; export const HIERARCHICAL_SUMMARY_DESCRIPTION = "Creates a concise, high-level summary that synthesizes content from multiple files and folders into a cohesive understanding of the directory's purpose and themes"; diff --git a/src/core/prompts/transformations/key-insights.ts b/src/core/prompts/transformations/key-insights.ts index 2b84829..a5b8b44 100644 --- a/src/core/prompts/transformations/key-insights.ts +++ b/src/core/prompts/transformations/key-insights.ts @@ -18,6 +18,9 @@ Take a step back and think step-by-step about how to achieve the best possible r - Do not give warnings or notes; only output the requested sections. - You use bulleted lists for output, not numbered lists. - Do not start items with the same opening words. -- Ensure you follow ALL these instructions when creating your output.`; +- Ensure you follow ALL these instructions when creating your output. + +You MUST respond in the {userLanguage} language. +`; export const KEY_INSIGHTS_DESCRIPTION = "Extracts important insights and actionable items"; diff --git a/src/core/prompts/transformations/reflections.ts b/src/core/prompts/transformations/reflections.ts index b6125b7..7b7aebe 100644 --- a/src/core/prompts/transformations/reflections.ts +++ b/src/core/prompts/transformations/reflections.ts @@ -16,6 +16,9 @@ You extract deep, thought-provoking, and meaningful reflections from text conten - The reflections should encourage deeper inquiry and provide a synthesis that transcends surface-level observations. - Use bullet points, not numbered lists. - Every bullet should be formatted as a question that elicits contemplation or a statement that offers a profound insight. -- Do not give warnings or notes; only output the requested section.`; +- Do not give warnings or notes; only output the requested section. + +You MUST respond in the {userLanguage} language. +`; export const REFLECTIONS_DESCRIPTION = "Generates reflection questions from the document to help explore it further"; diff --git a/src/core/prompts/transformations/simple-summary.ts b/src/core/prompts/transformations/simple-summary.ts index 5cc945d..adb11a8 100644 --- a/src/core/prompts/transformations/simple-summary.ts +++ b/src/core/prompts/transformations/simple-summary.ts @@ -5,7 +5,10 @@ You are a content summarization assistant that creates dense, information-rich s Analyze the provided content and create a summary that: - Captures the core concepts and key information - Uses clear, direct language -- Maintains context from any previous summaries`; +- Maintains context from any previous summaries + +You MUST respond in the {userLanguage} language. +`; export const SIMPLE_SUMMARY_DESCRIPTION = "Generates a small summary of the content"; diff --git a/src/core/prompts/transformations/table-of-contents.ts b/src/core/prompts/transformations/table-of-contents.ts index d161b52..619244c 100644 --- a/src/core/prompts/transformations/table-of-contents.ts +++ b/src/core/prompts/transformations/table-of-contents.ts @@ -5,6 +5,9 @@ Your ToC should capture all major topics and transitions in the content and shou # TASK Analyze the provided content and create a Table of Contents: - Captures the core topics included in the text -- Gives a small description of what is covered`; +- Gives a small description of what is covered + +You MUST respond in the {userLanguage} language. +`; export const TABLE_OF_CONTENTS_DESCRIPTION = "Describes the different topics of the document"; diff --git a/src/core/transformations/trans-engine.ts b/src/core/transformations/trans-engine.ts index ce94482..d57b96b 100644 --- a/src/core/transformations/trans-engine.ts +++ b/src/core/transformations/trans-engine.ts @@ -1,5 +1,5 @@ import { Result, err, ok } from "neverthrow"; -import { App, TFolder } from 'obsidian'; +import { App, TFolder, getLanguage } from 'obsidian'; import { DBManager } from '../../database/database-manager'; import { InsightManager } from '../../database/modules/insight/insight-manager'; @@ -8,10 +8,10 @@ import { LLMModel } from '../../types/llm/model'; import { RequestMessage } from '../../types/llm/request'; import { InfioSettings } from '../../types/settings'; import { readTFileContentPdf } from '../../utils/obsidian'; +import { getFullLanguageName } from '../../utils/prompt-generator'; import { tokenCount } from '../../utils/token'; import LLMManager from '../llm/manager'; import { ANALYZE_PAPER_DESCRIPTION, ANALYZE_PAPER_PROMPT } from '../prompts/transformations/analyze-paper'; -import { CONCISE_DENSE_SUMMARY_DESCRIPTION, CONCISE_DENSE_SUMMARY_PROMPT } from '../prompts/transformations/concise-dense-summary'; import { DENSE_SUMMARY_DESCRIPTION, DENSE_SUMMARY_PROMPT } from '../prompts/transformations/dense-summary'; import { HIERARCHICAL_SUMMARY_DESCRIPTION, HIERARCHICAL_SUMMARY_PROMPT } from '../prompts/transformations/hierarchical-summary'; import { KEY_INSIGHTS_DESCRIPTION, KEY_INSIGHTS_PROMPT } from '../prompts/transformations/key-insights'; @@ -68,7 +68,6 @@ class ConcurrencyLimiter { // 转换类型枚举 export enum TransformationType { DENSE_SUMMARY = 'dense_summary', - CONCISE_DENSE_SUMMARY = 'concise_dense_summary', HIERARCHICAL_SUMMARY = 'hierarchical_summary', ANALYZE_PAPER = 'analyze_paper', SIMPLE_SUMMARY = 'simple_summary', @@ -93,12 +92,6 @@ export const TRANSFORMATIONS: Record = description: DENSE_SUMMARY_DESCRIPTION, maxTokens: 4000 }, - [TransformationType.CONCISE_DENSE_SUMMARY]: { - type: TransformationType.CONCISE_DENSE_SUMMARY, - prompt: CONCISE_DENSE_SUMMARY_PROMPT, - description: CONCISE_DENSE_SUMMARY_DESCRIPTION, - maxTokens: 4000 - }, [TransformationType.HIERARCHICAL_SUMMARY]: { type: TransformationType.HIERARCHICAL_SUMMARY, prompt: HIERARCHICAL_SUMMARY_PROMPT, @@ -685,7 +678,7 @@ export class TransEngine { const messages: RequestMessage[] = [ { role: 'system', - content: transformationConfig.prompt + content: transformationConfig.prompt.replace('{userLanguage}', getFullLanguageName(getLanguage())) }, { role: 'user',