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

Update langchain handler for v1 #109

Merged
merged 12 commits into from
Mar 21, 2024
2 changes: 1 addition & 1 deletion agentops/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# agentops/__init__.py

from .client import Client
from .event import ActionEvent, LLMEvent, ToolEvent, ErrorEvent
from .event import Event, ActionEvent, LLMEvent, ToolEvent, ErrorEvent
from .logger import AgentOpsLogger
from .enums import Models, LLMMessageFormat
from .decorators import record_function
10 changes: 5 additions & 5 deletions agentops/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class EventType(Enum):
TOOL = "tools"
ERROR = "errors"


class Result(Enum):
SUCCESS = "Success"
FAIL = "Fail"
INDETERMINATE = "Indeterminate"
# TODO: Not used
bboynton97 marked this conversation as resolved.
Show resolved Hide resolved
# class Result(Enum):
# SUCCESS = "Success"
# FAIL = "Fail"
# INDETERMINATE = "Indeterminate"


class Models(Enum):
Expand Down
2 changes: 1 addition & 1 deletion agentops/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
AgentOps events.

Data Class:
Event: Represents discrete events to be recorded.
Event: Repents discrete events to be recorded.
bboynton97 marked this conversation as resolved.
Show resolved Hide resolved
"""

from dataclasses import dataclass, field
Expand Down
42 changes: 42 additions & 0 deletions agentops/helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from pprint import pprint, pformat
from functools import wraps
import time
from datetime import datetime
import json
import inspect
import logging
from uuid import UUID
import os


def singleton(class_):
Expand Down Expand Up @@ -84,3 +87,42 @@ def check_call_stack_for_agent_id() -> str | None:
logging.debug('LLM call from agent named: ' + getattr(var, '_agent_ops_agent_name'))
return getattr(var, '_agent_ops_agent_id')
return None

# Function decorator that prints function name and its arguments to the console for debug purposes
# Example output:
# <AGENTOPS_DEBUG_OUTPUT>
# on_llm_start called with arguments:
# run_id: UUID('5fda42fe-809b-4179-bad2-321d1a6090c7')
# parent_run_id: UUID('63f1c4da-3e9f-4033-94d0-b3ebed06668f')
# tags: []
# metadata: {}
# invocation_params: {'_type': 'openai-chat',
# 'model': 'gpt-3.5-turbo',
# 'model_name': 'gpt-3.5-turbo',
# 'n': 1,
# 'stop': ['Observation:'],
# 'stream': False,
# 'temperature': 0.7}
# options: {'stop': ['Observation:']}
# name: None
# batch_size: 1
# </AGENTOPS_DEBUG_OUTPUT>

# regex to filter for just this:
# <AGENTOPS_DEBUG_OUTPUT>([\s\S]*?)<\/AGENTOPS_DEBUG_OUTPUT>\n


def debug_print_function_params(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
if os.getenv('DEBUG_MODE') == 'Y':
print("\n<AGENTOPS_DEBUG_OUTPUT>")
print(f"{func.__name__} called with arguments:")

for key, value in kwargs.items():
print(f"{key}: {pformat(value)}")

print("</AGENTOPS_DEBUG_OUTPUT>\n")

return func(self, *args, **kwargs)
return wrapper
Loading