mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
Add a toggle to turn custom prompt templating off (#1460)
This commit is contained in:
parent
448a64c383
commit
6a9085a71c
4 changed files with 24 additions and 1 deletions
|
|
@ -550,6 +550,7 @@ export const DEFAULT_SETTINGS: CopilotSettings = {
|
|||
inlineEditCommands: DEFAULT_INLINE_EDIT_COMMANDS,
|
||||
lastDismissedVersion: null,
|
||||
passMarkdownImages: true,
|
||||
enableCustomPromptTemplating: true,
|
||||
};
|
||||
|
||||
export const EVENT_NAMES = {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,8 @@ async function extractVariablesFromPrompt(
|
|||
.map((note) => `## ${note.name}\n\n${note.content}`)
|
||||
.join("\n\n");
|
||||
variablesMap.set(variableName, markdownContent);
|
||||
} else {
|
||||
} else if (variableName.toLowerCase() !== "activenote") {
|
||||
// Only log warning for non-activeNote variables
|
||||
console.warn(`No notes found for variable: ${variableName}`);
|
||||
}
|
||||
}
|
||||
|
|
@ -93,6 +94,11 @@ export async function processPrompt(
|
|||
vault: Vault,
|
||||
activeNote?: TFile | null
|
||||
): Promise<string> {
|
||||
const settings = getSettings();
|
||||
if (!settings.enableCustomPromptTemplating) {
|
||||
return customPrompt;
|
||||
}
|
||||
|
||||
const variablesMap = await extractVariablesFromPrompt(customPrompt, vault, activeNote);
|
||||
let processedPrompt = customPrompt;
|
||||
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ export interface CopilotSettings {
|
|||
isPlusUser: boolean | undefined;
|
||||
inlineEditCommands: InlineEditCommandSettings[] | undefined;
|
||||
passMarkdownImages: boolean;
|
||||
enableCustomPromptTemplating: boolean;
|
||||
}
|
||||
|
||||
export const settingsStore = createStore();
|
||||
|
|
@ -217,6 +218,11 @@ export function sanitizeSettings(settings: CopilotSettings): CopilotSettings {
|
|||
sanitizedSettings.passMarkdownImages = DEFAULT_SETTINGS.passMarkdownImages;
|
||||
}
|
||||
|
||||
// Ensure enableCustomPromptTemplating has a default value
|
||||
if (typeof sanitizedSettings.enableCustomPromptTemplating !== "boolean") {
|
||||
sanitizedSettings.enableCustomPromptTemplating = DEFAULT_SETTINGS.enableCustomPromptTemplating;
|
||||
}
|
||||
|
||||
return sanitizedSettings;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,16 @@ export const AdvancedSettings: React.FC = () => {
|
|||
/>
|
||||
|
||||
<div className="space-y-4">
|
||||
<SettingItem
|
||||
type="switch"
|
||||
title="Custom Prompt Templating"
|
||||
description="Enable templating to process variables like {activenote}, {foldername} or {#tag} in prompts. Disable to use raw prompts without any processing."
|
||||
checked={settings.enableCustomPromptTemplating}
|
||||
onCheckedChange={(checked) => {
|
||||
updateSetting("enableCustomPromptTemplating", checked);
|
||||
}}
|
||||
/>
|
||||
|
||||
<SettingItem
|
||||
type="switch"
|
||||
title="Images in Markdown (Plus)"
|
||||
|
|
|
|||
Loading…
Reference in a new issue