Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to activate system prompts #568

Open
tlindgren opened this issue Apr 27, 2024 · 11 comments
Open

Unable to activate system prompts #568

tlindgren opened this issue Apr 27, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@tlindgren
Copy link

I was really excited to see the new system prompts feature but I can't seem to get it to work and I'm not sure if I'm doing something wrong. I have a system prompts folder saved and a note in the folder, but when I add the @ button in the chat, nothing happens.

I'm using version 2.1.50.

Thanks

@brianpetro
Copy link
Owner

Hey @tlindgren

Thanks for letting me know about this.

I think the issue is that nothing is indicating that nothing is indicating that the system prompt is being used in the Smart Chat window. I just made a note about this to get it fixed.

However, the system prompt should still be utilized by the chat. There are a couple ways that you can confirm this:

  1. Click the button to the right of the name of the chat to open the chat history note. This note should include a "system" heading that contains the contents of your system prompt.

  2. Inspect the request object being logged to the console.

Here's a screenshot you can use for reference:
Screenshot 2024-04-26 at 11 26 00 PM

If you confirm the system prompt is being included via either of the above steps but you feel like the chat isn't respecting the instructions, then it would be worth trying another chat model since some models pay more attention to system prompts that others.

🌴

@tlindgren
Copy link
Author

Hi Brian,

Thanks for getting back to me on this. Maybe I should back up to confirm how the feature is supposed to work. I'm assuming that after I designate a system prompt folder in settings, adding @ in the chat should pop up a list of my system prompts from that folder and then I can select the one I want to use. Do I have that correct? Or is there a different way I should be selecting a prompt.

Tim

@brianpetro
Copy link
Owner

@tlindgren that is correct, it should look something like this 🌴
Screenshot 2024-04-27 at 1 39 57 PM

@tlindgren
Copy link
Author

Thanks, @brianpetro - here's what I'm seeing: https://vimeo.com/940101097/ed84772a9a?share=copy. When I type @, the prompts dialog doesn't appear as it does in your screenshot. N

Let me know if you need more details/info

Tim

@brianpetro
Copy link
Owner

@tlindgren, thanks for the screenshot, that helps me better see what's going on.

Are you copy & pasting the @ in the video?

What if you type it in without anything else in the input box, does it work then?

This feature is something that will be improved soon, but in the meantime, if you type the @ at the beginning without any other content it should work.

If it still doesn't work then, check the developer console because there should be an error there you can screenshot so we can figure it out.

🌴

@tlindgren
Copy link
Author

@brianpetro

I'm just typing in @, not copying and pasting.

These are the only errors I'm seeing in the console:

image

@brianpetro
Copy link
Owner

@tlindgren those errors are unrelated and are OK.

Which operating system are you using?

Does typing [[ open the file selection window?

Thanks for your help in solving this
🌴

@tlindgren
Copy link
Author

@brianpetro [[ and /folder/ both work fine. I'm Sonoma 14.4.1

@brianpetro
Copy link
Owner

@tlindgren interesting. I'm kind of stumped on this one then.

I'll let you know if I think of something.

🌴

@PaulArthurM
Copy link

@brianpetro

Hi,

I had a similar issue on Windows 11. But for me, both '[[' and '@' weren't working.

After some tries I found a workaround using 'keydown' instead of 'keyup'.

I'm not sure if this is the optimal solution, but it worked for me and may be a helpful starting point.

  • I used the 'keydown' event listener instead of 'keyup' to detect key presses.
  • I adjusted the conditions for checking the previous character when handling the '[[', '/', and '@' keys. I now check 'textarea.value[caret_pos - 1]' instead of 'textarea.value[caret_pos - 2]'.
  • I added 'e.preventDefault()' to prevent the default behavior of the keys when the conditions for opening the suggestion modals are met.
  • I modified the 'ScFileSelectModal', 'ScFolderSelectModal', and 'ScSystemPromptSelectModal' classes to include the corresponding characters ('[[', '/', '@') before the inserted text when an item is chosen from the suggestion modals.
      add_chat_input_listeners() {
        super.add_chat_input_listeners();
        const chat_input = this.container.querySelector(".sc-chat-form");
        this.brackets_ct = 0;
        this.prevent_input = false;
        chat_input.addEventListener("keydown", this.key_down_handler.bind(this));
      }
      key_down_handler(e) {
        const textarea = this.container.querySelector(".sc-chat-form textarea");
        if (!["/", "@", "["].includes(e.key)) return;
        const caret_pos = textarea.selectionStart;
      
        if (e.key === "[") {
          if (textarea.value[caret_pos - 1] === "[") {
            e.preventDefault();
            this.open_file_suggestion_modal();
            return;
          }
        } else {
          this.brackets_ct = 0;
        }
      
        if (e.key === "/") {
          if (textarea.value.length === 0 || textarea.value[caret_pos - 1] === " ") {
            e.preventDefault();
            this.open_folder_suggestion_modal();
            return;
          }
        }
      
        if (e.key === "@") {
          if (textarea.value.length === 0 || textarea.value[caret_pos - 1] === " ") {
            e.preventDefault();
            this.open_system_prompt_modal();
            return;
          }
        }
      }

I also had to change this part as well to add the '@' or '[' character before the inserted text:

    var ScFileSelectModal = class extends FuzzySuggestModal {
      constructor(app, env) {
        super(app);
        this.app = app;
        this.env = env;
        this.setPlaceholder("Type the name of a file...");
      }
      // get all markdown files
      getItems() {
        return this.app.vault.getMarkdownFiles().sort((a, b) => a.basename.localeCompare(b.basename));
      }
      getItemText(item) {
        return item.basename;
      }
      onChooseItem(file) {
        this.env.chat_ui.insert_selection("[" + file.basename + "]] ");
      }
    };
    var ScFolderSelectModal = class extends FuzzySuggestModal {
      constructor(app, env, folders) {
        super(app);
        this.app = app;
        this.env = env;
        this.folders = folders;
        this.setPlaceholder("Type the name of a folder...");
      }
      getItems() {
        return this.folders;
      }
      getItemText(item) {
        return item;
      }
      onChooseItem(folder) {
        this.env.chat_ui.insert_selection(folder + "/ ");
      }
    };
    var ScSystemPromptSelectModal = class extends FuzzySuggestModal {
      constructor(app, env) {
        super(app);
        this.app = app;
        this.env = env;
        this.setPlaceholder("Type the name of a system prompt...");
      }
      // getItems() { return this.env.system_prompts; }
      getItems() {
        return this.env.system_prompts;
      }
      getItemText(item) {
        return item.basename;
      }
      onChooseItem(prompt) {
        this.env.chat_ui.insert_selection('@"' + prompt.basename + '"');
      }
    };
  }

@linmaobang
Copy link

I succeeded, first to create a "smart prompts" folder, this folder name can be changed in the Settings, keep it same. can also create prompt command in this folder.Notice!!!!To use the @ command to bring up commands in the chat window, you need to hit the space bar before @! That's the key
微信截图_20240516100215
微信截图_20240516100239
微信截图_20240516100302
微信截图_20240516100342

@christianngarcia christianngarcia added the bug Something isn't working label May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants