Skip to content

Commit

Permalink
Move prompts.py to root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Nov 16, 2023
1 parent 7e428e5 commit e6463ed
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion docs/api/prompts.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: outlines.text.prompts
::: outlines.prompts
8 changes: 4 additions & 4 deletions examples/babyagi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from collections import deque
from typing import Deque, List

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

model = models.openai("gpt-3.5-turbo")

Expand All @@ -18,7 +18,7 @@
#################


@text.prompt
@outlines.prompt
def perform_task_ppt(objective: str, task: str):
"""You are an AI who performs one task based on the following objective: {{objective}}.
Expand All @@ -33,7 +33,7 @@ def perform_task_ppt(objective: str, task: str):
#####################


@text.prompt
@outlines.prompt
def create_tasks_ppt(
objective: str, previous_task: str, result: str, task_list: List[str]
):
Expand Down Expand Up @@ -69,7 +69,7 @@ def create_tasks_fmt(result: str) -> List[str]:
########################


@text.prompt
@outlines.prompt
def prioritize_tasks_ppt(objective: str, task_names: List[str], next_task_id: int):
"""You are a task prioritization AI tasked with cleaning the formatting of \
and reprioritizing the following tasks: {{task_names}}.
Expand Down
3 changes: 2 additions & 1 deletion examples/dating_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import transformers
from pydantic import BaseModel, conlist

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

Expand Down Expand Up @@ -41,7 +42,7 @@ class Example:
profile: DatingProfile


@text.prompt
@outlines.prompt
def dating_profile_prompt(description: str, examples: list[Example]):
"""
You are a world-renowned matchmaker who understands the modern dating market. Your job is to generate dating app profiles for male clients interested in women based on a provided description. The profiles should be authentic, show off their strengths, and maximize their likelihood of getting matches on dating apps.
Expand Down
4 changes: 2 additions & 2 deletions examples/math_generate_code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Example from https://dust.tt/spolu/a/d12ac33169"""
import outlines
import outlines.models as models
import outlines.text as text

examples = [
{"question": "What is 37593 * 67?", "code": "37593 * 67"},
Expand All @@ -17,7 +17,7 @@
question = "Carla is downloading a 200 GB file. She can download 2 GB/minute, but 40% of the way through the download, the download fails. Then Carla has to restart the download from the beginning. How load did it take her to download the file in minutes?"


@text.prompt
@outlines.prompt
def answer_with_code_prompt(question, examples):
"""
{% for example in examples %}
Expand Down
16 changes: 8 additions & 8 deletions examples/meta_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"""
import argparse

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


def split_into_steps(question, model_name: str):
@text.prompt
@outlines.prompt
def solve(question):
"""{{question}}
Let's solve this problem by splitting it into steps.
Expand All @@ -32,14 +32,14 @@ def solve(question):


def fill_in_the_blanks(question, model_name: str):
@text.prompt
@outlines.prompt
def determine_goal(question):
"""{{question}}
In order to solve this problem, we will analyze each of the options and determine
"""

@text.prompt
@outlines.prompt
def solve(memory):
"""{{memory}}. Let's begin."""

Expand All @@ -55,7 +55,7 @@ def solve(memory):


def ask_an_expert(question, model_name: str):
@text.prompt
@outlines.prompt
def find_expert(question):
"""
{{question}}
Expand All @@ -73,7 +73,7 @@ def find_expert(question):
on the screen: "
"""

@text.prompt
@outlines.prompt
def get_answer(question, expert, memory):
"""
{{memory}}".
Expand All @@ -94,14 +94,14 @@ def get_answer(question, expert, memory):


def ask_an_expert_simple(question, model_name: str):
@text.prompt
@outlines.prompt
def find_expert(question):
"""
Q: {{question}}
A: A good person to answer this question would be
"""

@text.prompt
@outlines.prompt
def get_answer(expert, memory):
"""
{{memory}}.
Expand Down
4 changes: 2 additions & 2 deletions examples/pick_odd_one_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
arXiv preprint arXiv:2212.06094.
"""
import outlines
import outlines.models as models
import outlines.text as text


@text.prompt
@outlines.prompt
def build_ooo_prompt(options):
"""
Pick the odd word out: skirt, dress, pen, jacket.
Expand Down
6 changes: 3 additions & 3 deletions examples/react.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"""
import requests # type: ignore

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


@text.prompt
@outlines.prompt
def build_reAct_prompt(question):
"""What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?
Tho 1: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ...
Expand All @@ -30,7 +30,7 @@ def build_reAct_prompt(question):
"""


@text.prompt
@outlines.prompt
def add_mode(i, mode, result, prompt):
"""{{ prompt }}
{{ mode }} {{ i }}: {{ result }}
Expand Down
4 changes: 2 additions & 2 deletions examples/self_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np

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

examples = [
{
Expand Down Expand Up @@ -43,7 +43,7 @@
question = "When I was 6 my sister was half my age. Now I’m 70 how old is my sister?"


@text.prompt
@outlines.prompt
def few_shots(question, examples):
"""
{% for example in examples %}
Expand Down
2 changes: 1 addition & 1 deletion outlines/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Outlines is a Generative Model Programming Framework."""
from outlines.base import vectorize
from outlines.caching import clear_cache, disable_cache, get_cache
from outlines.text import prompt
from outlines.prompts import prompt

__all__ = [
"clear_cache",
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion outlines/text/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .generate import continuation
from .prompts import prompt, render
47 changes: 24 additions & 23 deletions tests/text/test_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,43 @@
import pytest
from pydantic import BaseModel, Field

import outlines.text as text
import outlines
from outlines.prompts import render


def test_render():
tpl = """
A test string"""
assert text.render(tpl) == "A test string"
assert render(tpl) == "A test string"

tpl = """
A test string
"""
assert text.render(tpl) == "A test string"
assert render(tpl) == "A test string"

tpl = """
A test
Another test
"""
assert text.render(tpl) == "A test\nAnother test"
assert render(tpl) == "A test\nAnother test"

tpl = """A test
Another test
"""
assert text.render(tpl) == "A test\nAnother test"
assert render(tpl) == "A test\nAnother test"

tpl = """
A test line
An indented line
"""
assert text.render(tpl) == "A test line\n An indented line"
assert render(tpl) == "A test line\n An indented line"

tpl = """
A test line
An indented line
"""
assert text.render(tpl) == "A test line\n An indented line\n"
assert render(tpl) == "A test line\n An indented line\n"


def test_render_escaped_linebreak():
Expand All @@ -47,7 +48,7 @@ def test_render_escaped_linebreak():
that we break \
in several lines
"""
assert text.render(tpl) == "A long test that we break in several lines"
assert render(tpl) == "A long test that we break in several lines"

tpl = """
Break in \
Expand All @@ -58,7 +59,7 @@ def test_render_escaped_linebreak():
Goes back to normal
"""
assert (
text.render(tpl)
render(tpl)
== "Break in several lines But respect the indentation\n on line breaks.\nAnd after everything Goes back to normal"
)

Expand All @@ -70,7 +71,7 @@ def test_render_jinja():

# Notice the newline after the end of the loop
examples = ["one", "two"]
prompt = text.render(
prompt = render(
"""
{% for e in examples %}
Example: {{e}}
Expand All @@ -81,7 +82,7 @@ def test_render_jinja():

# We can remove the newline by cloing with -%}
examples = ["one", "two"]
prompt = text.render(
prompt = render(
"""
{% for e in examples %}
Example: {{e}}
Expand All @@ -100,12 +101,12 @@ def test_render_jinja():
final
"""
assert text.render(tpl, is_true=True) == "true\nfinal"
assert text.render(tpl, is_true=False) == "final"
assert render(tpl, is_true=True) == "true\nfinal"
assert render(tpl, is_true=False) == "final"


def test_prompt_basic():
@text.prompt
@outlines.prompt
def test_tpl(variable):
"""{{variable}} test"""

Expand All @@ -121,7 +122,7 @@ def test_tpl(variable):
p = test_tpl(variable="test")
assert p == "test test"

@text.prompt
@outlines.prompt
def test_single_quote_tpl(variable):
"${variable} test"

Expand All @@ -130,7 +131,7 @@ def test_single_quote_tpl(variable):


def test_prompt_kwargs():
@text.prompt
@outlines.prompt
def test_kwarg_tpl(var, other_var="other"):
"""{{var}} and {{other_var}}"""

Expand All @@ -150,13 +151,13 @@ def test_kwarg_tpl(var, other_var="other"):
def test_no_prompt():
with pytest.raises(TypeError, match="template"):

@text.prompt
@outlines.prompt
def test_empty(variable):
pass

with pytest.raises(TypeError, match="template"):

@text.prompt
@outlines.prompt
def test_only_code(variable):
return variable

Expand All @@ -172,7 +173,7 @@ def with_description():
"""
pass

@text.prompt
@outlines.prompt
def name_description_ppt(fn):
"""
{{fn|name}}: {{fn|description}}
Expand All @@ -187,7 +188,7 @@ def name_description_ppt(fn):
def with_signature(one: int, two: List[str], three: float = 1.0):
pass

@text.prompt
@outlines.prompt
def name_signature_ppt(fn):
"""
{{fn|name}}: {{fn|signature}}
Expand All @@ -199,7 +200,7 @@ def name_signature_ppt(fn):
def test_function_call(one, two=2):
return one + two

@text.prompt
@outlines.prompt
def source_ppt(fn):
"""
{{fn|source}}
Expand All @@ -214,7 +215,7 @@ class SimpleResponse(BaseModel):
one: str = Field(description="a description")
two: str

@text.prompt
@outlines.prompt
def source_ppt(model):
"{{model | schema }}"

Expand Down Expand Up @@ -245,7 +246,7 @@ class ConvolutedResponse(BaseModel):
def test_prompt_dict_response():
response = {"one": "a description", "two": ""}

@text.prompt
@outlines.prompt
def source_ppt(model):
"{{model | schema }}"

Expand Down

0 comments on commit e6463ed

Please sign in to comment.