Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Fireworks Python SDK support #592

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b3035d7
feat: Add Fireworks provider integration
devin-ai-integration[bot] Dec 17, 2024
84e44b3
docs: Add Fireworks integration documentation
devin-ai-integration[bot] Dec 17, 2024
e822933
feat: Add Fireworks example notebook
devin-ai-integration[bot] Dec 17, 2024
58fee49
fix: Update Fireworks provider to handle streaming responses and fix …
devin-ai-integration[bot] Dec 18, 2024
2608f16
feat: Add Fireworks provider registration and example notebooks
devin-ai-integration[bot] Dec 18, 2024
566ced9
style: Fix formatting issues and add noqa for E402
devin-ai-integration[bot] Dec 18, 2024
8c8fa36
fix: Improve prompt formatting and streaming event handling
devin-ai-integration[bot] Dec 18, 2024
bb3b056
refactor: Update end_session to return detailed statistics
devin-ai-integration[bot] Dec 18, 2024
26c71cf
style: Apply ruff-format changes to improve code formatting
devin-ai-integration[bot] Dec 18, 2024
68b276e
fix: Improve prompt formatting and streaming event handling
devin-ai-integration[bot] Dec 18, 2024
e9a5a34
fix: Update Fireworks provider with proper sync/async handling
devin-ai-integration[bot] Dec 18, 2024
0f10f0a
style: Apply ruff-format changes to improve code formatting
devin-ai-integration[bot] Dec 18, 2024
9d22c6e
style: Apply additional ruff-format changes
devin-ai-integration[bot] Dec 18, 2024
a28c0f1
fix: Update notebook to handle async code without cell magic
devin-ai-integration[bot] Dec 18, 2024
49d3f27
fix: Update Fireworks provider and notebook for proper event tracking
devin-ai-integration[bot] Dec 18, 2024
74eed4a
test: Add comprehensive tests for FireworksProvider
devin-ai-integration[bot] Dec 18, 2024
c5d6c21
style: Apply ruff-format changes to improve code formatting
devin-ai-integration[bot] Dec 18, 2024
9cb419d
style: Apply ruff-format changes to improve code formatting
devin-ai-integration[bot] Dec 18, 2024
bf9355a
style: Apply ruff-format changes to consolidate multi-line statements
devin-ai-integration[bot] Dec 18, 2024
7203a76
style: Apply ruff-format changes to test file
devin-ai-integration[bot] Dec 18, 2024
001921e
fix: Update Fireworks provider tests to use correct session management
devin-ai-integration[bot] Dec 19, 2024
5a8341c
fix: Move session initialization to setup_method in Fireworks provide…
devin-ai-integration[bot] Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import traceback
from decimal import Decimal
from functools import cached_property
from typing import List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Set, Tuple, Union
from uuid import UUID, uuid4

