Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add function calling from {% completion %} #20

Merged
merged 11 commits into from
Oct 17, 2024
Merged

Conversation

masci
Copy link
Owner

@masci masci commented Oct 15, 2024

Working example:

import json

from banks import Prompt


def get_current_weather(location: str):
    """Get the current weather in a given location"""
    if "tokyo" in location.lower():
        return json.dumps({"location": "Tokyo", "temperature": "10", "unit": "celsius"})
    elif "san francisco" in location.lower():
        return json.dumps({"location": "San Francisco", "temperature": "72", "unit": "fahrenheit"})
    elif "paris" in location.lower():
        return json.dumps({"location": "Paris", "temperature": "22", "unit": "celsius"})
    else:
        return json.dumps({"location": location, "temperature": "unknown"})


p = Prompt("""
{% set response %}
{% completion model="gpt-3.5-turbo-0125" %}
    {% chat role="user" %}
           What's the weather like in {{ query }}?
    {% endchat %}
    {{ get_current_weather | tool }}
{% endcompletion %}
{% endset %}

{# the variable 'response' contains the result #}

{{ response }}
""")

print(p.text({"query": "Paris", "get_current_weather": get_current_weather}))

@coveralls
Copy link

coveralls commented Oct 15, 2024

Coverage Status

coverage: 95.748% (+1.2%) from 94.541%
when pulling 2cdbace on massi/function-calling
into 05194bb on main.

@masci masci merged commit ec125ab into main Oct 17, 2024
10 checks passed
@masci masci deleted the massi/function-calling branch October 17, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants