Skip to content

Commit

Permalink
rename record_function
Browse files Browse the repository at this point in the history
  • Loading branch information
bboynton97 committed Aug 5, 2024
1 parent 60607df commit f10b50e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 28 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,21 @@ Initialize the AgentOps client and automatically get analytics on every LLM call
import agentops

# Beginning of program's code (i.e. main.py, __init__.py)
agentops.init(<INSERT YOUR API KEY HERE>)
agentops.init( < INSERT
YOUR
API
KEY
HERE >)

...


# (optional: record specific functions)
@agentops.record_function('sample function being record')
@agentops.record_action('sample function being record')
def sample_function(...):
...


# End of program
agentops.end_session('Success')
# Woohoo You're done 🎉
Expand Down
2 changes: 1 addition & 1 deletion agentops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .client import Client
from .event import Event, ActionEvent, LLMEvent, ToolEvent, ErrorEvent
from .decorators import record_function, track_agent, record_tool
from .decorators import record_action, track_agent, record_tool, record_function
from .helpers import check_agentops_update
from .log_config import logger
from .session import Session
Expand Down
7 changes: 7 additions & 0 deletions agentops/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@


def record_function(event_name: str):
logger.warning(
"DEPRECATION WARNING: record_function has been replaced with record_action and will be removed in the next minor version. Also see: record_tool"
)
return record_action(event_name)


def record_action(event_name: str):
"""
Decorator to record an event before and after a function call.
Usage:
Expand Down
4 changes: 2 additions & 2 deletions docs/v1/usage/recording-events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ To make AgentOps easier to integrate, we also provide a function decorator to au
and records an event for your function.

```python python
from agentops import record_function
from agentops import record_action

@record_function('sample function being record')
@record_action('sample function being record')
def sample_function(...):
...
```
Expand Down
12 changes: 8 additions & 4 deletions examples/openai-gpt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"metadata": {
"collapsed": false
},
"id": "5d424a02e30ce7f4"
"id": "5d424a02e30ce7f4",
"execution_count": null
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -104,7 +105,8 @@
"metadata": {
"collapsed": false
},
"id": "2704d6d625efa77f"
"id": "2704d6d625efa77f",
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -125,7 +127,8 @@
"metadata": {
"collapsed": false
},
"id": "537abd77cd0e0d25"
"id": "537abd77cd0e0d25",
"execution_count": null
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -159,7 +162,8 @@
"metadata": {
"collapsed": false
},
"id": "544c8f1bdb8c6e4b"
"id": "544c8f1bdb8c6e4b",
"execution_count": null
},
{
"cell_type": "markdown",
Expand Down
6 changes: 3 additions & 3 deletions tests/openai_handlers/_test_llm_tracker_ge_1_async.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from openai import AsyncOpenAI
import asyncio
import agentops
from agentops import record_function
from agentops import record_action
from dotenv import load_dotenv

load_dotenv()

agentops.init()


@record_function("openai v1 async no streaming")
@record_action("openai v1 async no streaming")
async def call_openai_v1_async_no_streaming():
client = AsyncOpenAI()

Expand All @@ -25,7 +25,7 @@ async def call_openai_v1_async_no_streaming():
# raise ValueError("This is an intentional error for testing.")


@record_function("openai v1 async with streaming")
@record_action("openai v1 async with streaming")
async def call_openai_v1_async_streaming():
client = AsyncOpenAI() # Using the async client

Expand Down
6 changes: 3 additions & 3 deletions tests/openai_handlers/_test_llm_tracker_ge_1_sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from openai import OpenAI
import agentops
from agentops import record_function
from agentops import record_action
from packaging.version import parse
from importlib import import_module
import sys
Expand All @@ -19,7 +19,7 @@
print("openai version: ", module_version)


@record_function("openai v1 sync no streaming")
@record_action("openai v1 sync no streaming")
def call_openai_v1_sync_no_streaming():
client = OpenAI()
chat_completion = client.chat.completions.create(
Expand All @@ -34,7 +34,7 @@ def call_openai_v1_sync_no_streaming():
# raise ValueError("This is an intentional error for testing.")


@record_function("openai v1 sync with streaming")
@record_action("openai v1 sync with streaming")
def call_openai_v1_sync_streaming():
client = OpenAI()
chat_completion = client.chat.completions.create(
Expand Down
6 changes: 3 additions & 3 deletions tests/openai_handlers/_test_llm_tracker_lt_1_sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from openai import ChatCompletion
import agentops
from agentops import record_function
from agentops import record_action
from packaging.version import parse
from importlib import import_module
import sys
Expand All @@ -19,7 +19,7 @@
print("openai version: ", module_version)


@record_function("openai v0 sync no streaming")
@record_action("openai v0 sync no streaming")
def call_openai_v0_sync_no_streaming():
chat_completion = ChatCompletion.create(
model="gpt-3.5-turbo",
Expand All @@ -33,7 +33,7 @@ def call_openai_v0_sync_no_streaming():
# raise ValueError("This is an intentional error for testing.")


@record_function("openai v0 sync with streaming")
@record_action("openai v0 sync with streaming")
def call_openai_v0_sync_with_streaming():
chat_completion = ChatCompletion.create(
model="gpt-3.5-turbo",
Expand Down
20 changes: 10 additions & 10 deletions tests/test_record_function.py → tests/test_record_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests_mock
import time
import agentops
from agentops import record_function
from agentops import record_action
from datetime import datetime
from agentops.helpers import clear_singletons
import contextlib
Expand Down Expand Up @@ -46,10 +46,10 @@ def setup_method(self):
self.event_type = "test_event_type"
agentops.init(self.api_key, max_wait_time=5, auto_start_session=False)

def test_record_function_decorator(self, mock_req):
def test_record_action_decorator(self, mock_req):
agentops.start_session()

@record_function(event_name=self.event_type)
@record_action(event_name=self.event_type)
def add_two(x, y):
return x + y

Expand All @@ -67,11 +67,11 @@ def add_two(x, y):

agentops.end_session(end_state="Success")

def test_record_function_decorator_multiple(self, mock_req):
def test_record_action_decorator_multiple(self, mock_req):
agentops.start_session()

# Arrange
@record_function(event_name=self.event_type)
@record_action(event_name=self.event_type)
def add_three(x, y, z=3):
return x + y + z

Expand All @@ -92,10 +92,10 @@ def add_three(x, y, z=3):
agentops.end_session(end_state="Success")

@pytest.mark.asyncio
async def test_async_function_call(self, mock_req):
async def test_async_action_call(self, mock_req):
agentops.start_session()

@record_function(self.event_type)
@record_action(self.event_type)
async def async_add(x, y):
time.sleep(0.1)
return x + y
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_multiple_sessions_sync(self, mock_req):
assert session_2 is not None

# Arrange
@record_function(event_name=self.event_type)
@record_action(event_name=self.event_type)
def add_three(x, y, z=3):
return x + y + z

Expand Down Expand Up @@ -174,7 +174,7 @@ async def test_multiple_sessions_async(self, mock_req):
assert session_2 is not None

# Arrange
@record_function(self.event_type)
@record_action(self.event_type)
async def async_add(x, y):
time.sleep(0.1)
return x + y
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_require_session_if_multiple(self):
session_2 = agentops.start_session()

# Arrange
@record_function(self.event_type)
@record_action(self.event_type)
def add_two(x, y):
time.sleep(0.1)
return x + y
Expand Down

0 comments on commit f10b50e

Please sign in to comment.