diff --git a/agentops/session.py b/agentops/session.py index 0ffbc1d4..48909cc2 100644 --- a/agentops/session.py +++ b/agentops/session.py @@ -1,4 +1,5 @@ import copy +import functools import json import threading import time @@ -241,3 +242,11 @@ def create_agent(self, name, agent_id): ) return agent_id + + def patch(self, func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + kwargs["session"] = self + return func(*args, **kwargs) + + return wrapper diff --git a/tests/core_manual_tests/api_server/server.py b/tests/core_manual_tests/api_server/server.py index 36a5dcb9..28d4063e 100644 --- a/tests/core_manual_tests/api_server/server.py +++ b/tests/core_manual_tests/api_server/server.py @@ -22,7 +22,6 @@ def completion(): model="gpt-3.5-turbo", messages=messages, temperature=0.5, - session=session, # <-- add the agentops session to the create function ) session.record( diff --git a/tests/core_manual_tests/multi_session_llm.py b/tests/core_manual_tests/multi_session_llm.py index 837d3d9f..823f33e1 100644 --- a/tests/core_manual_tests/multi_session_llm.py +++ b/tests/core_manual_tests/multi_session_llm.py @@ -15,20 +15,18 @@ messages = [{"role": "user", "content": "Hello"}] -response = openai.chat.completions.create( +# option 1: use session.patch +response = session_1.patch(openai.chat.completions.create)( model="gpt-3.5-turbo", messages=messages, temperature=0.5, - session=session_1, # <-- add the agentops session_id to the create function ) session_1.record(ActionEvent(action_type="test event")) -response = openai.chat.completions.create( - model="gpt-3.5-turbo", - messages=messages, - temperature=0.5, - session=session_2, # <-- add the agentops session_id to the create function +# option 2: add session as a keyword argument +response2 = openai.chat.completions.create( + model="gpt-3.5-turbo", messages=messages, temperature=0.5, session=session_2 ) session_1.end_session(end_state="Success")