zaradana's picture
Upload 2 files
dc3177f verified
raw
history blame
1.66 kB
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