Final_Assignment_Agent / basic_agent_test.py
SrcLurker's picture
handle audio, remove extra sub-agent
7a87e6a
raw
history blame
2.29 kB
#!/usr/bin/env python3
import logging
import json
import basic_agent
LOG = logging.getLogger(__name__)
QUESTIONS_PATH = "../questions.json"
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
# Local:
# https://huggingface.co/docs/smolagents/tutorials/inspect_runs
# https://cobusgreyling.medium.com/introduce-inspectability-to-huggingface-smolagents-571bd3f8da4c
#
# pip install arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp openinference-instrumentation-smolagents
#
# pip install 'smolagents[telemetry]'
#
# python -m phoenix.server.main serve
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
endpoint = "http://0.0.0.0:6006/v1/traces"
trace_provider = TracerProvider()
trace_provider.add_span_processor(
SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
ba = basic_agent.BasicAgent()
with open(QUESTIONS_PATH, "r") as fp:
questions = json.load(fp)
# Should be 20
print(f"{len(questions)=}")
# One question entry:
#
# {'Level': '1',
# 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx',
# 'question': 'The attached Excel file contains the sales of menu items for a '
# 'local fast-food chain. What were the total sales that the chain '
# 'made from food (not including drinks)? Express your answer in '
# 'USD with two decimal places.',
# 'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733'},
#
# 18 has an xlsx file
# 13 has an mp3 file
# 11 has a py file
# 9 has an mp3 file
want = 9
question = questions[want]
q_task_id = question["task_id"]
q_text = question["question"]
q_filename = question.get("file_name", "")
if q_filename:
file_url = f"{DEFAULT_API_URL}/files/{q_task_id}"
print("Question {task_id=} has attachment: {file_url=}")
quest_with_url = f"{q_text}\nFile url: {file_url}"
else:
quest_with_url = q_text
answer = ba(quest_with_url)
LOG.warning(f"{answer=}")