Skip to content

Commit

Permalink
report metrics for simulations
Browse files Browse the repository at this point in the history
  • Loading branch information
kierangilliam committed Oct 8, 2023
1 parent 031d3d9 commit f6d60c0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions agentverse/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def add_message_to_memory(self, messages: List[Message]) -> None:
"""Add a message to the memory"""
pass

def get_spend(self) -> int:
def get_spend(self) -> float:
return self.llm.get_spend()

def get_spend_formatted(self) -> int:
def get_spend_formatted(self) -> str:
two_trailing = f"${self.get_spend():.2f}"
if two_trailing == "$0.00":
return f"${self.get_spend():.6f}"
Expand Down
3 changes: 3 additions & 0 deletions agentverse/environments/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
from agentverse.logging import logger

from abc import abstractmethod
from typing import TYPE_CHECKING, Any, Dict, List
Expand Down Expand Up @@ -48,6 +49,8 @@ def reset(self) -> None:

def report_metrics(self) -> None:
"""Report useful metrics"""
total_spent = sum([agent.get_spend() for agent in self.agents])
logger.info(f"Total spent: ${total_spent}")
pass

def is_done(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions agentverse/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def run(self):
self.environment.reset()
while not self.environment.is_done():
asyncio.run(self.environment.step())
self.environment.report_metrics()

def reset(self):
self.environment.reset()
Expand Down

0 comments on commit f6d60c0

Please sign in to comment.