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

Add function calling support #38

Merged
merged 19 commits into from
Aug 25, 2023
Merged

Conversation

piercefreeman
Copy link
Owner

@piercefreeman piercefreeman commented Aug 24, 2023

gpt-3.5-turbo-0613 and gpt-4-0613 were fine-tuned to support a specific syntax for function calls. This PR adds support for these function calls, alongside typehinted support for their input arguments. For more information, see the README.

This PR is slightly backwards incompatible with 0.3.0. Instead of expanding the tuple list that is returned by gpt_json.run(), we migrate to a RunResponse object. This object will return the JSON object, fix transformations, and now the functions that were parsed from the response payload. If there was a failure in parsing, all the fields will be None. This saves users from having to independently parse the different response types.

Migrations should be straightforward.

# old syntax
response, _ = await gpt_json.run(...)
print(response)

# new syntax
payload = await gpt_json.run(...)
print(payload.response)

Because of JSON formatting and field parsing, this new function calling syntax only supports Pydantic V2. Early commits as part of this PR tried to keep compatibility with V1 and V2 but this proved more complicated than it's worth. We therefore move forward with Pydantic2-only compatibility. Clients who want to use Pydantic 1.x should lock their versions to <0.4.0.

@piercefreeman piercefreeman merged commit f8c92a2 into main Aug 25, 2023
3 checks passed
@piercefreeman piercefreeman deleted the feature/add-function-calling branch August 25, 2023 23:24
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.

1 participant