Skip to content

Commit

Permalink
Update documentation (replace Function by Outline)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Jan 15, 2025
1 parent 4454ab3 commit 7991d18
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7991d18

Please sign in to comment.