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 15 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
182 changes: 182 additions & 0 deletions agentops/llms/providers/fireworks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
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 63 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L61-L63

Added lines #L61 - L63 were not covered by tests
async for chunk in stream_response:
if hasattr(chunk, "choices") and chunk.choices:
content = (

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L66

Added line #L66 was not covered by tests
chunk.choices[0].delta.content if hasattr(chunk.choices[0].delta, "content") else ""
)
if content:
accumulated_content += content
yield chunk

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
# Update event with final accumulated content
event.completion = accumulated_content
event.end_timestamp = time.time()

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L73 - L74 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 80 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L76-L80

Added lines #L76 - L80 were not covered by tests

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

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#L82-L84

Added lines #L82 - L84 were not covered by tests
for chunk in stream_response:
if hasattr(chunk, "choices") and chunk.choices:
content = (

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#L87

Added line #L87 was not covered by tests
chunk.choices[0].delta.content if hasattr(chunk.choices[0].delta, "content") else ""
)
if content:
accumulated_content += content
yield chunk

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L94-L95

Added lines #L94 - L95 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 101 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L97-L101

Added lines #L97 - L101 were not covered by tests
Comment on lines +82 to +101

Choose a reason for hiding this comment

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

🤖 Bug Fix:

Ensure Safe Access to 'event' and 'current_session' in Generator
The current implementation of the generator function does not check if event and current_session are defined before accessing their properties or methods. This can lead to runtime errors if these objects are not properly initialized. To prevent such issues, it's crucial to add checks to ensure these objects are not None before using them. Additionally, consider implementing error handling or default values to maintain functionality even if these objects are not initialized.

Actionable Steps:

  • Add checks to verify that event and current_session are not None before accessing their properties or methods.
  • Implement error handling to manage cases where these objects might be uninitialized, possibly by logging a warning or using default values.

🔧 Suggested Code Diff:

                def generator(stream_response):
                    accumulated_content = ""
                    try:
                        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 ""
                                )
                                if content:
                                    accumulated_content += content
                                    yield chunk
                        # Update event with final accumulated content
+                       if event is not None:
                            event.completion = accumulated_content
                            event.end_timestamp = time.time()
+                       else:
+                           logger.warning("Event object is None, cannot update completion.")
                        if current_session is not None:
                            current_session.record(event)
                            logger.info("Recorded streaming LLM event")
+                       else:
+                           logger.warning("Current session is None, cannot record event.")
                    except Exception as e:
                        logger.error(f"Error in generator: {str(e)}")
                        raise
📝 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
def generator(stream_response):
accumulated_content = ""
try:
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 ""
)
if content:
accumulated_content += content
yield chunk
# Update event with final accumulated content
event.completion = accumulated_content
event.end_timestamp = time.time()
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
def generator(stream_response):
accumulated_content = ""
try:
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 ""
)
if content:
accumulated_content += content
yield chunk
# Update event with final accumulated content
if event is not None:
event.completion = accumulated_content
event.end_timestamp = time.time()
else:
logger.warning("Event object is None, cannot update completion.")
if current_session is not None:
current_session.record(event)
logger.info("Recorded streaming LLM event")
else:
logger.warning("Current session is None, cannot record event.")
except Exception as e:
logger.error(f"Error in generator: {str(e)}")
raise
📜 Guidelines

• Use pylint to catch bugs and style issues
• Use f-strings or format methods for string formatting



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

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L104

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

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#L106

Added line #L106 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 111 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L110-L111

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L113 - L114 were not covered by tests

return response

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L116

Added line #L116 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L118-L120

Added lines #L118 - L120 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 124 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L124

Added line #L124 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 127 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L126 - L127 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 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 _override_fireworks_completion(self):
"""Override synchronous completion method."""
original_create = self._original_completion
provider = self

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#L135-L136

Added lines #L135 - L136 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L138-L141

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

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L143

