guidance
guidance copied to clipboard
[BUG/Feature request] Subexpressions are not supported for named parameters
The bug Guidance supports subexpressions, by which I mean the equivalently named feature for Handlebars (in parentheses):
{{function (function_two param)}}
However, the current implementation does not support the same functionality for named parameters. Hence, the above would work but not the following:
{{function param=(function_two param)}}
This will throw an error because this use-case is not a defined case in the grammar.
I think this could be argued either as a bug or a feature request depending on angle, but given that subexpressions for either case are a supported feature in handlebars (which we somewhat loosely claim parity with), the above is a deviation from expected behavior.
It creates issues with situations like {{#select options=(select_subfield_from_dict_that_is_an_array dict)}}
which otherwise forces users to place a dependency on the order of the arguments in the select function and hence is more prone to version breakages.
To Reproduce The following works:
def function(param):
return param+"faz"
def function_two(param):
return param+"bar"
p= guidance("""{{function (function_two param)}}""")
o= p(
function=function,
function_two=function_two,
param="foo"
)
and produces the expected result 'foobarfaz'
The following does not:
def function(param):
return param+"faz"
def function_two(param):
return param+"bar"
p= guidance("""{{function param=(function_two param)}}""")
o= p(
function=function,
function_two=function_two,
param="foo"
)
System info (please complete the following information):
- OS (e.g. Ubuntu, Windows 11, Mac OS, etc.): - OS (e.g. Ubuntu, Windows 11, Mac OS, etc.): Debian 11, both CPU and GPU inference
- Guidance Version (
guidance.__version__
): 0.0.61
For what it's worth, I'm willing to take a crack at implementing this.
Thanks for reporting this! That is indeed an oversight and should be supported. If you are willing to send a PR addressing it that would be great! I think the changes should just be in:
https://github.com/microsoft/guidance/blob/0f7be47a567f8c63b5eedf748385c63c4c0ee9e3/guidance/_grammar.py#L37-L38
We did away with handlebars in the new release. Hopefully f-strings still serve your purposes :)