Skip to content

Commit

Permalink
refactor(session): replace session_url with a property method
Browse files Browse the repository at this point in the history
  • Loading branch information
teocns committed Nov 26, 2024
1 parent 711df42 commit cfb3afa
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions agentops/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def __init__(
"errors": 0,
"apis": 0,
}
self.session_url: Optional[str] = None
# self.session_url: Optional[str] = None

# Start session first to get JWT
self.is_running = self._start_session()
Expand Down Expand Up @@ -530,14 +530,9 @@ def _start_session(self):
if jwt is None:
return False

session_url = res.body.get(
"session_url",
f"https://app.agentops.ai/drilldown?session_id={self.session_id}",
)

logger.info(
colored(
f"\x1b[34mSession Replay: {session_url}\x1b[0m",
f"\x1b[34mSession Replay: {self.session_url}\x1b[0m",
"blue",
)
)
Expand Down Expand Up @@ -656,11 +651,6 @@ def get_analytics(self) -> Optional[Dict[str, Any]]:
self.token_cost = self._get_token_cost(response)
formatted_cost = self._format_token_cost(self.token_cost)

self.session_url = response.body.get(
"session_url",
f"https://app.agentops.ai/drilldown?session_id={self.session_id}",
)

return {
"LLM calls": self.event_counts["llms"],
"Tool calls": self.event_counts["tools"],
Expand All @@ -670,5 +660,15 @@ def get_analytics(self) -> Optional[Dict[str, Any]]:
"Cost": formatted_cost,
}

@property
def session_url(self) -> str:
"""Returns the URL for this session in the AgentOps dashboard."""
assert self.session_id, "Session ID is required to generate a session URL"
return f"https://app.agentops.ai/drilldown?session_id={self.session_id}"

# @session_url.setter
# def session_url(self, url: str):
# pass


active_sessions: List[Session] = []

0 comments on commit cfb3afa

Please sign in to comment.