Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
refacto: Use native tuple type instead of typing lib
Clémence Lesné6a9a1dedb0b8
diff --git a/helpers/call_llm.py b/helpers/call_llm.pyindex 41fd5a0..45a5c6e 100644--- a/helpers/call_llm.py+++ b/helpers/call_llm.py@@ -1,4 +1,4 @@-from typing import Awaitable, Callable, Optional, Tuple, Type+from typing import Awaitable, Callable, Optional, Typefrom azure.communication.callautomation.aio import CallAutomationClientfrom helpers.config import CONFIGfrom helpers.logging import logger@@ -310,7 +310,7 @@ async def _execute_llm_chat(post_callback: Callable[[CallStateModel], None],tts_callback: Callable[[str, MessageStyleEnum], Awaitable[None]],use_tools: bool,-) -> Tuple[bool, bool, CallStateModel]:+) -> tuple[bool, bool, CallStateModel]:"""Perform the chat with the LLM model.diff --git a/helpers/config_models/conversation.py b/helpers/config_models/conversation.pyindex 0c7b98e..9b324c7 100644--- a/helpers/config_models/conversation.py+++ b/helpers/config_models/conversation.py@@ -3,7 +3,7 @@ from helpers.pydantic_types.phone_numbers import PhoneNumberfrom models.claim import ClaimFieldModel, ClaimTypeEnumfrom pydantic import BaseModel, EmailStr, Field, create_model, ConfigDictfrom pydantic.fields import FieldInfo-from typing import Annotated, Any, Optional, Tuple, Union+from typing import Annotated, Any, Optional, Unionclass LanguageEntryModel(BaseModel):@@ -189,7 +189,7 @@ def _fields_to_pydantic(name: str, fields: list[ClaimFieldModel]) -> type[BaseModef _field_to_pydantic(field: ClaimFieldModel,-) -> Union[Annotated[Any, ...], Tuple[type, FieldInfo]]:+) -> Union[Annotated[Any, ...], tuple[type, FieldInfo]]:type = _type_to_pydantic(field.type)return (Optional[type],diff --git a/helpers/config_models/llm.py b/helpers/config_models/llm.pyindex 4ece3c1..fd42c04 100644--- a/helpers/config_models/llm.py+++ b/helpers/config_models/llm.py@@ -2,7 +2,7 @@ from azure.identity import ManagedIdentityCredential, get_bearer_token_providerfrom enum import Enumfrom openai import AsyncAzureOpenAI, AsyncOpenAIfrom pydantic import field_validator, SecretStr, BaseModel, ValidationInfo, Field-from typing import Any, Optional, Tuple, Union+from typing import Any, Optional, Unionclass ModeEnum(str, Enum):@@ -27,7 +27,7 @@ class AzureOpenaiPlatformModel(AbstractPlatformModel):deployment: strendpoint: str- def instance(self) -> Tuple[AsyncAzureOpenAI, AbstractPlatformModel]:+ def instance(self) -> tuple[AsyncAzureOpenAI, AbstractPlatformModel]:if not self._client:api_key = self.api_key.get_secret_value() if self.api_key else Nonetoken_func = (@@ -56,7 +56,7 @@ class OpenaiPlatformModel(AbstractPlatformModel):api_key: SecretStrendpoint: str- def instance(self) -> Tuple[AsyncOpenAI, AbstractPlatformModel]:+ def instance(self) -> tuple[AsyncOpenAI, AbstractPlatformModel]:if not self._client:self._client = AsyncOpenAI(**self._client_kwargs,diff --git a/helpers/llm_utils.py b/helpers/llm_utils.pyindex f3eb8e0..c1c5adc 100644--- a/helpers/llm_utils.py+++ b/helpers/llm_utils.py@@ -232,7 +232,7 @@ async def _parameters(def _missing_annotations(typed_signature: inspect.Signature, required_params: set[str]-) -> Tuple[set[str], set[str]]:+) -> tuple[set[str], set[str]]:"""Get the missing annotations of a function and return them as a set.diff --git a/helpers/llm_worker.py b/helpers/llm_worker.pyindex 11b963b..a1cf4bb 100644--- a/helpers/llm_worker.py+++ b/helpers/llm_worker.py@@ -39,7 +39,7 @@ from helpers.resources import resources_dirfrom models.message import MessageModelfrom opentelemetry.instrumentation.openai import OpenAIInstrumentorfrom os import environ-from typing import AsyncGenerator, Optional, Tuple, Type, TypeVar, Union+from typing import AsyncGenerator, Optional, Type, TypeVar, Unionimport jsonimport tiktoken@@ -423,7 +423,7 @@ def _count_tokens(content: str, model: str) -> int:def _use_llm(is_fast: bool,-) -> Tuple[Union[AsyncAzureOpenAI, AsyncOpenAI], LlmAbstractPlatformModel]:+) -> tuple[Union[AsyncAzureOpenAI, AsyncOpenAI], LlmAbstractPlatformModel]:"""Returns an LLM client and platform model.diff --git a/models/message.py b/models/message.pyindex d5c9f69..db1e158 100644--- a/models/message.py+++ b/models/message.py@@ -1,7 +1,7 @@from datetime import datetime, UTCfrom enum import Enumfrom pydantic import BaseModel, Field, field_validator-from typing import Any, Optional, Tuple, Union+from typing import Any, Optional, Unionfrom openai.types.chat import (ChatCompletionAssistantMessageParam,ChatCompletionMessageToolCallParam,@@ -219,7 +219,7 @@ def remove_message_action(text: str) -> str:return content.strip() if content else ""-def extract_message_style(text: str) -> Tuple[Optional[StyleEnum], str]:+def extract_message_style(text: str) -> tuple[Optional[StyleEnum], str]:"""Detect the style of a message."""diff --git a/tests/conftest.py b/tests/conftest.pyindex dcdeb59..3c2adc2 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -6,7 +6,7 @@ from langchain_core.language_models import BaseChatModelfrom langchain_openai import AzureChatOpenAIfrom models.call import CallStateModel, CallInitiateModelfrom textwrap import dedent-from typing import Any, Callable, Optional, Tuple, Union+from typing import Any, Callable, Optional, Unionimport hashlibimport pytestimport random@@ -165,11 +165,11 @@ class DeepEvalAzureOpenAI(GPTModel):self._cache = cacheself._model = AzureChatOpenAI(**_langchain_kwargs)- def generate(self, prompt: str) -> Tuple[str, float]:+ def generate(self, prompt: str) -> tuple[str, float]:prompt = dedent(prompt).strip()cache_key = self._cache_key(prompt)# Try cache- content: Tuple[str, float] = self._cache.get(cache_key, None)+ content: tuple[str, float] = self._cache.get(cache_key, None)if content:return content# Try live@@ -178,11 +178,11 @@ class DeepEvalAzureOpenAI(GPTModel):self._cache.set(cache_key, res)return res- async def a_generate(self, prompt: str) -> Tuple[str, float]:+ async def a_generate(self, prompt: str) -> tuple[str, float]:prompt = dedent(prompt).strip()cache_key = self._cache_key(prompt)# Try cache- content: Tuple[str, float] = self._cache.get(cache_key, None)+ content: tuple[str, float] = self._cache.get(cache_key, None)if content:return content# Try live