Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
ops: Add more spans for persistence and chat plus enhance existing names
Clémence Lesnéf7cbc3fcd51e
diff --git a/helpers/call_llm.py b/helpers/call_llm.pyindex bee534e..f9f84ea 100644--- a/helpers/call_llm.py+++ b/helpers/call_llm.py@@ -19,6 +19,7 @@ from helpers.llm_worker import (completion_stream,)from helpers.logging import logger+from helpers.monitoring import tracerfrom models.call import CallStateModelfrom models.message import (ActionEnum as MessageAction,@@ -34,6 +35,7 @@ _cache = CONFIG.cache.instance()_db = CONFIG.database.instance()[email protected]_as_current_span("call_load_llm_chat")async def load_llm_chat(call: CallStateModel,client: CallAutomationClient,@@ -231,6 +233,7 @@ async def load_llm_chat(return call[email protected]_as_current_span("call_execute_llm_chat")async def _execute_llm_chat(call: CallStateModel,client: CallAutomationClient,diff --git a/helpers/llm_worker.py b/helpers/llm_worker.pyindex de4465e..a0ee250 100644--- a/helpers/llm_worker.py+++ b/helpers/llm_worker.py@@ -79,7 +79,7 @@ _retried_exceptions = [][email protected]_as_current_span("completion_stream")[email protected]_as_current_span("llm_completion_stream")async def completion_stream(max_tokens: int,messages: list[MessageModel],@@ -241,7 +241,7 @@ async def _completion_stream_worker(stop=stop_after_attempt(3),wait=wait_random_exponential(multiplier=0.8, max=8),)[email protected]_as_current_span("completion_sync")[email protected]_as_current_span("llm_completion_sync")async def completion_sync(res_type: type[T],system: list[ChatCompletionSystemMessageParam],diff --git a/models/call.py b/models/call.pyindex d2e6edc..31945b6 100644--- a/models/call.py+++ b/models/call.py@@ -116,7 +116,7 @@ class CallStateModel(CallGetModel, extra="ignore"):"""from helpers.config import CONFIG # pylint: disable=import-outside-toplevel- with tracer.start_as_current_span("trainings"):+ with tracer.start_as_current_span("call_trainings"):search = CONFIG.ai_search.instance()tasks = await asyncio.gather(*[diff --git a/models/message.py b/models/message.pyindex 50e0da5..28e3068 100644--- a/models/message.py+++ b/models/message.py@@ -112,7 +112,7 @@ class ToolModel(BaseModel):returnwith tracer.start_as_current_span(- name="execute_function",+ name="message_execute_function",attributes={"args": json.dumps(args),"name": name,diff --git a/persistence/icache.py b/persistence/icache.pyindex a44595c..d86b245 100644--- a/persistence/icache.py+++ b/persistence/icache.py@@ -8,17 +8,21 @@ from models.readiness import ReadinessEnumclass ICache(ABC):@abstractmethod+ @tracer.start_as_current_span("cache_areadiness")async def areadiness(self) -> ReadinessEnum:pass@abstractmethod+ @tracer.start_as_current_span("cache_aconnect")async def aget(self, key: str) -> Optional[bytes]:pass@abstractmethod+ @tracer.start_as_current_span("cache_aset")async def aset(self, key: str, value: Union[str, bytes, None]) -> bool:pass@abstractmethod+ @tracer.start_as_current_span("cache_adel")async def adel(self, key: str) -> bool:passdiff --git a/persistence/isearch.py b/persistence/isearch.pyindex da7c563..aafe617 100644--- a/persistence/isearch.py+++ b/persistence/isearch.py@@ -14,10 +14,12 @@ class ISearch(ABC):self._cache = cache@abstractmethod+ @tracer.start_as_current_span("search_areadiness")async def areadiness(self) -> ReadinessEnum:pass@abstractmethod+ @tracer.start_as_current_span("search_asearch_all")async def training_asearch_all(self,lang: str,diff --git a/persistence/isms.py b/persistence/isms.pyindex 3ddaa02..50ba369 100644--- a/persistence/isms.py+++ b/persistence/isms.py@@ -8,9 +8,11 @@ from models.readiness import ReadinessEnumclass ISms(ABC):@abstractmethod+ @tracer.start_as_current_span("sms_areadiness")async def areadiness(self) -> ReadinessEnum:pass@abstractmethod+ @tracer.start_as_current_span("sms_asend")async def asend(self, content: str, phone_number: PhoneNumber) -> bool:passdiff --git a/persistence/istore.py b/persistence/istore.pyindex 63dde6a..b0ee584 100644--- a/persistence/istore.py+++ b/persistence/istore.py@@ -15,22 +15,27 @@ class IStore(ABC):self._cache = cache@abstractmethod+ @tracer.start_as_current_span("store_areadiness")async def areadiness(self) -> ReadinessEnum:pass@abstractmethod+ @tracer.start_as_current_span("store_call_aget")async def call_aget(self, call_id: UUID) -> Optional[CallStateModel]:pass@abstractmethod+ @tracer.start_as_current_span("store_call_aset")async def call_aset(self, call: CallStateModel) -> bool:pass@abstractmethod+ @tracer.start_as_current_span("store_call_adel")async def call_asearch_one(self, phone_number: str) -> Optional[CallStateModel]:pass@abstractmethod+ @tracer.start_as_current_span("store_call_adel")async def call_asearch_all(self,count: int,