outlines
1"""Example from https://dust.tt/spolu/a/d12ac33169"""
2import outlines
3import outlines.models as models
4
5examples = [
6{"question": "What is 37593 * 67?", "code": "37593 * 67"},
7{
8"question": "Janet's ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?",
9"code": "(16-3-4)*2",
10},
11{
12"question": "A robe takes 2 bolts of blue fiber and half that much white fiber. How many bolts in total does it take?",
13"code": " 2 + 2/2",
14},
15]
16
17question = "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?"
18
19
20@outlines.prompt
21def answer_with_code_prompt(question, examples):
22"""
23{% for example in examples %}
24QUESTION: {{example.question}}
25CODE: {{example.code}}
26
27{% endfor %}
28QUESTION: {{question}}
29CODE:"""
30
31
32def execute_code(code):
33result = eval(code)
34return result
35
36
37prompt = answer_with_code_prompt(question, examples)
38model = models.openai("gpt-3.5-turbo")
39answer = outlines.generate.text(model)(prompt)
40result = execute_code(answer)
41print(f"It takes Carla {result:.0f} minutes to download the file.")
42