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

[Feature Request] Instruct template automatic substitution #69

Open
bafterfor opened this issue May 31, 2024 · 7 comments
Open

[Feature Request] Instruct template automatic substitution #69

bafterfor opened this issue May 31, 2024 · 7 comments

Comments

@bafterfor
Copy link

It would be convenient for testing different instruct models in a single session, where if you select a different template, it would search and replace the prefixes/suffixes in the current session.

@lmg-anon
Copy link
Owner

lmg-anon commented Jun 1, 2024

That's not a bad idea, but you can use {inst}/{/inst} instead so that the template automatically changes the way you want it to. A big drawback is that to get a prompt 100% correct you would have to write everything on the same line, but I guess it would be worth trying to optionally make the prompt templates more forgiving for cases like this.

@neCo2
Copy link
Contributor

neCo2 commented Jun 1, 2024

It'd probably be a good idea (not to mention relatively simple) to remove all whitespace between the suffix {/inst} and the following prefix {inst}. That way you can have as many linebreaks as you want inbetween. I forgot how my own code works. Anyways, removing all whitespace before {inst} is something we could do.
Also maybe a toggle in the instruct modal to make chat mode append the placeholders instead of the plaintext templates.

@bafterfor
Copy link
Author

I could indeed use the {} strings, but yeah I like seeing the exact prompt being sent to the backend.
I also happen to have a lot of sessions currently that have specific formatting in them, from before the update that added Instruct templating, so this feature would also be nice for converting those older sessions.

@neCo2
Copy link
Contributor

neCo2 commented Jun 3, 2024

You can see the exact prompt with everything filled in that's being sent to the model in the context modal (Persistent Context > Show Context), but I see your point.

Problem I see with the replacing formats is that either we'd have to check the prompt for all of the registered instruct formats, or explicitly specify which format we want to replace, since we currently have no way of elegantly figuring out what format a prompt used.
I'm also not sure this is something that should run every time you change your template, since I imagine this could get pretty expensive for long texts. But I don't know enough about js performance to say this with certainty.
It could also get finicky if the format doesn't exactly match what's defined in the templates.

Maybe it could get its own modal or collapsible where you can select "find" and "replace with" templates in two dropdowns?

@lmg-anon
Copy link
Owner

lmg-anon commented Jun 3, 2024

Problem I see with the replacing formats is that either we'd have to check the prompt for all of the registered instruct formats, or explicitly specify which format we want to replace, since we currently have no way of elegantly figuring out what format a prompt used.

If necessary, I suggest we assume the last selected format is the correct one.

I'm also not sure this is something that should run every time you change your template, since I imagine this could get pretty expensive for long texts. But I don't know enough about js performance to say this with certainty.

I doubt the performance would be bad enough to matter, and imo performance should only be a consideration if the change could consistently impact React's render time.

It could also get finicky if the format doesn't exactly match what's defined in the templates.

I think the most robust way to handle this would be to parse the context with a function like this, then it would be simple enough to rewrite it using the new format.

Maybe it could get its own modal or collapsible where you can select "find" and "replace with" templates in two dropdowns?

+1 for a modal. But we could also add a checkbox to the instruct modal that says something like "Auto-replace old instruct format on change"

@bafterfor
Copy link
Author

A find and replace feature would be interesting even on its own. Some general text editor programs have this which makes replacing several things at the same time quite nice and easy.

@neCo2
Copy link
Contributor

neCo2 commented Jun 7, 2024

Started on a search and replace feature in #77.
As for the original point of this request, the function lmg-anon pointed out in his chat completions PR does look very solid. I'll be waiting on that to be merged before doing any template substitution stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants