File size: 1,472 Bytes
9d098dd
 
 
 
 
 
 
 
766d2d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d098dd
 
7376a97
cc9ee3d
 
 
7376a97
 
 
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
#!/usr/bin/env python3

import logging

import basic_agent

LOG = logging.getLogger(__name__)


# 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()

"""
answer = ba(
    "Who is the 47th president of the united states? If necessary, use a web search to get the most up to date information."
)
"""
answer = ba("What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?"
)

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