from termcolor import colored
Expand Down Expand Up @@ -247,7 +247,7 @@
end_state_reason: Optional[str] = None,
video: Optional[str] = None,
is_auto_end: Optional[bool] = None,
) -> Optional[Decimal]:
) -> Optional[Dict[str, Any]]:
"""
End the current session with the AgentOps service.

Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Change in Return Type from Decimal to Dict
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is significant and can lead to logical errors if not handled properly. This change requires a thorough review of all the places where this function is called to ensure that the new return type is managed correctly.

Actionable Steps:

  • Audit Call Sites: Review all instances where this function is called to ensure they handle the new dictionary return type. This includes updating any logic that previously expected a Decimal.
  • Update Documentation: Ensure that the function's documentation reflects the new return type and provides guidance on how to handle it.
  • Testing: Implement unit tests to verify that the function behaves as expected with the new return type and that all calling code is updated accordingly.

This change is critical and should be prioritized to prevent runtime errors and ensure system stability. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Change in Return Type from Decimal to Dict
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is significant and can potentially break existing code that relies on the previous return type. This change should be carefully reviewed and tested to ensure compatibility across the codebase.

Actionable Steps:

  • Review Usage: Identify all instances where this function is called and ensure that the calling code can handle a Dict[str, Any] instead of a Decimal.
  • Update Documentation: Modify the function's docstring to reflect the new return type and provide examples of the expected dictionary structure.
  • Testing: Update existing tests to accommodate the new return type and add new tests if necessary to cover edge cases.
  • Communicate Changes: Inform the team about this change to ensure that everyone is aware and can make necessary adjustments in their respective modules.

This change is critical and should be handled with caution to avoid runtime errors or unexpected behavior in the application.

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Use docstrings for modules, functions, and classes
• Write unit tests for your code


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is a major modification that can have widespread implications on the codebase. This change can lead to runtime errors or incorrect behavior if the calling code is not updated to handle the new return type.

Actionable Steps:

  • Review Usage: Thoroughly review all instances where this function is called to ensure they are compatible with the new return type.
  • Update Dependent Code: Modify any code that processes the return value to handle a dictionary instead of a decimal.
  • Documentation: Update the function's documentation to reflect the new return type and provide examples of how to handle it.
  • Migration Guide: Consider creating a migration guide to assist other developers in adapting to this change.

This change should be communicated clearly to all team members to prevent any unexpected issues in the system. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant API Contract Change Detected
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is a major alteration in the API contract. This can potentially break existing code that relies on the previous return type.

Actionable Steps:

  • Review Usage: Thoroughly review all instances where this function is used in the codebase to ensure compatibility with the new return type.
  • Update Dependent Code: Modify any dependent code to handle the new return type appropriately. This may involve changes in how the return value is processed or stored.
  • Documentation: If this function is part of a public API, update the documentation to reflect the change. Consider providing a migration guide to assist users in adapting to the new return type.
  • Testing: Implement comprehensive tests to ensure that the new return type is handled correctly across the application.

This change is critical and should be handled with care to avoid introducing bugs or breaking existing functionality. 🛠️


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is a major modification that can potentially break existing code that depends on this function. This change requires a thorough review of all instances where this function is used to ensure compatibility with the new return type.

Actionable Steps:

  • Review Usage: Identify all places in the codebase where this function is called and verify that the new return type is handled correctly.
  • Update Dependent Code: Modify any dependent code to accommodate the new return type. This may involve changes in how the return value is processed or stored.
  • Documentation: Update the function's documentation to reflect the new return type and provide examples of how to handle it.
  • Testing: Implement comprehensive tests to ensure that the function behaves as expected with the new return type and that no existing functionality is broken.

This change is critical and should be approached with caution to avoid introducing bugs into the system. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is a major modification that can impact any code that depends on this function. This change requires a thorough review of all instances where this function is used to ensure compatibility with the new return type.

Actionable Steps:

  • Audit Usage: Identify all places in the codebase where this function is called.
  • Update Dependent Code: Modify the calling code to handle the new return type, Dict[str, Any]. This may involve updating how the return value is processed, stored, or passed to other functions.
  • Testing: Implement comprehensive tests to ensure that the changes do not introduce any regressions or new bugs.
  • Documentation: Update any relevant documentation to reflect the change in the return type and its implications.

This change is critical and should be handled with care to avoid breaking existing functionality. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is a major modification that can have widespread implications on the codebase. This alteration can lead to runtime errors or unexpected behavior if the calling code is not updated to handle the new return type.

Actionable Steps:

  • Review Usage: Thoroughly review all instances where this function is called to ensure they are compatible with the new return type.
  • Update Dependent Code: Modify any code that processes the return value to handle a dictionary instead of a decimal.
  • Migration Guide: If this function is part of a public API, consider providing a migration guide or a deprecation warning to inform users of the change.
  • Testing: Implement comprehensive tests to verify that the new return type is handled correctly across the application.

This change is critical and should be approached with caution to prevent breaking existing functionality. 🛠️


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Ensure Compatibility with New Return Type
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is significant and can lead to logical errors if not handled properly. Here are the steps to address this:

  • Review Usage: Thoroughly review all instances where this function is called to ensure that the new return type is handled correctly. This includes checking for any operations that expect a Decimal and updating them to handle a dictionary.
  • Update Documentation: Modify the function's docstring to clearly describe the new return type and the structure of the dictionary being returned. This will help other developers understand the expected output.
  • Test Cases: Update or add test cases to cover scenarios with the new return type. This ensures that the function behaves as expected and helps catch any issues early.
  • Communicate Changes: Inform the team about this change, especially if this function is part of a public API or widely used module, to prevent any unexpected runtime errors.

By following these steps, you can mitigate the risk of introducing bugs due to this change. 🛠️

📜 Guidelines

• Use docstrings for modules, functions, and classes • Use type annotations to improve code clarity and maintainability • Write unit tests for your code


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant API Change: Return Type Modification
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is a significant alteration in the function's API. This modification can lead to runtime errors in any part of the codebase that relies on the previous return type. It is crucial to:

  • Review all usages of this function across the codebase to ensure compatibility with the new return type.
  • Update dependent code to handle the new return type appropriately. This might involve changes in how the return value is processed or stored.
  • Consider providing a migration guide if this function is part of a public API, to assist users in adapting to the change.

This change should be communicated clearly to all stakeholders to prevent unexpected issues in production environments. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is a major alteration that can impact any code relying on this function. This change requires a thorough review of all instances where this function is used to ensure compatibility with the new return type.

Actionable Steps:

  • Audit Usage: Review all codebases where this function is called to identify potential issues with the new return type.
  • Update Dependent Code: Modify any dependent code to handle the Dict[str, Any] return type appropriately. This may involve changes in how the return value is processed or stored.
  • Documentation: Update the function's documentation to reflect the new return type and provide examples of how to handle it.
  • Migration Guide: Consider creating a migration guide to assist developers in adapting to this change, especially if this function is widely used.

This change is critical and should be communicated clearly to all developers involved in the project to prevent runtime errors or logical issues. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is a major modification that can have widespread implications on the codebase. This change can lead to runtime errors or incorrect behavior if the calling code is not updated to handle the new return type.

Actionable Steps:

  • Review Usage: Thoroughly review all instances where this function is called to ensure they are compatible with the new return type.
  • Update Dependent Code: Modify any code that processes the return value to handle a dictionary instead of a decimal.
  • Documentation: Update the function's documentation to clearly describe the new return type and its structure.
  • Migration Path: Consider providing a migration guide or notes to assist other developers in adapting their code to this change.

This change should be communicated clearly to the team to prevent any unexpected issues in the application. 📢

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 247 to 253

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Optional[Decimal] to Optional[Dict[str, Any]] is a major modification that can potentially break existing code that depends on the previous return type. This change requires a thorough review of all code that calls this function to ensure compatibility with the new return type.

Actionable Steps:

  • Review Usage: Identify all instances where this function is used and verify that the calling code can handle a Dict[str, Any] instead of a Decimal.
  • Update Dependent Code: Modify any dependent code to correctly process the new return type. This might involve changes in how the return value is accessed and used.
  • Documentation: Update any relevant documentation to reflect this change. If this function is part of a public API, consider providing a migration guide for external users.
  • Testing: Ensure that unit tests are updated or added to cover the new return type and its usage scenarios.

This change is critical and should be handled with care to avoid introducing bugs into the system. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Expand All @@ -258,17 +258,15 @@
is_auto_end (bool, optional): is this an automatic use of end_session and should be skipped with skip_auto_end_session

Returns:
Decimal: The token cost of the session. Returns 0 if the cost is unknown.
Dict[str, Any]: Session statistics including duration, cost, and event counts.
"""
session = self._safe_get_session()
if session is None:
return
return None

