Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
move more prompts to the constants file
perf3cta50575c12c3e
diff --git a/src/services/llm/chat_service.ts b/src/services/llm/chat_service.tsindex 8dc6b67272..f2ba2bc689 100644--- a/src/services/llm/chat_service.ts+++ b/src/services/llm/chat_service.ts@@ -2,6 +2,7 @@ import type { Message, ChatCompletionOptions } from './ai_interface.js';import aiServiceManager from './ai_service_manager.js';import chatStorageService from './chat_storage_service.js';import log from '../log.js';+import { CONTEXT_PROMPTS } from './constants/llm_prompt_constants.js';export interface ChatSession {id: string;@@ -132,7 +133,10 @@ export class ChatService {// Add error message so user knows something went wrongconst errorMessage: Message = {role: 'assistant',- content: `Error: Failed to generate response. ${error.message || 'Please check AI settings and try again.'}`+ content: CONTEXT_PROMPTS.ERROR_MESSAGES.GENERAL_ERROR.replace(+ '{errorMessage}',+ error.message || 'Please check AI settings and try again.'+ )};session.messages.push(errorMessage);@@ -177,7 +181,7 @@ export class ChatService {const contextMessage: Message = {role: 'user',- content: `Here is the content of the note I want to discuss:\n\n${context}\n\nPlease help me with this information.`+ content: CONTEXT_PROMPTS.NOTE_CONTEXT_PROMPT.replace('{context}', context)};session.messages.push(contextMessage);@@ -203,7 +207,9 @@ export class ChatService {const contextMessage: Message = {role: 'user',- content: `Here is the relevant information from my notes based on my query "${query}":\n\n${context}\n\nPlease help me understand this information in relation to my query.`+ content: CONTEXT_PROMPTS.SEMANTIC_NOTE_CONTEXT_PROMPT+ .replace('{query}', query)+ .replace('{context}', context)};session.messages.push(contextMessage);@@ -261,7 +267,10 @@ export class ChatService {// Prepend a system message with contextconst systemMessage: Message = {role: 'system',- content: `You are an AI assistant helping with Trilium Notes. Use this context to answer the user's question:\n\n${enhancedContext}`+ content: CONTEXT_PROMPTS.CONTEXT_AWARE_SYSTEM_PROMPT.replace(+ '{enhancedContext}',+ enhancedContext+ )};// Create messages array with system message@@ -307,7 +316,10 @@ export class ChatService {// Add error messageconst errorMessage: Message = {role: 'assistant',- content: `Error: Failed to generate response with note context. ${error.message || 'Please try again.'}`+ content: CONTEXT_PROMPTS.ERROR_MESSAGES.CONTEXT_ERROR.replace(+ '{errorMessage}',+ error.message || 'Please try again.'+ )};session.messages.push(errorMessage);diff --git a/src/services/llm/constants/llm_prompt_constants.ts b/src/services/llm/constants/llm_prompt_constants.tsindex 690d12472e..e6dcf08f34 100644--- a/src/services/llm/constants/llm_prompt_constants.ts+++ b/src/services/llm/constants/llm_prompt_constants.ts@@ -83,7 +83,32 @@ Now, based on the above information, please answer: {query}`,// Context for index serviceINDEX_NO_NOTES_CONTEXT:- "I'm an AI assistant helping with your Trilium notes. I couldn't find specific notes related to your query, but I'll try to assist based on general knowledge."+ "I'm an AI assistant helping with your Trilium notes. I couldn't find specific notes related to your query, but I'll try to assist based on general knowledge.",++ // Prompt for adding note context to chat+ NOTE_CONTEXT_PROMPT: `Here is the content of the note I want to discuss:++{context}++Please help me with this information.`,++ // Prompt for adding semantic note context to chat+ SEMANTIC_NOTE_CONTEXT_PROMPT: `Here is the relevant information from my notes based on my query "{query}":++{context}++Please help me understand this information in relation to my query.`,++ // System message prompt for context-aware chat+ CONTEXT_AWARE_SYSTEM_PROMPT: `You are an AI assistant helping with Trilium Notes. Use this context to answer the user's question:++{enhancedContext}`,++ // Error messages+ ERROR_MESSAGES: {+ GENERAL_ERROR: `Error: Failed to generate response. {errorMessage}`,+ CONTEXT_ERROR: `Error: Failed to generate response with note context. {errorMessage}`+ }};// Agent tool prompts