From 7991d183cd91230cd73399485b57aab18c066da7 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Wed, 15 Jan 2025 10:48:37 +0100 Subject: [PATCH] Update documentation (replace `Function` by `Outline`) --- docs/quickstart.md | 62 +++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/docs/quickstart.md b/docs/quickstart.md index 81a067ad6..24518c03a 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -163,56 +163,46 @@ print(prompt) # A: ``` -### Outlines functions +### `Outline`s -Once you are done experimenting with a prompt and an output structure, it is useful to be able to encapsulate all of these in a single function that can be called from other parts of the program. This is what `outlines.Function` allows you to do: +The `Outline` class allows you to encapsulate a model, a prompt template, and an expected output type into a single callable object. This can be useful for generating structured responses based on a given prompt. -=== "function.py" - - ```python - from pydantic import BaseModel - - import outlines +#### Example +First, define a Pydantic model for the expected output: - @outlines.prompt - def tell_a_joke(topic): - """Tell me a joke about {{ topic }}.""" - - class Joke(BaseModel): - setup: str - punchline: str +```python +from pydantic import BaseModel - generate_joke = outlines.Function( - tell_a_joke, - Joke, - "microsoft/Phi-3-mini-4k-instruct" - ) - ``` +class OutputModel(BaseModel): + result: int +``` -=== "Call a function" +Next, initialize a model and define a template function: - ```python - from .function import generate_joke +```python +from outlines import models - response = generate_joke("baseball") +model = models.transformers("gpt2") - # haha - # Joke(setup='Why was the baseball in a bad mood?', punchline='Because it got hit around a lot.') - ``` +def template(a: int) -> str: + return f"What is 2 times {a}?" +``` -=== "Call a function stored on GitHub" +Now, create an `Outline` instance: - You can load a function that is stored on a repository on GitHub directly from Outlines. Say `Someone` stores a function in `joke.py` at the root of the `TheirRepo` repository: +```python +from outlines.outline import Outline - ```python - import outlines +fn = Outline(model, template, OutputModel) +``` - joke = outlines.Function.from_github("Someone/TheirRepo/joke") - response = joke("baseball") - ``` - It make it easier for the community to collaborate on the infinite number of use cases enabled by these models! +You can then call the `Outline` instance with the required arguments: +```python +result = fn(3) +print(result) # Expected output: OutputModel(result=6) +``` ## Going further