File size: 1,250 Bytes
3469f37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3b823a
 
3469f37
 
 
 
 
 
 
 
 
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
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)