Final_Assignment_Template / local_development.py
h2oaimichalmarszalek's picture
redesign
d3b823a
raw
history blame
1.25 kB
import argparse
import json
import random
from agent import BasicAgent
from smolagents import LiteLLMModel
from tools.utils import download_file
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--id", required=False, type=str, help="Number of question to load", default=None)
args = parser.parse_args()
questions = []
question = None
file_path = None
base_url = 'https://agents-course-unit4-scoring.hf.space'
with open('questions.json', 'r') as s:
questions = json.load(s)
if args.id:
question = [q for q in questions if q['task_id'] == args.id][0]
print(f"Process question: {question.get('question')[:50]}")
else:
n = random.randint(0, len(questions))
question = questions[n]
print(f"Process random question: {question.get('question')[:50]}")
file_name = question.get('file_name')
prompt = question.get('question')
if file_name:
task_id = question.get('task_id')
file_path = download_file(f'{base_url}/files/{task_id}', file_name)
else:
file_path = None
model = LiteLLMModel(
model_id="ollama/qwen2.5:7b",
api_base="http://localhost:11434"
)
agent = BasicAgent(model)
response = agent(prompt, file_path)
print(response)