Check warning on line 265 in agentops/client.py

View check run for this annotation

Codecov / codecov/patch

agentops/client.py#L265

Added line #L265 was not covered by tests
if is_auto_end and self._config.skip_auto_end_session:
return

token_cost = session.end_session(end_state=end_state, end_state_reason=end_state_reason, video=video)
return None

Check warning on line 267 in agentops/client.py

View check run for this annotation

Codecov / codecov/patch

agentops/client.py#L267

Added line #L267 was not covered by tests

return token_cost
return session.end_session(end_state=end_state, end_state_reason=end_state_reason, video=video)

def create_agent(
self,
Comment on lines 258 to 272

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Change in Return Type from Decimal to Dict
The change in the return type from Decimal to Dict[str, Any] is significant and can potentially break existing code that relies on the previous return type. This change should be carefully reviewed to ensure that all parts of the codebase that use this function are updated to handle the new return type correctly.

Actionable Steps:

  • Audit Usage: Review all instances where this function is called to ensure they are compatible with the new return type.
  • Update Dependent Code: Modify any dependent code to handle the dictionary structure, extracting necessary information such as duration, cost, and event counts.
  • Testing: Implement comprehensive tests to verify that the changes do not introduce any regressions or unexpected behavior.

This change is critical and should be handled with caution to avoid breaking existing functionality. 🛠️


Comment on lines 258 to 272

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Ensure Compatibility with Updated Return Type
The recent change in the return type from Decimal to Dict[str, Any] for session statistics is a significant modification that can lead to logical errors if not handled properly. This change requires a thorough review of all calling code to ensure compatibility with the new return type.

Actionable Steps:

  • Audit Calling Code: Identify all instances where this function is called and ensure that the calling code is updated to handle a dictionary instead of a decimal.
  • Update Logic: Modify any logic that processes the return value to extract and use the necessary information from the dictionary, such as cost, duration, and event counts.
  • Testing: Implement comprehensive tests to verify that the updated logic correctly handles the new return type and that no runtime errors occur.

This change is critical as it affects the core functionality of session handling and could lead to incorrect behavior if not addressed properly. 🛠️

📜 Guidelines

• Encourage type annotations for clarity and error reduction


Comment on lines 258 to 272

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Return Type from Decimal to Dictionary
The change in the return type from Decimal to Dict[str, Any] is a significant modification that can impact any existing code relying on the previous return type. This change requires a thorough review of all dependent code to ensure compatibility with the new return type.

Actionable Steps:

  • Review Usage: Identify all instances where this function is called and ensure that the calling code is updated to handle a dictionary instead of a Decimal.
  • Update Documentation: Ensure that all documentation and comments reflect the new return type and its structure.
  • Testing: Implement comprehensive tests to verify that the function behaves as expected with the new return type and that all dependent code is functioning correctly.
  • Communicate Changes: Inform all team members and stakeholders about this change to prevent any unexpected issues in the production environment.

This change is critical and should be handled with care to avoid breaking existing functionality. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Expand Down
175 changes: 175 additions & 0 deletions agentops/llms/providers/fireworks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import logging
import time
import asyncio
from typing import Optional, AsyncGenerator
import pprint
from agentops.session import Session
from agentops.helpers import get_ISO_time
from agentops.event import LLMEvent
from agentops.enums import EventType
from .instrumented_provider import InstrumentedProvider

logger = logging.getLogger(__name__)


class FireworksProvider(InstrumentedProvider):
"""Provider for Fireworks.ai API."""

def __init__(self, client):
super().__init__(client)
self._provider_name = "Fireworks"
self._original_completion = None
self._original_async_completion = None
self._session = None # Initialize session attribute
self._accumulated_content = "" # Track accumulated content for streaming
self._init_timestamp = None # Track stream start time
logger.info(f"Initializing {self._provider_name} provider")

Check warning on line 26 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L19-L26

Added lines #L19 - L26 were not covered by tests

def set_session(self, session: Session):
"""Set the session for event tracking."""
self._session = session
logger.debug(f"Set session {session.session_id} for {self._provider_name} provider")

Check warning on line 31 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L30-L31

Added lines #L30 - L31 were not covered by tests

async def handle_response(self, response, kwargs, init_timestamp, session: Optional[Session] = None) -> dict:
"""Handle the response from the Fireworks API."""
try:

Check warning on line 35 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L35

Added line #L35 was not covered by tests
# Use existing session if provided, otherwise use provider's session
current_session = session if session else self._session

Check warning on line 37 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L37

Added line #L37 was not covered by tests
if not current_session:
logger.warning("No session available for event tracking")
return response

Check warning on line 40 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L39-L40

Added lines #L39 - L40 were not covered by tests

# Pass ChatML messages directly to LLMEvent
messages = kwargs.get("messages", [])
logger.debug(f"Using ChatML messages: {messages}")

Check warning on line 44 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L43-L44

Added lines #L43 - L44 were not covered by tests

# Create base LLMEvent
event = LLMEvent(

Check warning on line 47 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L47

Added line #L47 was not covered by tests
model=kwargs.get("model", ""),
prompt=messages, # Pass ChatML messages directly
init_timestamp=init_timestamp,
end_timestamp=time.time(),
completion="", # Will be updated for streaming responses
prompt_tokens=0, # Will be updated based on response
completion_tokens=0,
cost=0.0,
)

# Handle streaming response
if kwargs.get("stream", False):
async def async_generator(stream_response):
accumulated_content = ""
try:

Check warning on line 62 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L60-L62

Added lines #L60 - L62 were not covered by tests
async for chunk in stream_response:
if hasattr(chunk, "choices") and chunk.choices:
content = chunk.choices[0].delta.content if hasattr(chunk.choices[0].delta, "content") else ""

Check warning on line 65 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L65

Added line #L65 was not covered by tests
if content:
accumulated_content += content
yield chunk

Check warning on line 68 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L67-L68

Added lines #L67 - L68 were not covered by tests
# Update event with final accumulated content
event.completion = accumulated_content
event.end_timestamp = time.time()

Check warning on line 71 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L70-L71

Added lines #L70 - L71 were not covered by tests
if current_session:
current_session.record(event)
logger.info("Recorded streaming LLM event")
except Exception as e:
logger.error(f"Error in async_generator: {str(e)}")
raise

Check warning on line 77 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L73-L77

Added lines #L73 - L77 were not covered by tests

def generator(stream_response):
accumulated_content = ""
try:

Check warning on line 81 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L79-L81

Added lines #L79 - L81 were not covered by tests
for chunk in stream_response:
if hasattr(chunk, "choices") and chunk.choices:
content = chunk.choices[0].delta.content if hasattr(chunk.choices[0].delta, "content") else ""

Check warning on line 84 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L84

Added line #L84 was not covered by tests
if content:
accumulated_content += content
yield chunk

Check warning on line 87 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L86-L87

Added lines #L86 - L87 were not covered by tests
# Update event with final accumulated content
event.completion = accumulated_content
event.end_timestamp = time.time()

Check warning on line 90 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L89-L90

Added lines #L89 - L90 were not covered by tests
if current_session:
current_session.record(event)
logger.info("Recorded streaming LLM event")
except Exception as e:
logger.error(f"Error in generator: {str(e)}")
raise

Check warning on line 96 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L92-L96

Added lines #L92 - L96 were not covered by tests

if hasattr(response, "__aiter__"):
return async_generator(response) # Return async generator

Check warning on line 99 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L99

Added line #L99 was not covered by tests
else:
return generator(response) # Return sync generator

Check warning on line 101 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L101

Added line #L101 was not covered by tests

# Handle non-streaming response
if hasattr(response, "choices") and response.choices:
event.completion = response.choices[0].message.content
event.end_timestamp = time.time()

Check warning on line 106 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L105-L106

Added lines #L105 - L106 were not covered by tests
if current_session:
current_session.record(event)
logger.info("Recorded non-streaming LLM event")

Check warning on line 109 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L108-L109

Added lines #L108 - L109 were not covered by tests

return response

Check warning on line 111 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L111

Added line #L111 was not covered by tests

except Exception as e:
logger.error(f"Error handling response: {str(e)}")
raise

Check warning on line 115 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L113-L115

Added lines #L113 - L115 were not covered by tests

def override(self):
"""Override Fireworks API methods with instrumented versions."""
logger.info("Overriding Fireworks provider methods")

Check warning on line 119 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L119

Added line #L119 was not covered by tests
if not self._original_completion:
self._original_completion = self.client.chat.completions.create
self._override_fireworks_completion()

Check warning on line 122 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L121-L122

Added lines #L121 - L122 were not covered by tests

if not self._original_async_completion:
self._original_async_completion = self.client.chat.completions.acreate
self._override_fireworks_async_completion()

Check warning on line 126 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L125-L126

Added lines #L125 - L126 were not covered by tests

def _override_fireworks_completion(self):
"""Override synchronous completion method."""
original_create = self._original_completion
provider = self

Check warning on line 131 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L130-L131

Added lines #L130 - L131 were not covered by tests

def patched_function(*args, **kwargs):
try:
init_timestamp = time.time()
response = original_create(*args, **kwargs)

Check warning on line 136 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L133-L136

Added lines #L133 - L136 were not covered by tests
if kwargs.get("stream", False):
return provider.handle_response(response, kwargs, init_timestamp, provider._session)

Check warning on line 138 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L138

Added line #L138 was not covered by tests
else:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop.run_until_complete(provider.handle_response(response, kwargs, init_timestamp, provider._session))
except Exception as e:
logger.error(f"Error in Fireworks completion: {str(e)}")
raise

Check warning on line 145 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L140-L145

Added lines #L140 - L145 were not covered by tests

self.client.chat.completions.create = patched_function

Check warning on line 147 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L147

Added line #L147 was not covered by tests

def _override_fireworks_async_completion(self):
"""Override asynchronous completion method."""
original_acreate = self._original_async_completion
provider = self

Check warning on line 152 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L151-L152

Added lines #L151 - L152 were not covered by tests

async def patched_function(*args, **kwargs):
try:
init_timestamp = time.time()
response = await original_acreate(*args, **kwargs)

Check warning on line 157 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L154-L157

Added lines #L154 - L157 were not covered by tests

if kwargs.get("stream", False):
return await provider.handle_response(response, kwargs, init_timestamp, provider._session)

Check warning on line 160 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L160

Added line #L160 was not covered by tests
else:
return await provider.handle_response(response, kwargs, init_timestamp, provider._session)
except Exception as e:
logger.error(f"Error in Fireworks async completion: {str(e)}")
raise

Check warning on line 165 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L162-L165

Added lines #L162 - L165 were not covered by tests

self.client.chat.completions.acreate = patched_function

Check warning on line 167 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L167

Added line #L167 was not covered by tests

def undo_override(self):
"""Restore original Fireworks API methods."""
logger.info(f"Restoring original {self._provider_name} provider methods")

Check warning on line 171 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L171

Added line #L171 was not covered by tests
if self._original_completion:
self.client.chat.completions.create = self._original_completion

Check warning on line 173 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L173

Added line #L173 was not covered by tests
if self._original_async_completion:
self.client.chat.completions.acreate = self._original_async_completion

Check warning on line 175 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L175

Added line #L175 was not covered by tests
14 changes: 14 additions & 0 deletions agentops/llms/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .providers.anthropic import AnthropicProvider
from .providers.mistral import MistralProvider
from .providers.ai21 import AI21Provider
from .providers.fireworks import FireworksProvider

original_func = {}
original_create = None
Expand Down Expand Up @@ -48,6 +49,9 @@
"mistralai": {
"1.0.1": ("chat.complete", "chat.stream"),
},
"fireworks-ai": {
"0.1.0": ("chat.completions.create",),
},
"ai21": {
"2.0.0": (
"chat.completions.create",
Expand Down Expand Up @@ -155,6 +159,15 @@
else:
logger.warning(f"Only AI21>=2.0.0 supported. v{module_version} found.")

if api == "fireworks-ai":
module_version = version(api)

Check warning on line 163 in agentops/llms/tracker.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/tracker.py#L163

Added line #L163 was not covered by tests

if Version(module_version) >= parse("0.1.0"):
provider = FireworksProvider(self.client)
provider.override()

Check warning on line 167 in agentops/llms/tracker.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/tracker.py#L166-L167

Added lines #L166 - L167 were not covered by tests
else:
logger.warning(f"Only Fireworks>=0.1.0 supported. v{module_version} found.")

Check warning on line 169 in agentops/llms/tracker.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/tracker.py#L169

Added line #L169 was not covered by tests

if api == "llama_stack_client":
module_version = version(api)

Comment on lines 159 to 173

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Enhance Error Handling for Unsupported FireworksProvider Versions
The current implementation logs a warning when the FireworksProvider version is below 0.1.0, but it does not prevent the system from attempting to use an unsupported provider. This could lead to unexpected behavior or errors later in the execution. To address this, it's recommended to implement a fallback mechanism or raise an exception to ensure the system does not proceed with an unsupported version. This will improve the robustness and reliability of the code.

Actionable Steps:

  • Implement a fallback mechanism that either uses a default provider or skips the operation if the version is unsupported.
  • Alternatively, raise an exception to halt execution and notify the user of the unsupported version.
  • Ensure that any changes are accompanied by appropriate unit tests to verify the new behavior.

🔧 Suggested Code Diff:

else:
    logger.warning(f"Only Fireworks>=0.1.0 supported. v{module_version} found.")
+    raise RuntimeError(f"Unsupported Fireworks version: {module_version}. Please upgrade to >=0.1.0.")
📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
else:
logger.warning(f"Only AI21>=2.0.0 supported. v{module_version} found.")
if api == "fireworks-ai":
module_version = version(api)
if Version(module_version) >= parse("0.1.0"):
provider = FireworksProvider(self.client)
provider.override()
else:
logger.warning(f"Only Fireworks>=0.1.0 supported. v{module_version} found.")
if api == "llama_stack_client":
module_version = version(api)
else:
logger.warning(f"Only AI21>=2.0.0 supported. v{module_version} found.")
if api == "fireworks-ai":
module_version = version(api)
if Version(module_version) >= parse("0.1.0"):
provider = FireworksProvider(self.client)
provider.override()
else:
logger.warning(f"Only Fireworks>=0.1.0 supported. v{module_version} found.")
raise RuntimeError(f"Unsupported Fireworks version: {module_version}. Please upgrade to >=0.1.0.")
if api == "llama_stack_client":
module_version = version(api)
📜 Guidelines

• Use exceptions for error handling rather than return codes


Expand All @@ -174,3 +187,4 @@
MistralProvider(self.client).undo_override()
AI21Provider(self.client).undo_override()
LlamaStackClientProvider(self.client).undo_override()
FireworksProvider(self.client).undo_override()

Check warning on line 190 in agentops/llms/tracker.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/tracker.py#L190

Added line #L190 was not covered by tests
10 changes: 6 additions & 4 deletions agentops/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
end_state: str = "Indeterminate",
end_state_reason: Optional[str] = None,
video: Optional[str] = None,
) -> Union[Decimal, None]:
) -> Union[Dict[str, Any], None]:
with self._end_session_lock:
if not self.is_running:
return None
Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential Issue:

Ensure Compatibility with New Return Type
The change in the return type of the end_session method from Union[Decimal, None] to Union[Dict[str, Any], None] is significant and can lead to logical errors if not handled properly. This change requires a thorough review of all instances where this method is called to ensure that the new return type is compatible with existing logic.

Actionable Steps:

  • Audit Codebase: Identify all usages of the end_session method. This includes direct calls and any indirect dependencies.
  • Update Logic: Modify the logic that processes the return value to handle a dictionary instead of a decimal. This might involve changing how the return value is accessed and used.
  • Add Type Checks: Implement type checks or assertions where necessary to ensure that the return value is being used correctly.
  • Testing: Conduct thorough testing to ensure that the changes do not introduce new bugs or regressions.

By following these steps, you can mitigate the risk of runtime errors and ensure that the codebase remains robust and maintainable. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Review of Return Type Change in Function
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is significant and could potentially break existing code that relies on the previous return type. This change should be carefully reviewed and tested. Here are the steps to address this:

  • Review Usage: Identify all instances where this function is called and ensure that the calling code can handle a Dict[str, Any] return type instead of a Decimal.
  • Update Dependent Code: Modify any dependent code to correctly process the dictionary structure. This might involve updating how the return value is accessed and used.
  • Documentation: Update the function's documentation to reflect the new return type and provide examples of how to handle it.
  • Testing: Implement comprehensive tests to cover scenarios with the new return type. Ensure that edge cases are considered to prevent runtime errors.

This change is critical and should be handled with caution to avoid introducing bugs into the system. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major modification that can lead to runtime errors if not handled properly by the consumers of this function. This change can break existing functionality, especially if the consumers are expecting a Decimal and are not prepared to handle a Dict.

Actionable Steps:

  • Review Consumers: Thoroughly review all the consumers of this function to ensure they are updated to handle the new return type. This includes checking for any type checks or operations that assume a Decimal.
  • Update Documentation: If this change is intentional, update the function's documentation to reflect the new return type and its structure.
  • Migration Guide: If this function is part of a public API, consider providing a migration guide to assist users in adapting to the change.
  • Testing: Ensure that comprehensive tests are in place to verify that the function behaves as expected with the new return type.

This change should be communicated clearly to all stakeholders to prevent any unexpected issues in production environments. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Return Type Requires Thorough Review
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a critical modification that can have widespread implications on the codebase. This change could potentially break existing functionality if the dependent code is not updated to handle the new return type correctly.

Actionable Steps:

  • Review Usage: Conduct a comprehensive review of all instances where this function is called to ensure compatibility with the new return type.
  • Update Dependent Code: Modify any code that relies on the previous return type to handle a dictionary return type appropriately.
  • Testing: Implement thorough testing to ensure that the change does not introduce any bugs or unexpected behavior.
  • Documentation: Update the function's documentation to reflect the new return type and inform all relevant stakeholders about this change.

This change is high-impact and requires careful consideration and communication to avoid disruptions. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code
• Use meaningful variable and function names following specific naming conventions


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Change in Return Type from Decimal to Dict
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is significant and could lead to runtime errors if not handled properly. This change suggests that the function's output has been modified to return a dictionary instead of a decimal value.

Actionable Steps:

  • Review the Function Implementation: Ensure that the function's logic aligns with the new return type. Verify that the function indeed returns a dictionary in all scenarios where it previously returned a decimal.
  • Update Dependent Code: Identify all places where this function is called and update the handling of its return value to accommodate a dictionary instead of a decimal.
  • Communicate Changes: Document this change clearly and communicate it to all relevant stakeholders to prevent any integration issues.
  • Testing: Implement comprehensive tests to ensure that the new return type is handled correctly across the application.

This change is critical and should be approached with caution to avoid breaking existing functionality.


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major alteration that can have widespread implications across the codebase. This change could potentially break existing functionality that relies on the previous return type.

Actionable Steps:

  • Review Function Logic: Ensure that the function's logic aligns with the new return type. Verify that the function indeed returns a Dict[str, Any] in all scenarios where it previously returned a Decimal.
  • Update Dependent Code: Identify all parts of the codebase that interact with this function and update them to handle the new return type appropriately.
  • Documentation and Type Hints: Update any related documentation and type hints to reflect this change, ensuring that all developers are aware of the new expected output.
  • Testing: Implement comprehensive tests to cover the new return type scenarios, ensuring that the function behaves as expected in all cases.

This change is critical and should be handled with care to avoid introducing bugs. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major modification that can potentially break existing code that relies on the previous return type. This change should be carefully reviewed and tested to ensure compatibility with all consumers of this function.

Actionable Steps:

  • Review Usage: Thoroughly review all instances where this function is called to ensure they can handle a dictionary return type.
  • Update Documentation: Ensure that all relevant documentation and type hints are updated to reflect this change.
  • Migration Guide: If this function is part of a public API, consider providing a migration guide to assist users in adapting to the new return type.
  • Testing: Implement comprehensive tests to verify that the new return type is correctly handled across the codebase.

This change is critical and should be approached with caution to avoid introducing bugs or breaking existing functionality. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major modification that can lead to runtime errors if the calling code is not updated. This change could break existing functionality that expects a Decimal return type.

Actionable Steps:

  • Review Usage: Thoroughly review all instances where this function is called to ensure compatibility with the new return type.
  • Update Dependent Code: Modify any dependent code to handle a Dict[str, Any] return type instead of Decimal.
  • Migration Guide: Consider providing a migration guide or deprecation warning if this change is part of a larger refactor. This will help users transition smoothly.
  • Testing: Implement comprehensive tests to ensure that the new return type does not introduce bugs or unexpected behavior.

This change is critical and should be handled with care to avoid breaking existing systems. 🛠️

📜 Guidelines

• Encourage type annotations for clarity and error reduction


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Return Type Change Detected
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major modification that can have widespread implications on the codebase. This alteration could lead to unexpected behavior in any code that relies on the previous return type, potentially causing runtime errors or logical bugs if not handled properly.

Actionable Steps:

  • Review the Function Implementation: Ensure that the function's logic aligns with the new return type. Verify that the function indeed returns a Dict[str, Any] in all scenarios where it previously returned a Decimal.
  • Update Dependent Code: Identify all instances where this function is called and update them to handle a dictionary return type. This may involve modifying how the return value is processed or stored.
  • Backward Compatibility: Consider if backward compatibility is necessary. If so, provide a transitional solution or overload the function to support both return types temporarily.
  • Testing: Implement comprehensive tests to cover the new return type. Ensure that all edge cases are considered and that the function behaves as expected in all scenarios.

By following these steps, you can mitigate the risks associated with this change and ensure that the codebase remains stable and functional. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Return Type
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major modification that can impact the functionality of the code. This change requires a thorough review of all parts of the codebase that interact with this function to ensure they handle the new return type correctly.

Actionable Steps:

  • Review Calling Code: Examine all instances where this function is called to ensure they can handle a dictionary return type instead of a Decimal.
  • Update Logic: Modify any logic that processes the return value to accommodate the new dictionary structure.
  • Unit Tests: Update existing unit tests to reflect the new return type and add new tests if necessary to cover edge cases.
  • Documentation: Update any relevant documentation to reflect the change in the return type.

This change is critical and should be handled with care to avoid introducing bugs into the system. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major alteration in the function's API. This can lead to runtime errors if the calling code expects a Decimal and now receives a Dict.

Actionable Steps:

  • Review Usage: Thoroughly review all instances where this function is called to ensure they handle the new return type correctly.
  • Update Documentation: Modify the function's documentation to reflect the new return type and provide guidance on how to handle the Dict return value.
  • Testing: Implement comprehensive tests to verify that the function behaves as expected with the new return type and that all dependent code is updated accordingly.

This change is critical and should be handled with care to avoid breaking existing functionality. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Method Return Type
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major modification that can have widespread implications on the codebase. This alteration requires a thorough review of all the places where this method is invoked to ensure compatibility with the new return type.

Actionable Steps:

  • Review Usage: Identify all instances where this method is called and verify that the logic handling the return value is updated to process a dictionary instead of a decimal.
  • Update Documentation: Ensure that the method's documentation is updated to reflect the new return type and its structure.
  • Communicate Changes: Inform all relevant stakeholders about this change, especially those who maintain code that interacts with this method.
  • Testing: Implement comprehensive tests to validate that the new return type is correctly handled across the application.

This change is critical and should be approached with caution to prevent any runtime errors or logical inconsistencies in the application.

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major modification that can have widespread implications on the codebase. This alteration requires a thorough review of all instances where this function is called to ensure compatibility with the new return type.

Actionable Steps:

  • Audit Usage: Identify all places in the code where this function is used and verify that they can handle a dictionary return type.
  • Update Dependent Code: Modify any dependent code that expects a Decimal to correctly process a Dict[str, Any].
  • Type Checks: Consider adding type checks or assertions within the function to ensure the return value is consistent with the new type.
  • Documentation: Update the function's documentation to reflect the new return type and provide examples of how to handle it.

This change is critical and should be handled with care to prevent runtime errors and ensure the stability of the application. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability


Comment on lines 284 to 290

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Significant Change in Function Return Type
The change in the return type from Union[Decimal, None] to Union[Dict[str, Any], None] is a major modification that can have widespread implications across the codebase. This alteration requires a thorough review of all instances where this function is called to ensure compatibility with the new return type.

Actionable Steps:

  • Review Usage: Identify all places in the code where this function is used and verify that they can handle a Dict[str, Any] return type instead of a Decimal.
  • Update Dependent Code: Modify any dependent code to correctly process the dictionary return type. This may involve changes in how the return value is accessed and used.
  • Testing: Implement tests to validate the new behavior of the function. Ensure that these tests cover edge cases and verify that the function behaves as expected with the new return type.
  • Backward Compatibility: Consider if maintaining backward compatibility is necessary. If so, provide a transitional solution or document the change clearly for users of the function.

This change is critical and should be handled with care to prevent runtime errors or logical issues in the application.

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Expand Down Expand Up @@ -324,8 +324,9 @@
finally:
del self._span_processor

# 5. Final session update
if not (analytics_stats := self.get_analytics()):
# 5. Final session update and get analytics
analytics_stats = self.get_analytics()
if not analytics_stats:
return None

analytics = (
Expand All @@ -341,6 +342,7 @@

except Exception as e:
logger.exception(f"Error during session end: {e}")
return None

Check warning on line 345 in agentops/session.py

View check run for this annotation

Codecov / codecov/patch

agentops/session.py#L345

Added line #L345 was not covered by tests
finally:
active_sessions.remove(self) # First thing, get rid of the session

Expand All @@ -350,7 +352,7 @@
"blue",
)
)
return self.token_cost
return analytics_stats

def add_tags(self, tags: List[str]) -> None:
"""
Comment on lines 352 to 358

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug Fix:

Ensure Consistency in Return Value of end_session Method
The change in the return value of the end_session method from self.token_cost to analytics_stats is significant and could lead to logical errors if not handled properly. Here are the steps to address this:

  • Verify Definition: Ensure that analytics_stats is correctly defined and initialized with all necessary session statistics. This will prevent runtime errors and ensure that the method returns meaningful data.
  • Update Dependent Code: Review all parts of the codebase that call end_session to ensure they are updated to handle the new return type and structure. This includes checking for any assumptions about the return value that might no longer hold true.
  • Testing: Add comprehensive tests to validate the new functionality. This should include unit tests to check the correctness of analytics_stats and integration tests to ensure that the change does not introduce regressions in the system.

By following these steps, you can mitigate the risk of introducing logical errors and ensure that the system remains robust and reliable. 🛠️

📜 Guidelines

• Use type annotations to improve code clarity and maintainability
• Write unit tests for your code


Expand Down
Loading
Loading