Added line #L143 was not covered by tests
else:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop.run_until_complete(

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#L145-L147

Added lines #L145 - L147 were not covered by tests
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 152 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L150 - L152 were not covered by tests

self.client.chat.completions.create = patched_function

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L154

Added line #L154 was not covered by tests

Choose a reason for hiding this comment

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

🤖 Bug Fix:

Avoid Creating New Event Loops in Asynchronous Code
The current implementation creates a new event loop for handling non-streaming responses, which can lead to runtime errors or unexpected behavior in environments where an event loop is already running. This is a critical issue, especially in asynchronous applications, as it can break functionality.

Actionable Suggestions:

  • Use asyncio.get_event_loop() to check if an existing event loop is running and use it.
  • Only create a new event loop if none is running. This approach ensures compatibility with environments that already have an event loop in place.

By following these steps, you can prevent potential issues related to event loop management and ensure the code functions correctly in various environments.

🔧 Suggested Code Diff:

        def patched_function(*args, **kwargs):
            try:
                init_timestamp = time.time()
                response = original_create(*args, **kwargs)
                if kwargs.get("stream", False):
                    return provider.handle_response(response, kwargs, init_timestamp, provider._session)
                else:
-                    loop = asyncio.new_event_loop()
-                    asyncio.set_event_loop(loop)
+                    loop = asyncio.get_event_loop()
+                    if loop.is_running():
+                        return loop.run_until_complete(
+                            provider.handle_response(response, kwargs, init_timestamp, provider._session)
+                        )
+                    else:
+                        new_loop = asyncio.new_event_loop()
+                        asyncio.set_event_loop(new_loop)
+                        return new_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
📝 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
def _override_fireworks_completion(self):
"""Override synchronous completion method."""
original_create = self._original_completion
provider = self
def patched_function(*args, **kwargs):
try:
init_timestamp = time.time()
response = original_create(*args, **kwargs)
if kwargs.get("stream", False):
return provider.handle_response(response, kwargs, init_timestamp, provider._session)
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
self.client.chat.completions.create = patched_function
def _override_fireworks_completion(self):
"""Override synchronous completion method."""
original_create = self._original_completion
provider = self
def patched_function(*args, **kwargs):
try:
init_timestamp = time.time()
response = original_create(*args, **kwargs)
if kwargs.get("stream", False):
return provider.handle_response(response, kwargs, init_timestamp, provider._session)
else:
loop = asyncio.get_event_loop()
if loop.is_running():
return loop.run_until_complete(
provider.handle_response(response, kwargs, init_timestamp, provider._session)
)
else:
new_loop = asyncio.new_event_loop()
asyncio.set_event_loop(new_loop)
return new_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
self.client.chat.completions.create = patched_function
📜 Guidelines

• Use exceptions for error handling, but avoid assert statements for critical logic


Choose a reason for hiding this comment

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

🤖 Bug Fix:

Avoid Creating New Event Loops in Asynchronous Code
The current implementation creates a new event loop for each call in the _override_fireworks_completion method. This approach can lead to resource leaks and unexpected behavior, especially if the application already has an existing event loop. Instead, you should use the existing event loop by calling asyncio.get_event_loop(). This change will ensure that the event loop is managed correctly and efficiently, preventing potential resource exhaustion and maintaining the application's stability.

🔧 Suggested Code Diff:

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

        def patched_function(*args, **kwargs):
            try:
                init_timestamp = time.time()
                response = original_create(*args, **kwargs)
                if kwargs.get("stream", False):
                    return provider.handle_response(response, kwargs, init_timestamp, provider._session)
                else:
-                    loop = asyncio.new_event_loop()
-                    asyncio.set_event_loop(loop)
+                    loop = asyncio.get_event_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

        self.client.chat.completions.create = patched_function
📝 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
def _override_fireworks_completion(self):
"""Override synchronous completion method."""
original_create = self._original_completion
provider = self
def patched_function(*args, **kwargs):
try:
init_timestamp = time.time()
response = original_create(*args, **kwargs)
if kwargs.get("stream", False):
return provider.handle_response(response, kwargs, init_timestamp, provider._session)
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
self.client.chat.completions.create = patched_function
def _override_fireworks_completion(self):
"""Override synchronous completion method."""
original_create = self._original_completion
provider = self
def patched_function(*args, **kwargs):
try:
init_timestamp = time.time()
response = original_create(*args, **kwargs)
if kwargs.get("stream", False):
return provider.handle_response(response, kwargs, init_timestamp, provider._session)
else:
loop = asyncio.get_event_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
self.client.chat.completions.create = patched_function
📜 Guidelines

• Use exception handling for error management, but avoid overuse of try/except


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

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L158-L159

Added lines #L158 - L159 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 164 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L161-L164

Added lines #L161 - L164 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 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
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 172 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L169-L172

Added lines #L169 - L172 were not covered by tests

self.client.chat.completions.acreate = patched_function

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L174

Added line #L174 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 178 in agentops/llms/providers/fireworks.py

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L178

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

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L180

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

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

View check run for this annotation

Codecov / codecov/patch

agentops/llms/providers/fireworks.py#L182

Added line #L182 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