LibreChat icon indicating copy to clipboard operation
LibreChat copied to clipboard

Feature: Prompt Library

Open ClaraLeigh opened this issue 2 years ago • 15 comments

Summary

A library of prompts by the LibreChat team + the ability to add your own prompts to share with other users of your app. This is different from presets as presets are on a per-user basis and can be edited. You could however save a library item as a preset.

How to use

I have written up a new docs page for this. See it here.

Screenshot

image

Changes

  • Adds a folder for prompt files in json format
  • Adds folder for users who want their own custom prompts
  • Adds button to EndpointMenu
  • Minor code cleanup for unused classes
  • Prep work for meilisearch
  • Confirmed styling in light & dark mode

Testing

I have performed various tests in my local & prod environment to ensure this works. I would love to create a unit test but I'm not sure I've done it with a component nested in a popup like this. I would rather change this to a whole page so unless anyone has any gripes with it, I'd rather hold off writing a test until we create page templates and have this as an actual page rather than popup.

Future Work (out of scope)

I added backend code to index all prompts to meilisearch. However I won't be finishing it in this PR is because I want to modify templates and even fix up the existing convo search to use instantsearch too. This seems a little time intensive + there is scope creep with it affecting more areas as we need to fix up the conversation search too so that it can have infinite scroll and a better search bar or filters.

The search I have made for this works pretty well as is, however we may notice performance issues if the number of prompts get to the thousands (I don't expect this to happen quickly)

Also we likely need to rethink the prompt window. Currently we can't change AI providers and we need to refactor things to get this working well.

Checklist

  • [x] My code adheres to this project's style guidelines
  • [x] I have performed a self-review of my own code
  • [x] I have commented in any complex areas of my code
  • [x] I have made pertinent documentation changes
  • [x] My changes do not introduce new warnings
  • [ ] I have written tests demonstrating that my changes are effective or that my feature works
  • [x] Local unit tests pass with my changes

ClaraLeigh avatar Aug 12 '23 01:08 ClaraLeigh

Note: failed unit tests look unrelated. Seems they pass occasionally, must be a problem elsewhere?

ClaraLeigh avatar Aug 14 '23 02:08 ClaraLeigh

Note: failed unit tests look unrelated. Seems they pass occasionally, must be a problem elsewhere?

are you able to run them locally? npm run test:api and npm run test:client

I think one of the errors said package-lock is out of sync, but if they are intermittent (i see one passing now) could be an npm outage, I had issues with this in the past

I have a script for rebuilding package-lock: npm run rebuild:package-lock

danny-avila avatar Aug 14 '23 03:08 danny-avila

Think that was the meilisearch being weird. Commented out and we can come back to it with a bigger search update. Tests passing now :)

ClaraLeigh avatar Aug 14 '23 03:08 ClaraLeigh

Think that was the meilisearch being weird. Commented out and we can come back to it with a bigger search update. Tests passing now :)

for this i found out the root issue and was solved by mocking meilisearch module in a specific test file

danny-avila avatar Aug 14 '23 21:08 danny-avila

Think that was the meilisearch being weird. Commented out and we can come back to it with a bigger search update. Tests passing now :)

for this i found out the root issue and was solved by mocking meilisearch module in a specific test file

@danny-avila awesome, should be an easy fix when I come back to the meilisearch and we end up using it. Definitely for the next PR on it tho.

Lmk if there is anything else to get this over the line, otherwise from my view it should definitely be enough for a quick first version

ClaraLeigh avatar Aug 15 '23 00:08 ClaraLeigh

Trying it out now, I can resolve the package-lock conflict for you if you give me contributor access to your fork.

Otherwise, you can try running the rebuild:package-lock script after you try rebasing/merging.

I tried running this on a clean install, and it would crash on opening the EndpointMenu

Steps to reproduce: fresh install by cloning down the repo, running installation, then:

# this would not work for me
# git clone [email protected]:ClaraLeigh/PromptLibrary.git prompts/General-Library

