44from agent .ollama_integration import (
55 check_ollama_available ,
66 get_ollama_model_name ,
7- create_ollama_model
7+ create_ollama_model ,
88)
99from agent import answer
1010import httpx
1111
1212# Suppress the coroutine warning for tests
13- warnings .filterwarnings ("ignore" ,
14- message = "coroutine '.*' was never awaited" ,
15- category = RuntimeWarning )
13+ warnings .filterwarnings (
14+ "ignore" , message = "coroutine '.*' was never awaited" , category = RuntimeWarning
15+ )
1616
1717
1818def test_check_ollama_available ():
@@ -58,7 +58,7 @@ def test_ollama_provider():
5858 mock_result .final_output = "The answer to 2+2 is 4"
5959
6060 # Patch the asyncio run function to avoid actual API calls
61- with patch (' agent.assistant.asyncio.run' , return_value = mock_result ):
61+ with patch (" agent.assistant.asyncio.run" , return_value = mock_result ):
6262 # This should now run without errors since the API call is mocked
6363 response , _ = answer ("What is 2+2?" , provider = "ollama" )
6464
@@ -97,6 +97,7 @@ def test_ollama_provider():
9797
9898 except Exception as e :
9999 import traceback
100+
100101 print (f"❌ Error testing Ollama provider: { str (e )} " )
101102 print (traceback .format_exc ())
102103 raise
@@ -113,6 +114,7 @@ def test_ollama_tool_knowledge():
113114 # Create a session to maintain context
114115 from agent .session_manager import session_manager
115116 from agents .mcp import MCPServerSse
117+
116118 session_id = session_manager .create_session ()
117119 print (f"\n Created test session: { session_id } " )
118120
@@ -188,32 +190,45 @@ async def connect_mcp_server():
188190 found_terms = [term for term in expected_terms if term in response .lower ()]
189191
190192 print (f"Found terms: { found_terms } " )
191- assert found_terms , f"Expected tool terms ({ ', ' .join (expected_terms )} ) not found in response"
193+ assert found_terms , (
194+ f"Expected tool terms ({ ', ' .join (expected_terms )} ) not found in response"
195+ )
192196
193197 # Check for specific error messages
194- assert "[] is too short - 'messages'" not in response , "Error: Empty messages array sent to Ollama API"
198+ assert "[] is too short - 'messages'" not in response , (
199+ "Error: Empty messages array sent to Ollama API"
200+ )
195201
196202 # Step 3: Test conversation history and follow-up
197203 print ("\n 3️⃣ Testing follow-up question..." )
198204 followup_query = "Can you list the tools again and explain what each one does?"
199- followup_response , _ = answer (followup_query , provider = "ollama" , session_id = session_id )
205+ followup_response , _ = answer (
206+ followup_query , provider = "ollama" , session_id = session_id
207+ )
200208 print (f"Follow-up response: { followup_response [:500 ]} ..." )
201209
202210 # Verify the response has relevant terms
203211 followup_terms = ["csv" , "sql" , "pdf" , "database" , "file" ]
204- found_followup_terms = [term for term in followup_terms if term in followup_response .lower ()]
205- assert found_followup_terms , f"Follow-up response doesn't contain expected terms"
212+ found_followup_terms = [
213+ term for term in followup_terms if term in followup_response .lower ()
214+ ]
215+ assert found_followup_terms , "Follow-up response doesn't contain expected terms"
206216
207217 # Final check: Conversation history maintained
208218 history = session_manager .get_messages (session_id )
209219 print (f"\n ✅ Session maintained context through { len (history )} messages" )
210- assert len (history ) >= 4 , "Expected at least 4 messages in conversation history (2 queries + 2 responses)"
220+ assert len (history ) >= 4 , (
221+ "Expected at least 4 messages in conversation history (2 queries + 2 responses)"
222+ )
211223
212224 print ("\n ✅ Direct Ollama integration test PASSED." )
213- print (f" Found terms in responses: { ', ' .join (found_terms + found_followup_terms )} " )
225+ print (
226+ f" Found terms in responses: { ', ' .join (found_terms + found_followup_terms )} "
227+ )
214228
215229 except Exception as e :
216230 import traceback
231+
217232 print (f"\n ❌ Direct Ollama integration test FAILED: { str (e )} " )
218233 print (traceback .format_exc ())
219234 raise
@@ -258,13 +273,13 @@ def test_provider_fallback():
258273 # Test fallback if Ollama is unavailable
259274 if not check_ollama_available ():
260275 response , result = answer ("Test" , provider = "ollama" )
261- assert (
262- "⚠️ Ollama not available" in response
263- ), "Expected unavailable message for Ollama provider"
276+ assert "⚠️ Ollama not available" in response , (
277+ "Expected unavailable message for Ollama provider"
278+ )
264279
265280 # Test fallback if OpenAI key is not set
266281 if os .getenv ("OPENAI_API_KEY" ) is None :
267282 response , result = answer ("Test" , provider = "openai" )
268- assert (
269- "⚠️ OPENAI_API_KEY not set" in response
270- ), "Expected API key message for OpenAI provider"
283+ assert "⚠️ OPENAI_API_KEY not set" in response , (
284+ "Expected API key message for OpenAI provider"
285+ )
0 commit comments