-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheval.py
More file actions
38 lines (30 loc) · 1.41 KB
/
Copy patheval.py
File metadata and controls
38 lines (30 loc) · 1.41 KB
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
import requests
import opentelemetry.trace as trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.instrumentation.requests import RequestsInstrumentor
# 1. Set up OpenTelemetry tracing
trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
# 2. Export traces to Arize Phoenix locally
exporter = OTLPSpanExporter(endpoint="http://localhost:4318/v1/traces") # Default OpenTelemetry endpoint
trace.get_tracer_provider().add_span_processor(SimpleSpanProcessor(exporter))
# 3. Instrument requests globally
RequestsInstrumentor().instrument()
# 4. Set the local llama-server endpoint
LLAMA_SERVER_URL = "http://localhost:8080/v1/chat/completions"
# 5. Function to send traced requests
def send_traced_request():
with tracer.start_as_current_span("llama-server-request") as span:
payload = {
"model": "your-model-name",
"messages": [{"role": "user", "content": "Hello, how are you?"}]
}
response = requests.post(LLAMA_SERVER_URL, json=payload)
# Add metadata to the trace
span.set_attribute("http.status_code", response.status_code)
span.set_attribute("model.response", response.json())
return response.json()
# 6. Run the request
print(send_traced_request())