22
33import pytest
44from dotenv import load_dotenv
5+ from vision_agents .core .agents .conversation import InMemoryConversation
56from vision_agents .plugins .xai .llm import XAILLM
67
78from vision_agents .testing import collect_simple_response
89
910load_dotenv ()
1011
1112
13+ @pytest .fixture
14+ async def llm ():
15+ llm = XAILLM (model = "grok-4-latest" , api_key = os .getenv ("XAI_API_KEY" ))
16+ llm .set_conversation (InMemoryConversation ("be friendly" , []))
17+ yield llm
18+ await llm .close ()
19+
20+
1221@pytest .mark .integration
1322@pytest .mark .skipif (not os .getenv ("XAI_API_KEY" ), reason = "XAI_API_KEY not set" )
1423class TestXAILLMIntegration :
1524 """Test suite for XAILLM class with live API calls."""
1625
17- async def test_simple_response (self ):
18- llm = XAILLM (model = "grok-4-latest" , api_key = os .getenv ("XAI_API_KEY" ))
26+ async def test_simple_response (self , llm : XAILLM ):
1927 deltas , final = await collect_simple_response (
2028 llm .simple_response ("Explain quantum computing in 1 paragraph" )
2129 )
2230 assert deltas
2331 assert final .text
2432
25- async def test_memory (self ):
26- llm = XAILLM (model = "grok-4-latest" , api_key = os .getenv ("XAI_API_KEY" ))
33+ async def test_memory (self , llm : XAILLM ):
2734 await collect_simple_response (
2835 llm .simple_response (text = "There are 2 dogs in the room" )
2936 )
@@ -32,9 +39,7 @@ async def test_memory(self):
3239 )
3340 assert "8" in final .text or "eight" in final .text
3441
35- async def test_tool_calling (self ):
36- llm = XAILLM (model = "grok-4-latest" , api_key = os .getenv ("XAI_API_KEY" ))
37-
42+ async def test_tool_calling (self , llm : XAILLM ):
3843 @llm .register_function ()
3944 async def get_weather (location : str ) -> str :
4045 """Get the weather for a location."""
0 commit comments