Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
dev: Add telemetry for OpenAI SDK
Clémence Lesné02b2bd1e1352
diff --git a/helpers/llm_worker.py b/helpers/llm_worker.pyindex 368396d..28df019 100644--- a/helpers/llm_worker.py+++ b/helpers/llm_worker.py@@ -32,8 +32,16 @@ from typing import AsyncGenerator, Optional, Tuple, Type, TypeVar, Unionfrom models.message import MessageModelimport tiktokenimport json+from opentelemetry.instrumentation.openai import OpenAIInstrumentor+from os import environ+# Instrument OpenAI+environ["TRACELOOP_TRACE_CONTENT"] = str(+ True+) # Instrumentation logs prompts, completions, and embeddings to span attributes, set to False to lower monitoring costs or to avoid logging PII+OpenAIInstrumentor(enrich_token_usage=True).instrument()+_logger = build_logger(__name__)_logger.info(f"Using OpenAI GPT model {CONFIG.openai.gpt_model}")_logger.info(f"Using Content Safety {CONFIG.content_safety.endpoint}")diff --git a/helpers/logging.py b/helpers/logging.pyindex ce2dcf1..4d96b2d 100644--- a/helpers/logging.py+++ b/helpers/logging.py@@ -4,8 +4,10 @@ from logging import Logger, getLogger, basicConfig, StreamHandlerfrom opentelemetry import tracefrom opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentorfrom opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor+from os import environ+environ["OTEL_TRACES_SAMPLER_ARG"] = str(0.5) # Sample 50% of tracesconfigure_azure_monitor(connection_string=CONFIG.monitoring.application_insights.connection_string.get_secret_value(),) # Configure Azure monitor collectiondiff --git a/requirements.txt b/requirements.txtindex 364f1fb..898627f 100644--- a/requirements.txt+++ b/requirements.txt@@ -14,11 +14,12 @@ jinja2==3.1.3json-repair==0.11.1mistune==3.0.2openai==1.16.2-opentelemetry-instrumentation-aiohttp-client==0.44b0-opentelemetry-instrumentation-fastapi==0.44b0-opentelemetry-instrumentation-httpx==0.44b0-opentelemetry-instrumentation-redis==0.44b0-opentelemetry-instrumentation-sqlite3==0.44b0+opentelemetry-instrumentation-aiohttp-client==0.45b0+opentelemetry-instrumentation-fastapi==0.45b0+opentelemetry-instrumentation-httpx==0.45b0+opentelemetry-instrumentation-openai==0.15.11+opentelemetry-instrumentation-redis==0.45b0+opentelemetry-instrumentation-sqlite3==0.45b0phonenumbers==8.13.34 # Required for pydantic-extra-typespydantic-extra-types==2.6.0 # Required for pydanticpydantic-settings==2.2.1