Skip to content

Commit

Permalink
add patch function
Browse files Browse the repository at this point in the history
  • Loading branch information
bboynton97 committed Jul 3, 2024
1 parent 1b82054 commit 83b171c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 9 additions & 0 deletions agentops/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import functools
import json
import threading
import time
Expand Down Expand Up @@ -241,3 +242,11 @@ def create_agent(self, name, agent_id):
)

return agent_id

Check warning on line 244 in agentops/session.py

View check run for this annotation

Codecov / codecov/patch

agentops/session.py#L244

Added line #L244 was not covered by tests

def patch(self, func):
@functools.wraps(func)

Check warning on line 247 in agentops/session.py

View check run for this annotation

Codecov / codecov/patch

agentops/session.py#L247

Added line #L247 was not covered by tests
def wrapper(*args, **kwargs):
kwargs["session"] = self
return func(*args, **kwargs)

Check warning on line 250 in agentops/session.py

View check run for this annotation

Codecov / codecov/patch

agentops/session.py#L249-L250

Added lines #L249 - L250 were not covered by tests

return wrapper

Check warning on line 252 in agentops/session.py

View check run for this annotation

Codecov / codecov/patch

agentops/session.py#L252

Added line #L252 was not covered by tests
1 change: 0 additions & 1 deletion tests/core_manual_tests/api_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 5 additions & 7 deletions tests/core_manual_tests/multi_session_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 83b171c

Please sign in to comment.