CoolFace
Apppublic

MWBadra/Context-Aware-Conversational-Agent

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
test_agent.cpython-313.pyc41 linesDownload Raw Back to __pycache__
1�

2�4�i���$�SSKrSSKrSSKrSSKJr SSKJr SSKJr SSK	J3r4 SSKJr SSK
Jr SSKJr \R""\R$S	S59 \R&"\5r"SS\R,5r\S
:Xa\R0"5 gg)�N)�load_dotenv)�ChatGroq)�ContextAwareAgentManager)�ContextPresenceJudgeTool)�
WebSearchTool)�ContextRelevanceCheckerTool)�ContextSplitterToolz)%(asctime)s - %(levelname)s - %(message)s)�level�formatc�:�\rSrSrSr\S5rSrSrSr	Sr6g)	�TestContextAwareAgent�zv7Integration Tests for the Context-Aware Agent.8Verifies that the LLM, Tools, and Agent Workflow integrate correctly.9c�`�[RS5 [5 [R"S5Ul[R"S5UlUR10(aUR(d[S5e[RS5 [SSS9Ul	[URS	9[5[URS	9[URS	9/Ul[URURS119UlUR R#5Ulg)z�12This function is run only once before all tests begin.13 14It aims to prepare the environment, models, and tools to save processing time.15 z"Setting up the test environment...�GROQ_API_KEY�TAVILY_API_KEYz<Missing API Keys in .env file. Cannot run integration tests.z)Initializing LLM and Tools for testing...rzllama-3.3-70b-versatile)�temperature�16model_name)�llm)r�toolsN)�logger�infor�os�getenv�groq_key�17tavily_key�18ValueErrorrrrrrr	rr�
agent_manager�build_agent�agent_executor)�clss �jD:\books and slides\Cellula26\Cellula\Final_Project\Context-Aware-Conversational-Agent\tests\test_agent.py�19setUpClass� TestContextAwareAgent.setUpClasss���	���8�9��
��y�y��0������#3�4����|�|�3�>�>��[�\�\����?�@��q�5N�O���
%����1��O�'�C�G�G�4��C�G�G�,�	20��	�5�����	�	�R��� �.�.�:�:�<���c��Sn[RSU35 URRUSS.5nUR	SS5nURUS5 UR
U[S5 UR[U5S:�S	5 [RS21USSS
35 g![anURSU35 SnAgSnAff=f)zY22Test Case 1: User provides context.23The agent should identify the context and NOT fail.24z>Here is my Python code: `print(x)`. It gives a NameError. Why?z.Running Test 1 (Context Provided) with query: ���input�chat_history�output�#The agent returned a None response.�$The agent response must be a string.�25�#The response is suspiciously short.z& Test 1 Passed. Agent Answer snippet: N�d�...z1 Agent crashed on context-provided query. Error: �rrr�invoke�get�assertIsNotNone�assertIsInstance�str�26assertTrue�len�	Exception�fail��self�query�result�response�es     r!�test_context_provided_flow�0TestContextAwareAgent.test_context_provided_flow3s���27Q�����D�U�G�L�M�
	O��(�(�/�/�%�QS�0T�U�F��z�z�(�B�/�H�� � ��+P�Q��!�!�(�C�1W�X��O�O�C��M�B�.�0U�V��K�K�@��$�3��@P�PS�T�U���	O��I�I�I�!��M�N�N��	O���BB0�028C�:C�Cc��Sn[RSU35 URRUSS.5nUR	SS5nURUS5 UR
U[S5 UR[U5S:�S	5 [RS29USSS
35 g![anURSU35 SnAgSnAff=f)zi30Test Case 2: User asks a general question.31The agent MUST trigger the WebSearchTool to find the answer.32z:What is the latest version of LangChain released recently?z-Running Test 2 (Context Missing) with query: r&r'r*r+r,r-r.z%Test 2 Passed. Agent Answer snippet: Nr/r0z/Agent crashed on context-missing query. Error: r1r;s     r!�test_context_missing_flow�/TestContextAwareAgent.test_context_missing_flowJs���33M�����C�E�7�K�L�	M��(�(�/�/�%�QS�0T�U�F��z�z�(�B�/�H�
� � ��+P�Q��!�!�(�C�1W�X��O�O�C��M�B�.�0U�V��K�K�?���#��?O�s�S�T���	M��I�I�G��s�K�L�L��	M�rCc��Sn[RSU35 URRUSS.5nUR	SS5nURUS5 UR
SUS5 URS	UR5S345 [RSUSS
S35 g![anURSU35 SnAgSnAff=f)z�35Test Case 3: User provides irrelevant context.36The agent MUST ignore the context using ContextRelevanceChecker and answer the core question.37z`Here is a recipe for chicken: 1 cup rice, 2 chicken breasts. How do I fix a NameError in Python?z0Running Test 3 (Irrelevant Context) with query: r&r'r*r+�	NameErrorz1The agent failed to address the Python NameError.�chickenzFThe agent hallucinated and talked about the irrelevant chicken recipe.z%Test 3 Passed. Agent Answer snippet: Nr/r0z2Agent crashed on irrelevant-context query. Error: )rrrr2r3r4�assertIn�assertNotIn�lowerr9r:r;s     r!�test_irrelevant_context_flow�2TestContextAwareAgent.test_irrelevant_context_flowbs���38s�����F�u�g�N�O�	P��(�(�/�/�%�QS�0T�U�F��z�z�(�B�/�H�� � ��+P�Q��M�M�+�x�1d�e����Y����(8�;C�
D��K�K�?���#��?O�s�S�T���	P��I�I�J�1�#�N�O�O��	P�s�BB/�/39C�9C�C�N)�__name__�40__module__�__qualname__�__firstlineno__�__doc__�classmethodr"rArErM�__static_attributes__rOr$r!r
r
s-���41�=��=�8O�.M�0Pr$r
�__main__)�unittestr�logging�dotenvr�langchain_groqr�agent.agent_runnerr�tools.context_presence_judger�tools.web_search_toolr�tools.context_relevance_checkerr�tools.context_splitterr	�basicConfig�INFO�	getLoggerrPr�TestCaser
�mainrOr$r!�<module>rfsw���	���#�7�A�/�G�6����'�,�,�/Z�[�	�	�	�8�	$��fP�H�-�-�fP�P�z���M�M�O�r$