Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
refacto: Allow to use tracer without infinite import loop
Clémence Lesnéf09ee29e6b32
diff --git a/function_app.py b/function_app.pyindex c62b663..5fc9054 100644--- a/function_app.py+++ b/function_app.py@@ -37,13 +37,14 @@ from helpers.call_events import (from helpers.call_utils import ContextEnum as CallContextEnumfrom helpers.config import CONFIGfrom helpers.http import azure_transport-from helpers.logging import APP_NAME, logger, trace+from helpers.logging import logger+from helpers.monitoring import tracefrom helpers.pydantic_types.phone_numbers import PhoneNumberfrom models.call import CallGetModel, CallInitiateModel, CallStateModelfrom models.next import ActionEnum as NextActionEnumfrom models.readiness import ReadinessCheckModel, ReadinessEnum, ReadinessModel-logger.info("%s v%s", APP_NAME, CONFIG.version)+logger.info("call-center-ai v%s", CONFIG.version)# Jinja configuration_jinja = Environment(diff --git a/helpers/call_events.py b/helpers/call_events.pyindex a66820e..580dac6 100644--- a/helpers/call_events.py+++ b/helpers/call_events.py@@ -18,7 +18,8 @@ from helpers.call_utils import ()from helpers.config import CONFIGfrom helpers.llm_worker import completion_sync-from helpers.logging import logger, tracer+from helpers.logging import logger+from helpers.monitoring import tracerfrom models.call import CallStateModelfrom models.message import (ActionEnum as MessageActionEnum,diff --git a/helpers/llm_worker.py b/helpers/llm_worker.pyindex 0a5ea47..de4465e 100644--- a/helpers/llm_worker.py+++ b/helpers/llm_worker.py@@ -41,7 +41,8 @@ from tenacity import (from helpers.config import CONFIGfrom helpers.config_models.llm import AbstractPlatformModel as LlmAbstractPlatformModel-from helpers.logging import logger, tracer+from helpers.logging import logger+from helpers.monitoring import tracerfrom helpers.resources import resources_dirfrom models.message import MessageModeldiff --git a/helpers/logging.py b/helpers/logging.pyindex c723f5b..1d1ca12 100644--- a/helpers/logging.py+++ b/helpers/logging.py@@ -1,24 +1,7 @@from logging import basicConfig, getLogger-from azure.monitor.opentelemetry import configure_azure_monitor-from opentelemetry import trace-from opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentor-from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor-from helpers.config import CONFIG-APP_NAME = "call-center-ai"--# LoggerbasicConfig(level=CONFIG.monitoring.logging.sys_level.value)-logger = getLogger(APP_NAME)+logger = getLogger("call-center-ai")logger.setLevel(CONFIG.monitoring.logging.app_level.value)--# OpenTelemetry-configure_azure_monitor() # Configure Azure Application Insights exporter-AioHttpClientInstrumentor().instrument() # Instrument aiohttp-HTTPXClientInstrumentor().instrument() # Instrument httpx-tracer = trace.get_tracer(- instrumenting_library_version=CONFIG.version,- instrumenting_module_name=f"com.github.clemlesne.{APP_NAME}",-) # Create a tracer that will be used in the appdiff --git a/helpers/monitoring.py b/helpers/monitoring.pynew file mode 100644index 0000000..8aaeb8d--- /dev/null+++ b/helpers/monitoring.py@@ -0,0 +1,16 @@+from os import environ++from azure.monitor.opentelemetry import configure_azure_monitor+from opentelemetry import trace+from opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentor+from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor++VERSION = environ.get("VERSION", "0.0.0-unknown")++configure_azure_monitor() # Configure Azure Application Insights exporter+AioHttpClientInstrumentor().instrument() # Instrument aiohttp+HTTPXClientInstrumentor().instrument() # Instrument httpx+tracer = trace.get_tracer(+ instrumenting_library_version=VERSION,+ instrumenting_module_name="com.github.clemlesne.call-center-ai",+) # Create a tracer that will be used in the appdiff --git a/models/call.py b/models/call.pyindex 497fb5b..d2e6edc 100644--- a/models/call.py+++ b/models/call.py@@ -8,6 +8,7 @@ from uuid import UUID, uuid4from pydantic import BaseModel, Field, ValidationInfo, computed_field, field_validatorfrom helpers.config_models.conversation import LanguageEntryModel, WorkflowInitiateModel+from helpers.monitoring import tracerfrom helpers.pydantic_types.phone_numbers import PhoneNumberfrom models.message import ActionEnum as MessageActionEnum, MessageModelfrom models.next import NextModel@@ -114,7 +115,6 @@ class CallStateModel(CallGetModel, extra="ignore"):Is using query expansion from last messages. Then, data is sorted by score."""from helpers.config import CONFIG # pylint: disable=import-outside-toplevel- from helpers.logging import tracer # pylint: disable=import-outside-toplevelwith tracer.start_as_current_span("trainings"):search = CONFIG.ai_search.instance()diff --git a/models/message.py b/models/message.pyindex 32e9d03..50e0da5 100644--- a/models/message.py+++ b/models/message.py@@ -15,6 +15,8 @@ from openai.types.chat import (from openai.types.chat.chat_completion_chunk import ChoiceDeltaToolCallfrom pydantic import BaseModel, Field, field_validator+from helpers.monitoring import tracer+_FUNC_NAME_SANITIZER_R = r"[^a-zA-Z0-9_-]"_MESSAGE_ACTION_R = r"(?:action=*([a-z_]*))? *(.*)"_MESSAGE_STYLE_R = r"(?:style=*([a-z_]*))? *(.*)"@@ -80,10 +82,7 @@ class ToolModel(BaseModel):return selfasync def execute_function(self, plugins: object) -> None:- from helpers.logging import ( # pylint: disable=import-outside-toplevel- logger,- tracer,- )+ from helpers.logging import logger # pylint: disable=import-outside-topleveljson_str = self.function_argumentsname = self.function_namediff --git a/persistence/icache.py b/persistence/icache.pyindex ff1524e..a44595c 100644--- a/persistence/icache.py+++ b/persistence/icache.py@@ -1,6 +1,7 @@from abc import ABC, abstractmethodfrom typing import Optional, Union+from helpers.monitoring import tracerfrom models.readiness import ReadinessEnumdiff --git a/persistence/isearch.py b/persistence/isearch.pyindex 104fa26..da7c563 100644--- a/persistence/isearch.py+++ b/persistence/isearch.py@@ -1,6 +1,7 @@from abc import ABC, abstractmethodfrom typing import Optional+from helpers.monitoring import tracerfrom models.readiness import ReadinessEnumfrom models.training import TrainingModelfrom persistence.icache import ICachediff --git a/persistence/isms.py b/persistence/isms.pyindex e5b916a..3ddaa02 100644--- a/persistence/isms.py+++ b/persistence/isms.py@@ -1,5 +1,6 @@from abc import ABC, abstractmethod+from helpers.monitoring import tracerfrom helpers.pydantic_types.phone_numbers import PhoneNumberfrom models.readiness import ReadinessEnumdiff --git a/persistence/istore.py b/persistence/istore.pyindex 99e7d8b..63dde6a 100644--- a/persistence/istore.py+++ b/persistence/istore.py@@ -2,6 +2,7 @@ from abc import ABC, abstractmethodfrom typing import Optionalfrom uuid import UUID+from helpers.monitoring import tracerfrom models.call import CallStateModelfrom models.readiness import ReadinessEnumfrom persistence.icache import ICache