mirror of
				https://github.com/deepset-ai/haystack.git
				synced 2025-10-31 09:49:48 +00:00 
			
		
		
		
	fix agents tests (#4237)
This commit is contained in:
		
							parent
							
								
									b193e08a64
								
							
						
					
					
						commit
						722dead1b2
					
				
							
								
								
									
										36
									
								
								.github/workflows/tests.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										36
									
								
								.github/workflows/tests.yml
									
									
									
									
										vendored
									
									
								
							| @ -92,6 +92,7 @@ jobs: | |||||||
|         topic: |         topic: | ||||||
|           - document_stores |           - document_stores | ||||||
|           - nodes |           - nodes | ||||||
|  |           - agents | ||||||
|     runs-on: ${{ matrix.os }} |     runs-on: ${{ matrix.os }} | ||||||
|     steps: |     steps: | ||||||
|       - uses: actions/checkout@v3 |       - uses: actions/checkout@v3 | ||||||
| @ -399,9 +400,37 @@ jobs: | |||||||
|           channel: '#haystack' |           channel: '#haystack' | ||||||
|         if: failure() && github.repository_owner == 'deepset-ai' && github.ref == 'refs/heads/main' |         if: failure() && github.repository_owner == 'deepset-ai' && github.ref == 'refs/heads/main' | ||||||
| 
 | 
 | ||||||
|  |   integration-tests-agents: | ||||||
|  |     name: Integration / Agents / ${{ matrix.os }} | ||||||
|  |     needs: | ||||||
|  |      - unit-tests | ||||||
|  |     strategy: | ||||||
|  |       fail-fast: false | ||||||
|  |       matrix: | ||||||
|  |         os: [ubuntu-latest,windows-latest] | ||||||
|  |     runs-on: ${{ matrix.os }} | ||||||
|  |     steps: | ||||||
|  |       - uses: actions/checkout@v3 | ||||||
|  | 
 | ||||||
|  |       - name: Setup Python | ||||||
|  |         uses: ./.github/actions/python_cache/ | ||||||
|  | 
 | ||||||
|  |       - name: Install Haystack | ||||||
|  |         run: pip install -U . | ||||||
|  | 
 | ||||||
|  |       - name: Run tests | ||||||
|  |         run: | | ||||||
|  |           pytest --maxfail=5 -m "integration" test/agents | ||||||
|  | 
 | ||||||
|  |       - uses: act10ns/slack@v2 | ||||||
|  |         with: | ||||||
|  |           status: ${{ job.status }} | ||||||
|  |           channel: '#haystack' | ||||||
|  |         if: failure() && github.repository_owner == 'deepset-ai' && github.ref == 'refs/heads/main' | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| # | # | ||||||
| # TODO: the following steps need to be revisited | # IMPORTANT: the following steps need to be revisited PLEASE DO NOT ADD ANYTHING TO THE JOBS BELOW! | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -413,7 +442,6 @@ jobs: | |||||||
|         folder: |         folder: | ||||||
|           - "nodes" |           - "nodes" | ||||||
|           - "pipelines" |           - "pipelines" | ||||||
|           - "agents" |  | ||||||
|           - "modeling" |           - "modeling" | ||||||
|           - "others" |           - "others" | ||||||
| 
 | 
 | ||||||
| @ -459,9 +487,7 @@ jobs: | |||||||
|         folder: |         folder: | ||||||
|           - "nodes" |           - "nodes" | ||||||
|           - "pipelines" |           - "pipelines" | ||||||
|           - "agents" |  | ||||||
|           - "modeling" |           - "modeling" | ||||||
|           #- "others" |  | ||||||
| 
 | 
 | ||||||
|     runs-on: windows-latest |     runs-on: windows-latest | ||||||
|     if: contains(github.event.pull_request.labels.*.name, 'topic:windows') || !github.event.pull_request.draft |     if: contains(github.event.pull_request.labels.*.name, 'topic:windows') || !github.event.pull_request.draft | ||||||
| @ -510,7 +536,6 @@ jobs: | |||||||
|         folder: |         folder: | ||||||
|           - "nodes" |           - "nodes" | ||||||
|           - "pipelines" |           - "pipelines" | ||||||
|           - "agents" |  | ||||||
|           - "modeling" |           - "modeling" | ||||||
|           - "others" |           - "others" | ||||||
| 
 | 
 | ||||||
| @ -606,7 +631,6 @@ jobs: | |||||||
|         folder: |         folder: | ||||||
|           - "nodes" |           - "nodes" | ||||||
|           - "pipelines" |           - "pipelines" | ||||||
|           - "agents" |  | ||||||
|           - "modeling" |           - "modeling" | ||||||
|           - "others" |           - "others" | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ from haystack.pipelines import ExtractiveQAPipeline, DocumentSearchPipeline, Bas | |||||||
| from test.conftest import MockRetriever, MockPromptNode | from test.conftest import MockRetriever, MockPromptNode | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.mark.unit | ||||||
| def test_add_and_overwrite_tool(): | def test_add_and_overwrite_tool(): | ||||||
|     # Add a Node as a Tool to an Agent |     # Add a Node as a Tool to an Agent | ||||||
|     agent = Agent(prompt_node=MockPromptNode()) |     agent = Agent(prompt_node=MockPromptNode()) | ||||||
| @ -52,6 +53,7 @@ def test_add_and_overwrite_tool(): | |||||||
|     assert isinstance(agent.tools["Retriever"].pipeline_or_node, BaseStandardPipeline) |     assert isinstance(agent.tools["Retriever"].pipeline_or_node, BaseStandardPipeline) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.mark.unit | ||||||
| def test_agent_chooses_no_action(): | def test_agent_chooses_no_action(): | ||||||
|     agent = Agent(prompt_node=MockPromptNode()) |     agent = Agent(prompt_node=MockPromptNode()) | ||||||
|     retriever = MockRetriever() |     retriever = MockRetriever() | ||||||
| @ -66,6 +68,7 @@ def test_agent_chooses_no_action(): | |||||||
|         agent.run("How many letters does the name of the town where Christelle lives have?") |         agent.run("How many letters does the name of the town where Christelle lives have?") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.mark.unit | ||||||
| def test_max_iterations(caplog, monkeypatch): | def test_max_iterations(caplog, monkeypatch): | ||||||
|     # Run an Agent and stop because max_iterations is reached |     # Run an Agent and stop because max_iterations is reached | ||||||
|     agent = Agent(prompt_node=MockPromptNode(), max_iterations=3) |     agent = Agent(prompt_node=MockPromptNode(), max_iterations=3) | ||||||
| @ -97,6 +100,7 @@ def test_max_iterations(caplog, monkeypatch): | |||||||
|     assert "Maximum number of iterations (2) reached" in caplog.text |     assert "Maximum number of iterations (2) reached" in caplog.text | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.mark.unit | ||||||
| def test_run_tool(): | def test_run_tool(): | ||||||
|     agent = Agent(prompt_node=MockPromptNode()) |     agent = Agent(prompt_node=MockPromptNode()) | ||||||
|     retriever = MockRetriever() |     retriever = MockRetriever() | ||||||
| @ -111,6 +115,7 @@ def test_run_tool(): | |||||||
|     assert result[0]["documents"] == [] |     assert result[0]["documents"] == [] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.mark.unit | ||||||
| def test_extract_observation(): | def test_extract_observation(): | ||||||
|     agent = Agent(prompt_node=MockPromptNode()) |     agent = Agent(prompt_node=MockPromptNode()) | ||||||
|     observation = agent._extract_observation( |     observation = agent._extract_observation( | ||||||
| @ -124,6 +129,7 @@ def test_extract_observation(): | |||||||
|     assert observation == "first answer" |     assert observation == "first answer" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.mark.unit | ||||||
| def test_extract_tool_name_and_tool_input(): | def test_extract_tool_name_and_tool_input(): | ||||||
|     agent = Agent(prompt_node=MockPromptNode()) |     agent = Agent(prompt_node=MockPromptNode()) | ||||||
| 
 | 
 | ||||||
| @ -132,6 +138,7 @@ def test_extract_tool_name_and_tool_input(): | |||||||
|     assert tool_name == "Search" and tool_input == "Where was Jeremy McKinnon born" |     assert tool_name == "Search" and tool_input == "Where was Jeremy McKinnon born" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.mark.unit | ||||||
| def test_extract_final_answer(): | def test_extract_final_answer(): | ||||||
|     agent = Agent(prompt_node=MockPromptNode()) |     agent = Agent(prompt_node=MockPromptNode()) | ||||||
| 
 | 
 | ||||||
| @ -140,6 +147,7 @@ def test_extract_final_answer(): | |||||||
|     assert final_answer == "Florida" |     assert final_answer == "Florida" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.mark.unit | ||||||
| def test_format_answer(): | def test_format_answer(): | ||||||
|     agent = Agent(prompt_node=MockPromptNode()) |     agent = Agent(prompt_node=MockPromptNode()) | ||||||
|     formatted_answer = agent._format_answer(query="query", answer="answer", transcript="transcript") |     formatted_answer = agent._format_answer(query="query", answer="answer", transcript="transcript") | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Massimiliano Pippi
						Massimiliano Pippi