File size: 1,661 Bytes
dc3177f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
from smolagents import OpenAIServerModel
from dotenv import load_dotenv
from huggingface_hub import HfApi
import os

load_dotenv()
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
repo_id = "zaradana/temp_files"

api = HfApi()

def check_asnwer_format(final_answer, agent_memory):
    multimodal_model = OpenAIServerModel("gpt-4o", max_tokens=8096, api_key=OPENAI_API_KEY)
    prompt = (
        f"Here is a user-given task and the agent steps: {agent_memory.get_succinct_steps()}. "
        f"Here is the final answer: {final_answer}. "
        "Please check that the answer is in the requested format. "
        "First list reasons why yes/no, then write your final decision: PASS in caps lock if it is satisfactory, FAIL if it is not."
    )
    messages = [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": prompt,
                }
            ],
        }
    ]
    output = multimodal_model(messages).content
    print("Feedback: ", output)
    if "FAIL" in output:
        raise Exception(output)
    return True


def upload_file(file_local_path: str) -> str:
    """
    Upload a file to the Hugging Face Hub and return the URL
    Args:
        file_local_path: The local path to the file
    Returns:
        The URL of the uploaded file
    """
    file_name = file_local_path.split("/")[-1]

    api.upload_file(
        path_or_fileobj=file_local_path,
        path_in_repo=file_name,
        repo_id=repo_id,
        repo_type="dataset"
    )
    file_url = f"https://huggingface.co/datasets/{repo_id}/resolve/main/{file_name}"
    return file_url