lmg-anon / mikupad

LLM Frontend in a single html file
https://lmg-anon.github.io/mikupad/mikupad.html
Creative Commons Zero v1.0 Universal
175 stars 24 forks source link

[Feature Request] Instruct template automatic substitution #69

Open bafterfor opened 1 month ago

bafterfor commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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.