Skip to content

Commit

Permalink
Update documentation and examples following outlines.prompt depreca…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
rlouf committed Feb 26, 2025
1 parent 5c8ff7e commit 4abe628
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 235 deletions.
7 changes: 4 additions & 3 deletions docs/cookbook/chain_of_density.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ The prompt also asks the model to return a list of JSON objects that contain the
We can now implement the prompt provided in the paper:

```python
import outlines
from outlines import Template

@outlines.prompt
def chain_of_density(article):

chain_of_density = Template.from_string(
"""Article: {{ article }}
You will generate increasingly concise, entity-dense summaries of the above Article.
Expand Down Expand Up @@ -61,6 +61,7 @@ def chain_of_density(article):
Answer in JSON. The JSON should be a a dictionary with key "summaries" that contains a list (length 5) of dictionaries whose keys are "Missing_Entities" and "Denser_Summary".
"""
)
```

??? Note
Expand Down
7 changes: 5 additions & 2 deletions docs/cookbook/classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ model = outlines.models.transformers("TheBloke/Mistral-7B-OpenOrca-AWQ", device=
We will use the following prompt template:

```python
@outlines.prompt
def customer_support(request):
from outlines import Template


customer_support = Template.from_string(
"""You are an experienced customer success manager.
Given a request from a client, you need to determine when the
Expand All @@ -36,6 +38,7 @@ def customer_support(request):
Request: {{ request }}
Label: """
)
```

## Choosing between multiple choices
Expand Down
5 changes: 3 additions & 2 deletions docs/cookbook/dating_profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class Example:
We will use Outlines' prompt templating abilities to generate the prompt for us. This help clearly separate the general prompting logic from what is specific to an example.

```python
from outlines import Template

@outlines.prompt
def dating_profile_prompt(description: str, examples: list[Example]):
dating_profile_prompt = Template.from_string(
"""
You are a world-renowned matchmaker who understands the modern dating
market. Your job is to generate dating app profiles for male clients
Expand All @@ -79,6 +79,7 @@ def dating_profile_prompt(description: str, examples: list[Example]):
Description: {{ description }}
Profile:
"""
)
```

We will provide the model with several few-shot examples:
Expand Down
7 changes: 5 additions & 2 deletions docs/cookbook/extraction.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ model = outlines.models.transformers("TheBloke/Mistral-7B-OpenOrca-AWQ", device=
And we will be using the following prompt template:

```python
@outlines.prompt
def take_order(order):
from outlines import Template


take_order = Template.from_string(
"""You are the owner of a pizza parlor. Customers \
send you orders from which you need to extract:
Expand All @@ -42,6 +44,7 @@ def take_order(order):
ORDER: {{ order }}
RESULT: """
)
```

We now define our data model using Pydantic:
Expand Down
14 changes: 6 additions & 8 deletions docs/cookbook/simtom.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ To implement SimToM with Outlines, we will need to:

Let's dive into it!

### Using Prompt Functions

With Outlines, you can write your prompts as Python functions by adding the `@outlines.prompt` decorator. The prompt template is contained in their docstring, and their arguments correspond to variables used in the prompt.
### Using Prompt Templates

The authors have shared their code, prompts and data in [this GitHub repository](https://github.com/shawnsihyunlee/simulatedtom). Below, we define in Outlines the prompts they used for the ToMI dataset:

```python
import outlines
from outlines import Template


@outlines.prompt
def perspective_taking(story: str, character: str) -> None:
perspective_taking = Template.from_string(
"""<s>[INST] The following is a sequence of events about some characters, that takes place in multiple locations.
Your job is to output only the events that the specified character, {{character}}, knows about.
Expand All @@ -45,16 +42,17 @@ def perspective_taking(story: str, character: str) -> None:
Story: {{story}}
What events does {{character}} know about? Only output the events according to the above rules, do not provide an explanation. [/INST]""" # noqa
)

@outlines.prompt
def simulation(events: list, name: str, question: str) -> None:
simulation = Template.from_string(
"""<s>[INST] {% for event in events %}
{{event}}
{% endfor %}
You are {{name}}.
Based on the above information, answer the following question:
{{question}}
You must choose one of the above choices, do not say there is not enough information. Answer with a single word, do not output anything else. [/INST]""" # noqa
)
```

### JSON Structured Generation
Expand Down
10 changes: 5 additions & 5 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ Or use the [requests][requests]{:target="_blank"} library from another python pr
Prompting can lead to messy code. Outlines' prompt functions are python functions that contain a template for the prompt in their docstring. We use a powerful templating language to allow you to loop over lists, dictionaries, add conditionals, etc. directly from the prompt. When called, a prompt function returns the rendered template:

```python
import outlines
from outlines import Template

@outlines.prompt
def few_shots(instructions, examples, question):
few_shots = Template.from_string(
"""{{ instructions }}
Examples
Expand All @@ -135,6 +134,7 @@ def few_shots(instructions, examples, question):
Q: {{ question }}
A:
"""
)

instructions = "Please answer the following question following the examples"
examples = [
Expand Down Expand Up @@ -175,9 +175,9 @@ Once you are done experimenting with a prompt and an output structure, it is use
import outlines


@outlines.prompt
def tell_a_joke(topic):
tell_a_joke = outlines.Template.from_string(
"""Tell me a joke about {{ topic }}."""
)

class Joke(BaseModel):
setup: str
Expand Down
Loading

0 comments on commit 4abe628

Please sign in to comment.