Skip to content

Commit

Permalink
fix: Move session initialization to setup_method in Fireworks provide…
Browse files Browse the repository at this point in the history
…r tests

Co-Authored-By: Alex Reibman <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and areibman committed Dec 19, 2024
1 parent 001921e commit 5a8341c
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions tests/test_fireworks_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ def setup_method(self):
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
]
# Initialize session at setup
self.session = agentops.init(api_key=self.api_key)

def test_sync_completion(self):
# Mock response for non-streaming completion
mock_response = MockFireworksResponse("Hello! How can I help you?")
self.mock_client.chat.completions.create.return_value = mock_response

# Initialize session and override
session = agentops.init(api_key=self.api_key)
self.provider.set_session(session)
# Use session from setup
self.provider.set_session(self.session)
self.provider.override()

# Test non-streaming completion
Expand All @@ -82,9 +83,8 @@ def test_sync_streaming(self):
]
self.mock_client.chat.completions.create.return_value = iter(chunks)

# Initialize session and override
session = agentops.init(api_key=self.api_key)
self.provider.set_session(session)
# Use session from setup
self.provider.set_session(self.session)
self.provider.override()

# Test streaming completion
Expand All @@ -110,9 +110,8 @@ async def test_async_completion(self):
)
self.mock_client.chat.completions.acreate = AsyncMock(return_value=mock_response)

# Initialize session and override
session = agentops.init(api_key=self.api_key)
self.provider.set_session(session)
# Use session from setup
self.provider.set_session(self.session)
self.provider.override()

# Test async non-streaming completion
Expand All @@ -133,9 +132,8 @@ async def test_async_streaming(self):
mock_response = MockAsyncGenerator(chunks)
self.mock_client.chat.completions.acreate = AsyncMock(return_value=mock_response)

# Initialize session and override
session = agentops.init(api_key=self.api_key)
self.provider.set_session(session)
# Use session from setup
self.provider.set_session(self.session)
self.provider.override()

# Test async streaming completion
Expand Down Expand Up @@ -171,16 +169,15 @@ def test_event_recording(self):
mock_response = MockFireworksResponse("Hello! How can I help you?")
self.mock_client.chat.completions.create.return_value = mock_response

# Initialize session and override
session = agentops.init(api_key=self.api_key)
self.provider.set_session(session)
# Use session from setup
self.provider.set_session(self.session)
self.provider.override()

# Make completion request
self.mock_client.chat.completions.create(model="fireworks-llama", messages=self.test_messages, stream=False)

# Verify event was recorded
events = session._events
events = self.session._events
assert len(events) > 0
assert any(isinstance(event, LLMEvent) for event in events)
llm_event = next(event for event in events if isinstance(event, LLMEvent))
Expand Down

0 comments on commit 5a8341c

Please sign in to comment.