feat: add langfuse_opentelemetry_instrumentation
Browse files
app.py
CHANGED
|
@@ -12,6 +12,14 @@ from transformers import pipeline
|
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
from typing import Optional
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
from smolagents import (
|
| 16 |
CodeAgent,
|
| 17 |
DuckDuckGoSearchTool,
|
|
@@ -92,6 +100,20 @@ def language_detection(text:str)-> str:
|
|
| 92 |
return "None"
|
| 93 |
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# tools from /tools/
|
| 96 |
final_answer = FinalAnswerTool()
|
| 97 |
visit_webpage = VisitWebpageTool()
|
|
@@ -143,6 +165,7 @@ agent = CodeAgent(
|
|
| 143 |
prompt_templates=prompt_templates
|
| 144 |
)
|
| 145 |
|
| 146 |
-
|
|
|
|
| 147 |
|
| 148 |
-
agent.
|
|
|
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
from typing import Optional
|
| 14 |
|
| 15 |
+
import os
|
| 16 |
+
import base64
|
| 17 |
+
|
| 18 |
+
from opentelemetry.sdk.trace import TracerProvider
|
| 19 |
+
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
| 20 |
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
| 21 |
+
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
| 22 |
+
|
| 23 |
from smolagents import (
|
| 24 |
CodeAgent,
|
| 25 |
DuckDuckGoSearchTool,
|
|
|
|
| 100 |
return "None"
|
| 101 |
|
| 102 |
|
| 103 |
+
def initialize_langfuse_opentelemetry_instrumentation():
|
| 104 |
+
LANGFUSE_PUBLIC_KEY=os.environ.get("LANGFUSE_PUBLIC_KEY")
|
| 105 |
+
LANGFUSE_SECRET_KEY=os.environ.get("LANGFUSE_SECRET_KEY")
|
| 106 |
+
LANGFUSE_AUTH=base64.b64encode(f"{LANGFUSE_PUBLIC_KEY}:{LANGFUSE_SECRET_KEY}".encode()).decode()
|
| 107 |
+
|
| 108 |
+
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://cloud.langfuse.com/api/public/otel" # EU data region
|
| 109 |
+
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Basic {LANGFUSE_AUTH}"
|
| 110 |
+
|
| 111 |
+
trace_provider = TracerProvider()
|
| 112 |
+
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))
|
| 113 |
+
|
| 114 |
+
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
# tools from /tools/
|
| 118 |
final_answer = FinalAnswerTool()
|
| 119 |
visit_webpage = VisitWebpageTool()
|
|
|
|
| 165 |
prompt_templates=prompt_templates
|
| 166 |
)
|
| 167 |
|
| 168 |
+
initialize_langfuse_opentelemetry_instrumentation()
|
| 169 |
+
agent.push_to_hub('laverdes/Alfredo')
|
| 170 |
|
| 171 |
+
GradioUI(agent).launch()
|