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

Define end-to-end applications #413

Merged
merged 2 commits into from
Dec 13, 2023
Merged

Conversation

rlouf
Copy link
Member

@rlouf rlouf commented Dec 7, 2023

In this PR we allow users to define end-to-end functions from a prompt template, a Pydantic model and a model name (that can be downloaded from the Hugging Face hub):

import outlines


@outlines.prompt
def test_template(text: str):
    """{{ text }}"""


class Foo(BaseModel):
    id: int


fn = outlines.Function(test_template, Foo, "gpt2")

These functions can then be executed, and imported by another module:

from .foo import function as foo_fn

result = foo_fn("A prompt")

I also added a from_github classmethod that allows to directly download a function from a github repository:

import outlines

fn = outlines.Function.from_github("outlines-dev/outlines/chain_of_density")

which looks for a variable named fn in the chain_of_density.py file in the outlines-dev/outlines repository on GitHub. It is also possible to specify an alternative name for the function:

import outlines

fn = outlines.Function.from_github("outlines-dev/outlines/chain_of_density", function_name="agent")

Possible improvements

  • Loading models only when a generator is called would allow to use other model providers;
  • Users might want to change the model that is being used.

@rlouf rlouf added enhancement structured generation Linked to structured generation JSON labels Dec 7, 2023
@rlouf rlouf changed the title Add the Application object Define end-to-end applications Dec 7, 2023
@rlouf rlouf marked this pull request as draft December 7, 2023 19:37
@rlouf rlouf force-pushed the add-applications branch 9 times, most recently from 36ae612 to 7ae4f59 Compare December 11, 2023 11:45
@rlouf rlouf marked this pull request as ready for review December 11, 2023 11:45
The `Function` object encapsulates a prompt template, a (`transformers`)
model name and an output structure. It can then simply be called with a
prompt throughout an application.
@rlouf rlouf merged commit 4f34714 into outlines-dev:main Dec 13, 2023
5 checks passed
@rlouf rlouf deleted the add-applications branch December 13, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement JSON structured generation Linked to structured generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants