diff --git a/docs/api/prompts.md b/docs/api/prompts.md index f9899400e..9d28f838c 100644 --- a/docs/api/prompts.md +++ b/docs/api/prompts.md @@ -1 +1 @@ -::: outlines.text.prompts +::: outlines.prompts diff --git a/examples/babyagi.py b/examples/babyagi.py index fd4b8b3d8..406e41d75 100644 --- a/examples/babyagi.py +++ b/examples/babyagi.py @@ -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") @@ -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}}. @@ -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] ): @@ -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}}. diff --git a/examples/dating_profile.py b/examples/dating_profile.py index 228f13993..7bf2a886d 100644 --- a/examples/dating_profile.py +++ b/examples/dating_profile.py @@ -5,6 +5,7 @@ import transformers from pydantic import BaseModel, conlist +import outlines import outlines.models as models import outlines.text as text @@ -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. diff --git a/examples/math_generate_code.py b/examples/math_generate_code.py index 507a76ec0..707b09761 100644 --- a/examples/math_generate_code.py +++ b/examples/math_generate_code.py @@ -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"}, @@ -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 %} diff --git a/examples/meta_prompting.py b/examples/meta_prompting.py index eb10b9bd9..04334ed55 100644 --- a/examples/meta_prompting.py +++ b/examples/meta_prompting.py @@ -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. @@ -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.""" @@ -55,7 +55,7 @@ def solve(memory): def ask_an_expert(question, model_name: str): - @text.prompt + @outlines.prompt def find_expert(question): """ {{question}} @@ -73,7 +73,7 @@ def find_expert(question): on the screen: " """ - @text.prompt + @outlines.prompt def get_answer(question, expert, memory): """ {{memory}}". @@ -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}}. diff --git a/examples/pick_odd_one_out.py b/examples/pick_odd_one_out.py index 286125037..88ebeeb20 100644 --- a/examples/pick_odd_one_out.py +++ b/examples/pick_odd_one_out.py @@ -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. diff --git a/examples/react.py b/examples/react.py index c3964cfa2..7324e715a 100644 --- a/examples/react.py +++ b/examples/react.py @@ -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 ... @@ -30,7 +30,7 @@ def build_reAct_prompt(question): """ -@text.prompt +@outlines.prompt def add_mode(i, mode, result, prompt): """{{ prompt }} {{ mode }} {{ i }}: {{ result }} diff --git a/examples/self_consistency.py b/examples/self_consistency.py index 6aded6e67..9d725a3ff 100644 --- a/examples/self_consistency.py +++ b/examples/self_consistency.py @@ -2,8 +2,8 @@ import numpy as np +import outlines import outlines.models as models -import outlines.text as text examples = [ { @@ -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 %} diff --git a/outlines/__init__.py b/outlines/__init__.py index a50822878..0bf1a38ea 100644 --- a/outlines/__init__.py +++ b/outlines/__init__.py @@ -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", diff --git a/outlines/text/prompts.py b/outlines/prompts.py similarity index 100% rename from outlines/text/prompts.py rename to outlines/prompts.py diff --git a/outlines/text/__init__.py b/outlines/text/__init__.py index b1ae976c9..a1189ca01 100644 --- a/outlines/text/__init__.py +++ b/outlines/text/__init__.py @@ -1,2 +1 @@ from .generate import continuation -from .prompts import prompt, render diff --git a/tests/text/test_prompts.py b/tests/text/test_prompts.py index d3f3698e4..65eeb2022 100644 --- a/tests/text/test_prompts.py +++ b/tests/text/test_prompts.py @@ -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(): @@ -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 \ @@ -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" ) @@ -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}} @@ -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}} @@ -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""" @@ -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" @@ -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}}""" @@ -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 @@ -172,7 +173,7 @@ def with_description(): """ pass - @text.prompt + @outlines.prompt def name_description_ppt(fn): """ {{fn|name}}: {{fn|description}} @@ -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}} @@ -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}} @@ -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 }}" @@ -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 }}"