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

Allow to pass a function to generate.json #350

Closed
rlouf opened this issue Nov 11, 2023 · 0 comments · Fixed by #355
Closed

Allow to pass a function to generate.json #350

rlouf opened this issue Nov 11, 2023 · 0 comments · Fixed by #355

Comments

@rlouf
Copy link
Member

rlouf commented Nov 11, 2023

In most cases we want to do either of two things with the JSON generated by a model:

  1. Parse it, typically with a Pydantic BaseModel;
  2. Call a function with the values it contains.

In the second case the user would need to define a Pydantic model just for this purpose. We could make this easier by allowing users to pass a function to generate.json and generate the JSON Schema from the functions' signature.

import outlines.text as text
import outlines.models as models 


def do_something(foo: str, bar: List[int]):
    ...

model = models.transformers("gpt2")
res = text.generate.json(model, do_something)(prompt)
do_something(**res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant