From 8290215b86ca8ce4ef43e4af3f57bbe81bdf10c9 Mon Sep 17 00:00:00 2001 From: Kate Yeh Date: Sun, 28 Apr 2024 12:24:17 -0700 Subject: [PATCH 1/5] minor change --- agentops/client.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/agentops/client.py b/agentops/client.py index d6a4c14a..6f72365b 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -33,16 +33,16 @@ class Client(metaclass=MetaClient): Args: - api_key (str, optional): API Key for AgentOps services. If none is provided, key will + api_key (str, optional): API Key for AgentOps services. If none is provided, key will be read from the AGENTOPS_API_KEY environment variable. - parent_key (str, optional): Organization key to give visibility of all user sessions the user's organization. If none is provided, key will + parent_key (str, optional): Organization key to give visibility of all user sessions the user's organization. If none is provided, key will be read from the AGENTOPS_PARENT_KEY environment variable. - endpoint (str, optional): The endpoint for the AgentOps service. If none is provided, key will + endpoint (str, optional): The endpoint for the AgentOps service. If none is provided, key will be read from the AGENTOPS_API_ENDPOINT environment variable. Defaults to 'https://api.agentops.ai'. - max_wait_time (int, optional): The maximum time to wait in milliseconds before flushing the queue. + max_wait_time (int, optional): The maximum time to wait in milliseconds before flushing the queue. Defaults to 30,000 (30 seconds) max_queue_size (int, optional): The maximum size of the event queue. Defaults to 100. - tags (List[str], optional): Tags for the sessions that can be used for grouping or + tags (List[str], optional): Tags for the sessions that can be used for grouping or sorting later (e.g. ["GPT-4"]). override (bool, optional): [Deprecated] Use `instrument_llm_calls` instead. Whether to instrument LLM calls and emit LLMEvents.. instrument_llm_calls (bool): Whether to instrument LLM calls and emit LLMEvents.. @@ -95,7 +95,7 @@ def __init__(self, def add_tags(self, tags: List[str]): """ - Append to session tags at runtime. + Append to session tags at runtime. Args: tags (List[str]): The list of tags to append. @@ -111,7 +111,7 @@ def add_tags(self, tags: List[str]): def set_tags(self, tags: List[str]): """ - Replace session tags at runtime. + Replace session tags at runtime. Args: tags (List[str]): The list of tags to set. @@ -268,7 +268,7 @@ def end_session(self, if token_cost == 'unknown': print('🖇 AgentOps: Could not determine cost of run.') else: - print('🖇 AgentOps: This run cost ${:.6f}'.format(float(token_cost))) + print('🖇 AgentOps: This run cost ${:.6f}'.format('0' if token_cost == 0 else '{:.6f}'.format(token_cost))) self._session = None self._worker = None @@ -305,7 +305,7 @@ def handle_exception(exc_type, exc_value, exc_traceback): Args: exc_type (Type[BaseException]): The type of the exception. exc_value (BaseException): The exception instance. - exc_traceback (TracebackType): A traceback object encapsulating the call stack at the + exc_traceback (TracebackType): A traceback object encapsulating the call stack at the point where the exception originally occurred. """ formatted_traceback = ''.join(traceback.format_exception(exc_type, exc_value, From 1fd5ac59158a221a92cacbea0361470d48926d2d Mon Sep 17 00:00:00 2001 From: Kate Yeh Date: Sun, 28 Apr 2024 12:31:19 -0700 Subject: [PATCH 2/5] two decimals for 0 --- agentops/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agentops/client.py b/agentops/client.py index 6f72365b..9af94c7c 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -268,7 +268,7 @@ def end_session(self, if token_cost == 'unknown': print('🖇 AgentOps: Could not determine cost of run.') else: - print('🖇 AgentOps: This run cost ${:.6f}'.format('0' if token_cost == 0 else '{:.6f}'.format(token_cost))) + print('🖇 AgentOps: This run cost ${}'.format('{:.2f}'.format(token_cost) if token_cost == 0 else '{:.6f}'.format(token_cost))) self._session = None self._worker = None From a8e37179aa457419877f34a1b5e30c349fa0a04d Mon Sep 17 00:00:00 2001 From: Kate Yeh Date: Sun, 28 Apr 2024 18:47:31 -0700 Subject: [PATCH 3/5] put in float --- agentops/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agentops/client.py b/agentops/client.py index 9af94c7c..55520487 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -268,7 +268,7 @@ def end_session(self, if token_cost == 'unknown': print('🖇 AgentOps: Could not determine cost of run.') else: - print('🖇 AgentOps: This run cost ${}'.format('{:.2f}'.format(token_cost) if token_cost == 0 else '{:.6f}'.format(token_cost))) + print('🖇 AgentOps: This run cost ${}'.format('{:.2f}'.format(token_cost) if token_cost == 0 else '{:.6f}'.format(float(token_cost)))) self._session = None self._worker = None From e39c408350280e3f26142998218d6c1b27b7d776 Mon Sep 17 00:00:00 2001 From: Kate Yeh Date: Mon, 29 Apr 2024 11:13:00 -0700 Subject: [PATCH 4/5] changed to decimal lib --- agentops/client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/agentops/client.py b/agentops/client.py index 55520487..37676f26 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -15,12 +15,14 @@ from typing import Optional, List import traceback from .log_config import logger, set_logging_level_info +from decimal import * import inspect import atexit import signal import sys import threading + from .meta_client import MetaClient from .config import Configuration, ConfigurationError from .llm_tracker import LlmTracker @@ -264,11 +266,13 @@ def end_session(self, self._session.video = video self._session.end_session(end_state, end_state_reason) - token_cost = self._worker.end_session(self._session) + getcontext().prec = 6 + token_cost = Decimal(self._worker.end_session(self._session)) if token_cost == 'unknown': print('🖇 AgentOps: Could not determine cost of run.') else: - print('🖇 AgentOps: This run cost ${}'.format('{:.2f}'.format(token_cost) if token_cost == 0 else '{:.6f}'.format(float(token_cost)))) + + print('🖇 AgentOps: This run cost ${}'.format('{:.2f}'.format(token_cost) if token_cost == 0 else '{:.6f}'.format(token_cost))) self._session = None self._worker = None From 599f07db15e3be3829b0202823daf77176edf8f8 Mon Sep 17 00:00:00 2001 From: Kate Yeh Date: Mon, 29 Apr 2024 21:58:37 -0700 Subject: [PATCH 5/5] tookout get context --- agentops/client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agentops/client.py b/agentops/client.py index 37676f26..2aa90e00 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -15,7 +15,7 @@ from typing import Optional, List import traceback from .log_config import logger, set_logging_level_info -from decimal import * +from decimal import Decimal import inspect import atexit import signal @@ -266,7 +266,6 @@ def end_session(self, self._session.video = video self._session.end_session(end_state, end_state_reason) - getcontext().prec = 6 token_cost = Decimal(self._worker.end_session(self._session)) if token_cost == 'unknown': print('🖇 AgentOps: Could not determine cost of run.')