outlines

Форк
0
/
math_generate_code.py 
41 строка · 1.5 Кб
1
"""Example from https://dust.tt/spolu/a/d12ac33169"""
2
import outlines
3
import outlines.models as models
4

5
examples = [
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

17
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?"
18

19

20
@outlines.prompt
21
def answer_with_code_prompt(question, examples):
22
    """
23
    {% for example in examples %}
24
    QUESTION: {{example.question}}
25
    CODE: {{example.code}}
26

27
    {% endfor %}
28
    QUESTION: {{question}}
29
    CODE:"""
30

31

32
def execute_code(code):
33
    result = eval(code)
34
    return result
35

36

37
prompt = answer_with_code_prompt(question, examples)
38
model = models.openai("gpt-3.5-turbo")
39
answer = outlines.generate.text(model)(prompt)
40
result = execute_code(answer)
41
print(f"It takes Carla {result:.0f} minutes to download the file.")
42

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.