import unittest from unittest.mock import MagicMock import numpy as np from deepsearcher.llm.base import BaseLLM, ChatResponse from deepsearcher.embedding.base import BaseEmbedding from deepsearcher.vector_db.base import BaseVectorDB, RetrievalResult, CollectionInfo class MockLLM(BaseLLM): """Mock LLM implementation for testing agents.""" def __init__(self, predefined_responses=None): """ Initialize the MockLLM. Args: predefined_responses: Dictionary mapping prompt substrings to responses """ self.chat_called = False self.last_messages = None self.predefined_responses = predefined_responses or {} def chat(self, messages, **kwargs): """Mock implementation of chat that returns predefined responses or a default response.""" self.chat_called = True self.last_messages = messages if self.predefined_responses: message_content = messages[0]["content"] if messages else "" for key, response in self.predefined_responses.items(): if key in message_content: return ChatResponse(content=response, total_tokens=10) # Default response for RERANK_PROMPT - treat all chunks as relevant if "Based on the query questions and the retrieved chunks" in message_content: # Count the number of chunks in the message chunk_count = message_content.count("