Spaces:
Paused
Paused
Update app.py with langfuse telemetry
Browse files
app.py
CHANGED
|
@@ -1,18 +1,36 @@
|
|
| 1 |
import yaml
|
| 2 |
import os
|
|
|
|
| 3 |
from smolagents import GradioUI, CodeAgent, HfApiModel
|
| 4 |
|
| 5 |
# Get current directory path
|
| 6 |
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from tools.web_search import DuckDuckGoSearchTool as WebSearch
|
| 9 |
from tools.visit_webpage import VisitWebpageTool as VisitWebpage
|
| 10 |
from tools.suggest_menu import SimpleTool as SuggestMenu
|
| 11 |
from tools.catering_service_tool import SimpleTool as CateringServiceTool
|
| 12 |
from tools.superhero_party_theme_generator import SuperheroPartyThemeTool as SuperheroPartyThemeGenerator
|
| 13 |
from tools.final_answer import FinalAnswerTool as FinalAnswer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
|
| 17 |
model = HfApiModel(
|
| 18 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
|
|
| 1 |
import yaml
|
| 2 |
import os
|
| 3 |
+
import base64
|
| 4 |
from smolagents import GradioUI, CodeAgent, HfApiModel
|
| 5 |
|
| 6 |
# Get current directory path
|
| 7 |
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 8 |
|
| 9 |
+
# use langfuse as otel dashboard
|
| 10 |
+
LANGFUSE_PUBLIC_KEY=os.getenv("LANGFUSE_PUBLIC_KEY")
|
| 11 |
+
LANGFUSE_SECRET_KEY=os.getenv("LANGFUSE_SECRET_KEY")
|
| 12 |
+
LANGFUSE_AUTH=base64.b64encode(f"{LANGFUSE_PUBLIC_KEY}:{LANGFUSE_SECRET_KEY}".encode()).decode()
|
| 13 |
+
|
| 14 |
+
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://cloud.langfuse.com/api/public/otel" # EU data region
|
| 15 |
+
# os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://us.cloud.langfuse.com/api/public/otel" # US data region
|
| 16 |
+
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Basic {LANGFUSE_AUTH}"
|
| 17 |
+
|
| 18 |
from tools.web_search import DuckDuckGoSearchTool as WebSearch
|
| 19 |
from tools.visit_webpage import VisitWebpageTool as VisitWebpage
|
| 20 |
from tools.suggest_menu import SimpleTool as SuggestMenu
|
| 21 |
from tools.catering_service_tool import SimpleTool as CateringServiceTool
|
| 22 |
from tools.superhero_party_theme_generator import SuperheroPartyThemeTool as SuperheroPartyThemeGenerator
|
| 23 |
from tools.final_answer import FinalAnswerTool as FinalAnswer
|
| 24 |
+
from opentelemetry.sdk.trace import TracerProvider
|
| 25 |
+
|
| 26 |
+
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
| 27 |
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
| 28 |
+
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
| 29 |
|
| 30 |
+
trace_provider = TracerProvider()
|
| 31 |
+
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))
|
| 32 |
|
| 33 |
+
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
|
| 34 |
|
| 35 |
model = HfApiModel(
|
| 36 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|