Spaces:
Build error
Build error
Merge pull request #1 from serverdaun/langfuse
Browse files- app.py +29 -2
- requirements.txt +5 -0
app.py
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from smolagents import CodeAgent, HfApiModel, FinalAnswerTool
|
| 2 |
from tools.get_weather import get_weather_forecast
|
| 3 |
from utils.utils import load_prompt
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
-
import
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
if "city" not in st.session_state:
|
| 9 |
st.session_state.city = ""
|
|
@@ -15,6 +22,26 @@ if "sex" not in st.session_state:
|
|
| 15 |
load_dotenv()
|
| 16 |
hf_token = os.getenv("HF_TOKEN")
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def get_clothing_reccomendation(city: str, age: str, sex: str) -> str:
|
| 19 |
"""
|
| 20 |
This function returns clothing recommendations based on the weather forecast for a specific city.
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import os
|
| 4 |
+
import base64
|
| 5 |
from smolagents import CodeAgent, HfApiModel, FinalAnswerTool
|
| 6 |
from tools.get_weather import get_weather_forecast
|
| 7 |
from utils.utils import load_prompt
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
+
from opentelemetry.sdk.trace import TracerProvider
|
| 10 |
+
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
| 11 |
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
| 12 |
+
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
| 13 |
+
from opentelemetry import trace
|
| 14 |
|
| 15 |
if "city" not in st.session_state:
|
| 16 |
st.session_state.city = ""
|
|
|
|
| 22 |
load_dotenv()
|
| 23 |
hf_token = os.getenv("HF_TOKEN")
|
| 24 |
|
| 25 |
+
# Set up the OpenTelemetry exporter for LangFuse
|
| 26 |
+
LANGFUSE_AUTH = base64.b64encode(
|
| 27 |
+
f"{os.environ.get('LANGFUSE_PUBLIC_KEY')}:{os.environ.get('LANGFUSE_SECRET_KEY')}".encode()
|
| 28 |
+
).decode()
|
| 29 |
+
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = os.environ.get("LANGFUSE_HOST") + "/api/public/otel"
|
| 30 |
+
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Basic {LANGFUSE_AUTH}"
|
| 31 |
+
|
| 32 |
+
# Create a TracerProvider for OpenTelemetry
|
| 33 |
+
trace_provider = TracerProvider()
|
| 34 |
+
|
| 35 |
+
# Add a SimpleSpanProcessor with the OTLPSpanExporter to send traces
|
| 36 |
+
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))
|
| 37 |
+
|
| 38 |
+
# Set the global default tracer provider
|
| 39 |
+
trace.set_tracer_provider(trace_provider)
|
| 40 |
+
tracer = trace.get_tracer(__name__)
|
| 41 |
+
|
| 42 |
+
# Instrument smolagents with the configured provider
|
| 43 |
+
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
|
| 44 |
+
|
| 45 |
def get_clothing_reccomendation(city: str, age: str, sex: str) -> str:
|
| 46 |
"""
|
| 47 |
This function returns clothing recommendations based on the weather forecast for a specific city.
|
requirements.txt
CHANGED
|
@@ -3,3 +3,8 @@ pandas
|
|
| 3 |
openmeteo_requests
|
| 4 |
python-dotenv
|
| 5 |
streamlit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
openmeteo_requests
|
| 4 |
python-dotenv
|
| 5 |
streamlit
|
| 6 |
+
smolagents[telemetry]
|
| 7 |
+
opentelemetry-sdk
|
| 8 |
+
opentelemetry-exporter-otlp
|
| 9 |
+
openinference-instrumentation-smolagents
|
| 10 |
+
langfuse
|