File size: 2,133 Bytes
9d098dd
 
 
895992e
9d098dd
 
 
 
 
895992e
766d2d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
895992e
 
766d2d7
 
 
9d098dd
 
895992e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d098dd
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3

import logging
import json

import basic_agent

LOG = logging.getLogger(__name__)

QUESTIONS_PATH = "../questions.json"

# 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'},
#

want = 7
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"{api_url}/files/{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(question_text)

LOG.warning(f"{answer=}")