From 75da491f42fd9219e7ca9aeca115713e20f0636f Mon Sep 17 00:00:00 2001 From: Barrca <60709314+FBarrca@users.noreply.github.com> Date: Wed, 29 Jan 2025 12:59:04 -0800 Subject: [PATCH] Actually add the prompts to the model --- src/api.ts | 3 ++- src/modules/commands/parser.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/modules/commands/parser.ts diff --git a/src/api.ts b/src/api.ts index 1506a6a..20821f0 100644 --- a/src/api.ts +++ b/src/api.ts @@ -6,6 +6,7 @@ import { InlineAISettings } from "./settings"; import { App, MarkdownView, Notice } from "obsidian"; import { EditorView } from "@codemirror/view"; import { setGeneratedResponseEffect } from "./modules/AIExtension"; +import { parseCommand } from "./modules/commands/parser"; /** * Class to manage interactions with different chat APIs. @@ -164,7 +165,7 @@ export class ChatApiManager { **Output:**`; } - return this.handleEditorUpdate(systemPrompt, userPrompt); + return this.handleEditorUpdate(systemPrompt, parseCommand(userPrompt, this.settings.commandPrefix, this.settings.customCommands)); } /** diff --git a/src/modules/commands/parser.ts b/src/modules/commands/parser.ts new file mode 100644 index 0000000..dd50744 --- /dev/null +++ b/src/modules/commands/parser.ts @@ -0,0 +1,12 @@ +import { SlashCommand } from "./source"; + + +export function parseCommand(userInput: string, prefix: string, customCommands: SlashCommand[]): string { +for (const command of customCommands) { + const commandPattern = `${prefix}${command.keyword}`; + if (userInput.startsWith(commandPattern)) { + return userInput.replace(commandPattern, command.prompt).trim(); + } +} +return userInput; // Return original text if no command matches +}