Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
conf: Let's ops decide if them want to use fast/slow LLM for chat
Clémence Lesné2a578fc32636
diff --git a/helpers/config_models/workflow.py b/helpers/config_models/workflow.pyindex 7633cfc..31af4c7 100644--- a/helpers/config_models/workflow.py+++ b/helpers/config_models/workflow.py@@ -132,6 +132,7 @@ class WorkflowModel(BaseModel):intelligence_hard_timeout_sec: int = 180 # 3 minutesintelligence_soft_timeout_sec: int = 30 # 30 secondsmax_voice_recognition_retry: int = 3+ use_slow_llm_for_chat_as_default: bool = Truedef _fields_to_pydantic(name: str, fields: list[ClaimFieldModel]) -> type[BaseModel]:diff --git a/helpers/llm_worker.py b/helpers/llm_worker.pyindex c2c02d3..23e64b2 100644--- a/helpers/llm_worker.py+++ b/helpers/llm_worker.py@@ -97,46 +97,43 @@ async def completion_stream(Completion is first made with the fast LLM, then the slow LLM if the previous fails. Catch errors for a maximum of 3 times (internal + `RateLimitError`). If it fails again, raise the error."""- # Try a three time with fast LLM+ # Try a first time with primary LLMtry:- retryed = AsyncRetrying(- reraise=True,- retry=retry_any(- *[- retry_if_exception_type(exception)- for exception in _retried_exceptions- ]- ),- stop=stop_after_attempt(- 3- ), # Usage is short-lived, so stop after 3 attempts- wait=wait_random_exponential(multiplier=0.8, max=8),- )- async for attempt in retryed:- with attempt:- async for chunck in _completion_stream_worker(- is_fast=True,- max_tokens=max_tokens,- messages=messages,- system=system,- tools=tools,- ):- yield chunck- return+ async for chunck in _completion_stream_worker(+ is_fast=not CONFIG.workflow.use_slow_llm_for_chat_as_default, # Let configuration decide+ max_tokens=max_tokens,+ messages=messages,+ system=system,+ tools=tools,+ ):+ yield chunck+ returnexcept Exception as e:if not any(isinstance(e, exception) for exception in _retried_exceptions):raise e- logger.warning(f"{e.__class__.__name__} error, trying with slow LLM")+ logger.warning(+ f"{e.__class__.__name__} error, trying with {'fast' if CONFIG.workflow.use_slow_llm_for_chat_as_default else 'slow'} LLM"+ )- # Try a last time with slow LLM, if it fails again, raise the error- async for chunck in _completion_stream_worker(- is_fast=False,- max_tokens=max_tokens,- messages=messages,- system=system,- tools=tools,- ):- yield chunck+ # Try more times with backup LLM, if it fails again, raise the error+ retryed = AsyncRetrying(+ reraise=True,+ retry=retry_any(+ *[retry_if_exception_type(exception) for exception in _retried_exceptions]+ ),+ stop=stop_after_attempt(3), # Usage is short-lived, so stop after 3 attempts+ wait=wait_random_exponential(multiplier=0.5, max=30),+ )+ async for attempt in retryed:+ with attempt:+ async for chunck in _completion_stream_worker(+ is_fast=CONFIG.workflow.use_slow_llm_for_chat_as_default, # Let configuration decide+ max_tokens=max_tokens,+ messages=messages,+ system=system,+ tools=tools,+ ):+ yield chunckasync def _completion_stream_worker(