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

Build a JSON schema from a function's signature #355

Merged
merged 3 commits into from
Nov 13, 2023

Conversation

rlouf
Copy link
Member

@rlouf rlouf commented Nov 12, 2023

A common use case for JSON-guided generation is to extract values that are then passed to a function (see autonomous agents applications. This PR adds the possibility to extract the JSON specification from the signature of a function. Under the hood we create a Pydantic model from the extract argument names and type annotation.

The use interface is the following:

from outlines import models
from outlines.text import generate

def do_something_with_result(foo: str, bar: List[int]):
    pass

model = models.transformers("mistalai/Mistral-7b")

generator = generate.json(model, do_something_with_result)
args = generator("Generate arguments for the function")
do_something_with_result(**args)

Closes #350. Closes #351

TODO

@rlouf rlouf force-pushed the json-from-function-signature branch 2 times, most recently from 1f3f759 to 8023bbf Compare November 13, 2023 20:02
@rlouf rlouf force-pushed the json-from-function-signature branch 2 times, most recently from 3631894 to 6f0441b Compare November 13, 2023 20:49
@rlouf rlouf force-pushed the json-from-function-signature branch from 6f0441b to 97ecb6f Compare November 13, 2023 20:50
@rlouf rlouf merged commit 96773e1 into outlines-dev:main Nov 13, 2023
5 checks passed
@rlouf rlouf deleted the json-from-function-signature branch November 13, 2023 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant