thorwhalen / oa

Python interface to OpenAi
Apache License 2.0
0 stars 0 forks source link

A way to be able to ignore the braces marked placeholders #7

Closed thorwhalen closed 5 months ago

thorwhalen commented 5 months ago

Sometimes (example, when giving json, or prompt template examples in prompt template) you need to not interpret braces as marking placeholders for inputs.

There's plenty of ways we can implement that, but for now, I propose a quick fix for this, which has the following behavior.

from oa import prompt_function

prompt_template = """
\```
In this block, all {placeholders} are {igno:red} so that they can appear in prompt.
\```
But outside {inputs} are {injected:normally}
"""

f = prompt_function(prompt_template, prompt_func=None)
from i2 import Sig
assert str(Sig(f)) == "(inputs, *, injected='normally')"

Note how neither {placeholders} nor {igno:red} show up in the function's signature!

Of course, the triple-backtick blocks will remain in the prompt template, therefore the prompt. Shouldn't be a problem, but if we think it might be, we can add an argument remove them (but in that case, we might want to add a specifier to denote which to remove (like ```remove_this_block...).