llm icon indicating copy to clipboard operation
llm copied to clipboard

Fix support for Python template syntax

Open jeeger opened this issue 1 year ago • 3 comments

All dollar signs in a template's prompt or system values are interpreted as introducing placeholders. The documentation for string.Template says that doubling a dollar sign should escape it.

Due to the custom implementation of Template.extract_vars, this did not work, as it extracted a double dollar sign as an identifier with an empty named group. By using string.Template.get_identifiers() instead, this now works. Additionally, this automatically adds support for parenthesized identifiers as well.

jeeger avatar Feb 28 '24 10:02 jeeger

Tests failed on Python 3.8:

llm/templates.py:54: in Template
    def extract_identifiers(cls, template: string.Template) -> list[str]:
E   TypeError: 'type' object is not subscriptable

I'll fix that now.

simonw avatar Mar 09 '24 19:03 simonw

Sorry for the bad code, I should figure out how to run the tests locally.

jeeger avatar Mar 18 '24 08:03 jeeger

There, that should do it. Sorry for the noise, I was apparently coding on half a brain last week.

jeeger avatar Mar 18 '24 08:03 jeeger