-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Dust math generation code example
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import outlines.text as text | ||
|
||
|
||
examples = [ | ||
{"question": "What is 37593 * 67?", "code": "37593 * 67"}, | ||
{"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?", "code": "(16-3-4)*2"}, | ||
{"question": "A robe takes 2 bolts of blue fiber and half that much white fiber. How many bolts in total does it take?", "code": " 2 + 2/2"}, | ||
] | ||
|
||
|
||
@text.completion("openai/text-davinci-003", stop_at=["QUESTION"]) | ||
def answer_with_code(question, examples): | ||
""" | ||
{% for example in examples %} | ||
QUESTION: {{example.question}} | ||
CODE: {{example.code}} | ||
{% endfor %} | ||
QUESTION: {{question}} | ||
CODE:""" | ||
|
||
def execute_code(code): | ||
result = eval(code) | ||
return result | ||
|
||
|
||
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?" | ||
result_code, _ = answer_with_code(question, examples) | ||
result = execute_code(result_code) | ||
print(result) |