Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

perf: Use only cached RAG for live conversations

Clémence Lesné0e15027d817e
diff --git a/helpers/call_llm.py b/helpers/call_llm.py
index 3ffebab..9dbefec 100644
--- a/helpers/call_llm.py
+++ b/helpers/call_llm.py
@@ -359,7 +359,7 @@ async def _execute_llm_chat(
return new_style
# Build RAG
- trainings = await call.trainings()
+ trainings = await call.trainings(cache_only=True)
logger.info(f"Enhancing LLM chat with {len(trainings)} trainings")
logger.debug(f"Trainings: {trainings}")
diff --git a/models/call.py b/models/call.py
index 9aabc5e..60752cb 100644
--- a/models/call.py
+++ b/models/call.py
@@ -105,7 +105,7 @@ class CallStateModel(CallGetModel):
def lang(self, short_code: str) -> None:
self.lang_short_code = short_code
- async def trainings(self) -> list[TrainingModel]:
+ async def trainings(self, cache_only: bool = False) -> list[TrainingModel]:
"""
Get the trainings from the last messages.
@@ -119,7 +119,9 @@ class CallStateModel(CallGetModel):
tasks = await asyncio.gather(
*[
search.training_asearch_all(
- text=message.content, lang=self.lang.short_code
+ cache_only=cache_only,
+ lang=self.lang.short_code,
+ text=message.content,
)
for message in self.messages[-CONFIG.ai_search.expansion_k :]
],
diff --git a/persistence/ai_search.py b/persistence/ai_search.py
index dc87223..89aea52 100644
--- a/persistence/ai_search.py
+++ b/persistence/ai_search.py
@@ -58,8 +58,9 @@ class AiSearchSearch(ISearch):
)
async def training_asearch_all(
self,
- text: str,
lang: str,
+ text: str,
+ cache_only: bool = False,
) -> Optional[list[TrainingModel]]:
logger.debug(f'Searching training data for "{text}"')
if not text:
@@ -75,6 +76,9 @@ class AiSearchSearch(ISearch):
logger.warning(f"Error parsing cached training: {cached}")
pass
+ if cache_only:
+ return None
+
# Try live
trainings: list[TrainingModel] = []
try:
diff --git a/persistence/isearch.py b/persistence/isearch.py
index 3d22e6b..e5641f9 100644
--- a/persistence/isearch.py
+++ b/persistence/isearch.py
@@ -19,7 +19,8 @@ class ISearch(ABC):
@abstractmethod
async def training_asearch_all(
self,
- text: str,
lang: str,
+ text: str,
+ cache_only: bool = False,
) -> Optional[list[TrainingModel]]:
pass