JerryGao commited on
Commit
ad99069
·
verified ·
1 Parent(s): 697f9b6

add langfuse observability

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -7,6 +7,24 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
  def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ from opentelemetry.sdk.trace import TracerProvider
11
+ from openinference.instrumentation.smolagents import SmolagentsInstrumentor
12
+ from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
13
+ from opentelemetry.sdk.trace.export import SimpleSpanProcessor
14
+
15
+ os.environ["PYTHONIOENCODING"] ="utf-8"
16
+ LANGFUSE_PUBLIC_KEY = os.getenv("LANGFUSE_PUBLIC_KEY", "")
17
+ LANGFUSE_SECRET_KEY = os.getenv("LANGFUSE_SECRET_KEY", "")
18
+ LANGFUSE_AUTH=base64.b64encode(f"{LANGFUSE_PUBLIC_KEY}:{LANGFUSE_SECRET_KEY}".encode()).decode()
19
+ os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://cloud.langfuse.com/api/public/otel"
20
+ os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Basic {LANGFUSE_AUTH}"
21
+
22
+ # add langfuse observability to this factchecking agent
23
+ trace_provider = TracerProvider()
24
+ trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))
25
+ SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
26
+
27
+
28
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
29
  @tool
30
  def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type