guidance-ai / guidance

A guidance language for controlling large language models.
MIT License
19.04k stars 1.04k forks source link

User-defined functions (handlebars helpers) do not work without passing in at least one argument #358

Closed jscheel closed 11 months ago

jscheel commented 1 year ago

The bug Handlebars helpers can be called without passing in arguments. However Guidance does not respect this as will instead pass the string representation of the function.

To Reproduce

import datetime
import openai
import guidance

openai.api_key = os.getenv("OPENAI_API_KEY")

gpt35 = guidance.llms.OpenAI("gpt-3.5-turbo")

def current_year():
    return datetime.datetime.now().year 

prog = guidance.Program("""
                        {{#user~}}
                        - Say the year "{{current_year}}" in roman numerals.
                        - Say nothing else but the roman numerals.
                        - If the year does not look like a year, say "FAIL".
                        {{~/user}}

                        {{#assistant~}}
                        {{gen 'answer' temperature=0 max_tokens=100}}
                        {{~/assistant}}
                        """, llm=gpt35)

prog(current_year=current_year)

Expected Behavior - Say the year "{{current_year}}" in roman numerals.

Actual Behavior - Say the year "<function current_year at 0x1253672e0>" in roman numerals.

System info (please complete the following information):

jscheel commented 1 year ago

I should say that the obvious solution is to call the function when you pass in the values. But ideally this would still behave.

marcotcr commented 11 months ago

Please check out our new release, where tool use is way better. Sorry it took us so long to get to it!

jscheel commented 11 months ago

@marcotcr awesome news!