Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
quality: Logger "warn()" method is deprecated
Clémence Lesné477b53537221
diff --git a/helpers/call_events.py b/helpers/call_events.pyindex 47be35a..41910e8 100644--- a/helpers/call_events.py+++ b/helpers/call_events.py@@ -146,9 +146,9 @@ async def on_speech_unknown_error(error_code: int,) -> None:if error_code == 8511: # Failure while trying to play the prompt- _logger.warn("Failed to play prompt")+ _logger.warning("Failed to play prompt")else:- _logger.warn(+ _logger.warning(f"Recognition failed with unknown error code {error_code}, answering with default error")await handle_recognize_text(@@ -187,17 +187,17 @@ async def on_play_error(_logger.debug("Play failed")# See: https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/communication-services/how-tos/call-automation/play-action.mdif error_code == 8535: # Action failed, file format- _logger.warn("Error during media play, file format is invalid")+ _logger.warning("Error during media play, file format is invalid")elif error_code == 8536: # Action failed, file downloaded- _logger.warn("Error during media play, file could not be downloaded")+ _logger.warning("Error during media play, file could not be downloaded")elif error_code == 8565: # Action failed, AI services config_logger.error("Error during media play, impossible to connect with Azure AI services")elif error_code == 9999: # Unknown- _logger.warn("Error during media play, unknown internal server error")+ _logger.warning("Error during media play, unknown internal server error")else:- _logger.warn(f"Error during media play, unknown error code {error_code}")+ _logger.warning(f"Error during media play, unknown error code {error_code}")async def on_ivr_recognized(@@ -212,7 +212,7 @@ async def on_ivr_recognized(CONFIG.workflow.lang.default_lang,)except ValueError:- _logger.warn(f"Unknown IVR {label}, code not implemented")+ _logger.warning(f"Unknown IVR {label}, code not implemented")return_logger.info(f"Setting call language to {lang}")@@ -305,7 +305,7 @@ async def _post_call_sms(call: CallModel) -> None:)if not content:- _logger.warn("Error generating SMS report")+ _logger.warning("Error generating SMS report")return_logger.info(f"SMS report: {content}")@@ -328,7 +328,7 @@ async def _post_call_sms(call: CallModel) -> None:)await _db.call_aset(call)else:- _logger.warn(+ _logger.warning(f"Failed SMS to {response.to}, status {response.http_status_code}, error {response.error_message}")@@ -339,7 +339,7 @@ async def _post_call_sms(call: CallModel) -> None:except HttpResponseError as e:_logger.error(f"Error sending SMS: {e}")except Exception:- _logger.warn(f"Failed SMS to {call.phone_number}", exc_info=True)+ _logger.warning(f"Failed SMS to {call.phone_number}", exc_info=True)async def _post_call_synthesis(call: CallModel) -> None:@@ -366,7 +366,7 @@ async def _post_call_synthesis(call: CallModel) -> None:)if not short or not long:- _logger.warn("Error generating synthesis")+ _logger.warning("Error generating synthesis")return_logger.info(f"Short synthesis: {short}")@@ -390,7 +390,7 @@ async def _post_call_next(call: CallModel) -> None:)if not next:- _logger.warn("Error generating next action")+ _logger.warning("Error generating next action")return_logger.info(f"Next action: {next}")diff --git a/helpers/call_llm.py b/helpers/call_llm.pyindex b81b5a8..c72bfce 100644--- a/helpers/call_llm.py+++ b/helpers/call_llm.py@@ -61,11 +61,11 @@ async def llm_completion(text: Optional[str], call: CallModel) -> Optional[str]:system=system,)except ReadError:- _logger.warn("Network error", exc_info=True)+ _logger.warning("Network error", exc_info=True)except APIError as e:- _logger.warn(f"OpenAI API call error: {e}")+ _logger.warning(f"OpenAI API call error: {e}")except SafetyCheckError as e:- _logger.warn(f"OpenAI safety check error: {e}")+ _logger.warning(f"OpenAI safety check error: {e}")return content@@ -94,9 +94,9 @@ async def llm_model(system=system,)except ReadError:- _logger.warn("Network error", exc_info=True)+ _logger.warning("Network error", exc_info=True)except APIError as e:- _logger.warn(f"OpenAI API call error: {e}")+ _logger.warning(f"OpenAI API call error: {e}")return res@@ -148,7 +148,7 @@ async def load_llm_chat(try:await safety_check(text)except SafetyCheckError as e:- _logger.warn(f"Unsafe text detected, not playing: {e}")+ _logger.warning(f"Unsafe text detected, not playing: {e}")returnshould_play_sound = False@@ -161,7 +161,7 @@ async def load_llm_chat()if _backup_model:- _logger.warn("Using backup model")+ _logger.warning("Using backup model")chat_task = asyncio.create_task(_execute_llm_chat(@@ -200,7 +200,7 @@ async def load_llm_chat(breakif hard_timeout_task.done(): # Break when hard timeout is reached- _logger.warn(+ _logger.warning(f"Hard timeout of {CONFIG.workflow.intelligence_hard_timeout_sec}s reached")# Clean up@@ -212,7 +212,7 @@ async def load_llm_chat(if (soft_timeout_task.done() and not soft_timeout_triggered): # Speak when soft timeout is reached- _logger.warn(+ _logger.warning(f"Soft timeout of {CONFIG.workflow.intelligence_soft_timeout_sec}s reached")soft_timeout_triggered = True@@ -234,11 +234,11 @@ async def load_llm_chat(await asyncio.sleep(5)except Exception:- _logger.warn("Error loading intelligence", exc_info=True)+ _logger.warning("Error loading intelligence", exc_info=True)if is_error: # Error during chatif not continue_chat or _iterations_remaining < 1: # Maximum retries reached- _logger.warn("Maximum retries reached, stopping chat")+ _logger.warning("Maximum retries reached, stopping chat")should_user_answer = Truecontent = await CONFIG.prompts.tts.error(call)style = MessageStyleEnum.NONE@@ -377,7 +377,7 @@ async def _execute_llm_chat(tools = []if not use_tools:- _logger.warn("Tools disabled for this chat")+ _logger.warning("Tools disabled for this chat")else:tools = plugins.to_openai()_logger.debug(f"Tools: {tools}")@@ -408,10 +408,10 @@ async def _execute_llm_chat(content_buffer_pointer += len(sentence)plugins.style = await _content_callback(sentence, plugins.style)except ReadError:- _logger.warn("Network error", exc_info=True)+ _logger.warning("Network error", exc_info=True)return True, True, should_user_answer, callexcept APIError as e:- _logger.warn(f"OpenAI API call error: {e}")+ _logger.warning(f"OpenAI API call error: {e}")return True, True, should_user_answer, call# Flush the remaining buffer@@ -435,12 +435,12 @@ async def _execute_llm_chat(if any(tool_call.function_name == "multi_tool_use.parallel" for tool_call in tool_calls):- _logger.warn(f'LLM send back invalid tool schema "multi_tool_use.parallel"')+ _logger.warning(f'LLM send back invalid tool schema "multi_tool_use.parallel"')return True, True, should_user_answer, call# OpenAI GPT-4 Turbo tends to return empty content, in that case, retry within limitsif not content_full and not tool_calls:- _logger.warn("Empty content, retrying")+ _logger.warning("Empty content, retrying")return True, True, should_user_answer, call# Execute toolsdiff --git a/main.py b/main.pyindex 0a4c2d2..9f91e4d 100644--- a/main.py+++ b/main.py@@ -250,10 +250,10 @@ async def _communication_event_worker() -> None:call = await _db.call_asearch_one(phone_number)if not call:- _logger.warn(f"Call {phone_number} not found")+ _logger.warning(f"Call {phone_number} not found")returnif call.callback_secret != secret:- _logger.warn(f"Secret for call {phone_number} does not match")+ _logger.warning(f"Secret for call {phone_number} does not match")returnevent = CloudEvent.from_dict(event_dict)diff --git a/persistence/ai_search.py b/persistence/ai_search.pyindex 076c072..f8950e6 100644--- a/persistence/ai_search.py+++ b/persistence/ai_search.py@@ -58,7 +58,7 @@ class AiSearchSearch(ISearch):try:return TypeAdapter(List[TrainingModel]).validate_json(cached)except ValidationError:- _logger.warn(f"Error parsing cached training: {cached}")+ _logger.warning(f"Error parsing cached training: {cached}")pass# Try live@@ -108,7 +108,7 @@ class AiSearchSearch(ISearch):))except ValidationError as e:- _logger.warn(f"Error parsing training: {e.errors()}")+ _logger.warning(f"Error parsing training: {e.errors()}")except HttpResponseError as e:_logger.error(f"Error requesting AI Search, {e}")except ServiceRequestError as e:diff --git a/persistence/cosmos_db.py b/persistence/cosmos_db.pyindex 4612964..571ec9f 100644--- a/persistence/cosmos_db.py+++ b/persistence/cosmos_db.py@@ -49,7 +49,7 @@ class CosmosDbStore(IStore):try:res = CallModel(**raw)except ValidationError as e:- _logger.warn(f"Error parsing call: {e.errors()}")+ _logger.warning(f"Error parsing call: {e.errors()}")except StopAsyncIteration:passexcept CosmosHttpResponseError as e:@@ -99,7 +99,7 @@ class CosmosDbStore(IStore):try:res = CallModel(**raw)except ValidationError as e:- _logger.warn(f"Error parsing call: {e.errors()}")+ _logger.warning(f"Error parsing call: {e.errors()}")except StopAsyncIteration:passexcept CosmosHttpResponseError as e:@@ -132,7 +132,7 @@ class CosmosDbStore(IStore):try:calls.append(CallModel(**raw))except ValidationError as e:- _logger.warn(f"Error parsing call: {e.errors()}")+ _logger.warning(f"Error parsing call: {e.errors()}")except CosmosHttpResponseError as e:_logger.error(f"Error accessing CosmosDB, {e}")return calls or Nonediff --git a/persistence/sqlite.py b/persistence/sqlite.pyindex 8946ec3..4c7efb9 100644--- a/persistence/sqlite.py+++ b/persistence/sqlite.py@@ -37,7 +37,7 @@ class SqliteStore(IStore):try:return CallModel.model_validate_json(row[0])except ValidationError as e:- _logger.warn(f"Error parsing call: {e.errors()}")+ _logger.warning(f"Error parsing call: {e.errors()}")return Noneasync def call_aset(self, call: CallModel) -> bool:@@ -70,7 +70,7 @@ class SqliteStore(IStore):try:return CallModel.model_validate_json(row[0])except ValidationError as e:- _logger.warn(f"Error parsing call: {e.errors()}")+ _logger.warning(f"Error parsing call: {e.errors()}")return Noneasync def call_asearch_all(self, phone_number: str) -> Optional[List[CallModel]]:@@ -91,7 +91,7 @@ class SqliteStore(IStore):try:calls.append(CallModel.model_validate_json(row[0]))except ValidationError as e:- _logger.warn(f"Error parsing call: {e.errors()}")+ _logger.warning(f"Error parsing call: {e.errors()}")return calls or Noneasync def _init_db(self, db: SQLiteConnection):