Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
refacto: Dedicated func for trainings
Clémence Lesnéa78b53f39cd4
diff --git a/helpers/call_llm.py b/helpers/call_llm.pyindex c72bfce..21cc367 100644--- a/helpers/call_llm.py+++ b/helpers/call_llm.py@@ -334,16 +334,8 @@ async def _execute_llm_chat(_logger.info("Chat stopped by tool")should_user_answer = False- # Build RAG using query expansion from last messages- trainings_tasks = await asyncio.gather(- *[- _search.training_asearch_all(message.content, call)- for message in call.messages[-CONFIG.ai_search.expansion_k :]- ],- )- trainings = sorted(- set(training for trainings in trainings_tasks for training in trainings or [])- ) # Flatten, remove duplicates, and sort by score+ # Build RAG+ trainings = await call.trainings()_logger.info(f"Enhancing LLM chat with {len(trainings)} trainings")_logger.debug(f"Trainings: {trainings}")diff --git a/models/call.py b/models/call.pyindex 368227d..1294b2a 100644--- a/models/call.py+++ b/models/call.py@@ -5,9 +5,11 @@ from models.message import MessageModelfrom models.next import NextModelfrom models.reminder import ReminderModelfrom models.synthesis import SynthesisModel+from models.training import TrainingModelfrom pydantic import BaseModel, Field, computed_fieldfrom typing import List, Optionalfrom uuid import UUID, uuid4+import asyncioimport randomimport string@@ -51,3 +53,27 @@ class CallModel(BaseModel):@lang.setterdef lang(self, value: LanguageEntryModel) -> None:self.lang_short_code = value.short_code++ async def trainings(self) -> List[TrainingModel]:+ """+ Get the trainings from the last messages.++ Is using query expansion from last messages. Then, data is sorted by score.+ """+ from helpers.config import CONFIG++ search = CONFIG.ai_search.instance()+ trainings_tasks = await asyncio.gather(+ *[+ search.training_asearch_all(message.content, self)+ for message in self.messages[-CONFIG.ai_search.expansion_k :]+ ],+ ) # Get trainings from last messages+ trainings = sorted(+ set(+ training+ for trainings in trainings_tasks+ for training in trainings or []+ )+ ) # Flatten, remove duplicates, and sort by score+ return trainings