From 3c438888f3b71853e06bd1821c377035bbf15956 Mon Sep 17 00:00:00 2001 From: Siddharth Prajosh Date: Sun, 23 Jun 2024 13:58:29 +0530 Subject: [PATCH 1/4] Return token cost on session_end --- agentops/__init__.py | 2 +- agentops/client.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/agentops/__init__.py b/agentops/__init__.py index e8600cce..7a31698d 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -118,7 +118,7 @@ def end_session( video (str, optional): URL to a video recording of the session is_auto_end (bool, optional): is this an automatic use of end_session and should be skipped with bypass_auto_end_session """ - Client().end_session( + return Client().end_session( end_state=end_state, end_state_reason=end_state_reason, video=video, diff --git a/agentops/client.py b/agentops/client.py index 7108e393..14d38448 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -1,8 +1,8 @@ """ - AgentOps client module that provides a client class with public interfaces and configuration. +AgentOps client module that provides a client class with public interfaces and configuration. - Classes: - Client: Provides methods to interact with the AgentOps service. +Classes: + Client: Provides methods to interact with the AgentOps service. """ import os @@ -80,7 +80,6 @@ def __init__( inherited_session_id: Optional[str] = None, skip_auto_end_session: Optional[bool] = False, ): - if override is not None: logger.warning( "The 'override' parameter is deprecated. Use 'instrument_llm_calls' instead.", @@ -439,6 +438,7 @@ def end_session( self._session = None self._worker = None + return token_cost_d def create_agent(self, name: str, agent_id: Optional[str] = None): if agent_id is None: From 2b745b6ab6bc16c4cc37a6c5745489f883946f89 Mon Sep 17 00:00:00 2001 From: Siddharth Prajosh Date: Wed, 26 Jun 2024 23:42:09 +0530 Subject: [PATCH 2/4] Add type hint for return --- agentops/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/agentops/client.py b/agentops/client.py index 14d38448..157b60bc 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -388,7 +388,7 @@ def end_session( end_state_reason: Optional[str] = None, video: Optional[str] = None, is_auto_end: Optional[bool] = None, - ): + ) -> Decimal: """ End the current session with the AgentOps service. @@ -419,6 +419,7 @@ def end_session( if token_cost is None or token_cost == "unknown": logger.info("Could not determine cost of run.") + token_cost_d = Decimal(0) else: token_cost_d = Decimal(token_cost) logger.info( From 8e43e887451c3688f613cee3fbc0d66aade3cdf2 Mon Sep 17 00:00:00 2001 From: Siddharth Prajosh Date: Thu, 27 Jun 2024 00:20:33 +0530 Subject: [PATCH 3/4] Add docstring --- agentops/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/agentops/client.py b/agentops/client.py index 157b60bc..34db1359 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -397,6 +397,9 @@ def end_session( end_state_reason (str, optional): The reason for ending the session. video (str, optional): The video screen recording of the session 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. """ if is_auto_end and self.config.skip_auto_end_session: From 5785da3554630af841388c3568742ff68b74a4b7 Mon Sep 17 00:00:00 2001 From: Siddharth Prajosh Date: Thu, 27 Jun 2024 00:32:59 +0530 Subject: [PATCH 4/4] Fix black formatting error --- examples/openai-gpt.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/openai-gpt.ipynb b/examples/openai-gpt.ipynb index ddc511c1..0fe4f241 100644 --- a/examples/openai-gpt.ipynb +++ b/examples/openai-gpt.ipynb @@ -127,7 +127,7 @@ "for chunk in res:\n", " if chunk.choices[0].delta.content is not None:\n", " full_response += chunk.choices[0].delta.content\n", - " \n", + "\n", "print(full_response.strip())" ] },