git clone https://github.com/ClaraLeigh/PromptLibrary.git prompts/General-Library

Run the app, hit endpoint menu to choose endpoint, then server crashes:

# server logs
There was an uncaught error:
TypeError: Cannot read properties of undefined (reading 'includes')
    at getTagsFromFilename (mydir\api\lib\utils\PromptLibrary.js:30:16)
    at mydir\api\lib\utils\PromptLibrary.js:54:13
    at Array.forEach (<anonymous>)
    at collatePromptLibrary (mydir\api\lib\utils\PromptLibrary.js:45:9)
    at mydir\api\server\routes\promptLibrary.js:8:31
    at Layer.handle [as handle_request] (mydir\node_modules\express\lib\router\layer.js:95:5)
    at next (mydir\node_modules\express\lib\router\route.js:144:13)
    at complete (mydir\node_modules\passport\lib\middleware\authenticate.js:271:13)
    at mydir\node_modules\passport\lib\middleware\authenticate.js:278:15        
    at pass (mydir\node_modules\passport\lib\authenticator.js:428:14)
Clearing sync timeouts before exiting...

All prompts are under prompts\General-Library

# prompts/General-Library
    |___/Advanced
    |___/Awesome
    |___/Coding
    |___.gitignore
# ...etc

Also cleared cookies/localStorage and was able to reproduce

danny-avila avatar Aug 15 '23 02:08 danny-avila

I can reproduce this issue, aswell

techwithanirudh avatar Aug 15 '23 04:08 techwithanirudh

@danny-avila windows? Might be a backslash thing. I'll see if I can test it somewhere

ClaraLeigh avatar Aug 15 '23 21:08 ClaraLeigh

@danny-avila windows? Might be a backslash thing. I'll see if I can test it somewhere

yup I am on windows, that could be it. maybe use path.resolve for os-agnostic solution

danny-avila avatar Aug 15 '23 23:08 danny-avila

Easy, I should have some time this weekend to finish it off then

ClaraLeigh avatar Aug 17 '23 22:08 ClaraLeigh

@ClaraLeigh Any updates on this P.R?

techwithanirudh avatar Oct 04 '23 08:10 techwithanirudh

@ClaraLeigh Any updates on this P.R?

I think I have a more upto date branch somewhere but it works expect on windows. I use it on my version. Still haven't had time of late to update for windows. Currently focused on some paid work atm that's taking all of my free time

ClaraLeigh avatar Oct 04 '23 22:10 ClaraLeigh

I think this is basically what I mean here: https://github.com/danny-avila/LibreChat/issues/1016 as well

frankhommers avatar Oct 26 '23 15:10 frankhommers

This looks great and the Tree of Thoughts prompt output blew my mind :)

Question: when importing the prompt definitions, I kept needing to change the endpoint and model to work with my configuration (Azure and GPT-4), because most of the definitions are for openAI and gpt-3.5-turbo. Is the plan perhaps that these fields will be optional and if empty, when you select the prompt it will continue to use the currently selected endpoint?

drittich avatar Nov 20 '23 05:11 drittich

Looks like something I was looking for but the code is not compatible with latest update. any plan on updating this feature?

nbhadauria avatar Dec 21 '23 01:12 nbhadauria

Though I closed this PR, prompt features are on the roadmap. Possibly next month if stretch goals are met. Things may accelerate if I can work on this project full-time.

danny-avila avatar Jan 19 '24 19:01 danny-avila

I will look forward to update on prompt features, although I don't see any other planned features looking as good as this :)

nbhadauria avatar Jan 22 '24 03:01 nbhadauria

Glad to here this is still on the roadmap. This was one of my favorite features I was looking forward to

bsu3338 avatar Jan 24 '24 03:01 bsu3338

Agreed, this feature would be really helpful!

fret423 avatar Mar 14 '24 08:03 fret423

Great work @ClaraLeigh, any plans to work on this again?

ndrsfel avatar Mar 14 '24 09:03 ndrsfel