File size: 1,499 Bytes
ecbc0b3
 
 
 
 
0b6bcde
 
4e998d8
ecbc0b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e998d8
ecbc0b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
from smolagents import OpenAIServerModel


system_text = """
Revise the answer to match exactly what the question is asking. Keep it concise and focused, removing irrelevant details, redundant phrases, or formatting. 
Do not change the meaning or add new information. Ensure the output directly answers the question, with the correct level of specificity and format requested.
Only return the revised answer. Do not include explanations or headers. If the question asks a number of something return only the number, no extra words.
"""


def check_final_answer(question: str, answer: str) -> str:
    """
    Pass the question and answer to a LLM, to make it proper for GAIA comparison.

    Args:
        question: Question.
        answer: Original final answer.
    """
    OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')

    answer_model = OpenAIServerModel(
        api_key=OPENAI_API_KEY,
        model_id='gpt-4o-mini',
        temperature=0,
    )

    messages = [
        {
            "role": "system",
            "content": [
                {
                    "type": "text",
                    "text": system_text
                }
            ]
        },
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": f"Question:\n{question}\n\nOriginal Answer:\n{answer}",
                }
            ]
        }
    ]
    response = answer_model(messages).content

    return response