Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the cost info easier to read #2356

Merged
merged 9 commits into from
Apr 15, 2024
6 changes: 3 additions & 3 deletions autogen/agentchat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def consolidate_chat_info(chat_info, uniform_sender=None) -> None:
), "llm client must be set in either the recipient or sender when summary_method is reflection_with_llm."


def gather_usage_summary(agents: List[Agent]) -> Tuple[Dict[str, any], Dict[str, any]]:
def gather_usage_summary(agents: List[Agent]) -> Dict[Dict[str, any], Dict[str, any]]:
Hk669 marked this conversation as resolved.
Show resolved Hide resolved
r"""Gather usage summary from all agents.

Args:
agents: (list): List of agents.

Returns:
tuple: (total_usage_summary, actual_usage_summary)
dictionary: (total_usage_summary, actual_usage_summary)
Hk669 marked this conversation as resolved.
Show resolved Hide resolved

Example:

Expand Down Expand Up @@ -77,7 +77,7 @@ def aggregate_summary(usage_summary: Dict[str, Any], agent_summary: Dict[str, An
aggregate_summary(total_usage_summary, agent.client.total_usage_summary)
aggregate_summary(actual_usage_summary, agent.client.actual_usage_summary)

return total_usage_summary, actual_usage_summary
return {"total_usage_summary": total_usage_summary, "actual_usage_summary": actual_usage_summary}
Hk669 marked this conversation as resolved.
Show resolved Hide resolved


def parse_tags_from_content(tag: str, content: Union[str, List[Dict[str, Any]]]) -> List[Dict[str, Dict[str, str]]]:
Expand Down
2 changes: 1 addition & 1 deletion autogen/code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


def content_str(content: Union[str, List[Union[UserMessageTextContentPart, UserMessageImageContentPart]], None]) -> str:
"""Converts the `content` field of an OpenAI merssage into a string format.
"""Converts the `content` field of an OpenAI message into a string format.
sonichi marked this conversation as resolved.
Show resolved Hide resolved

This function processes content that may be a string, a list of mixed text and image URLs, or None,
and converts it into a string. Text is directly appended to the result string, while image URLs are
Expand Down
11 changes: 6 additions & 5 deletions test/agentchat/test_agent_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def test_gathering():
"gpt-4": {"cost": 0.3, "prompt_tokens": 100, "completion_tokens": 200, "total_tokens": 300},
}

total_usage, _ = gather_usage_summary([assistant1, assistant2, assistant3])
total_usage = gather_usage_summary([assistant1, assistant2, assistant3])

assert round(total_usage["total_cost"], 8) == 0.6
assert round(total_usage["gpt-35-turbo"]["cost"], 8) == 0.3
assert round(total_usage["gpt-4"]["cost"], 8) == 0.3
assert round(total_usage["total_usage_summary"]["total_cost"], 8) == 0.6
assert round(total_usage["total_usage_summary"]["gpt-35-turbo"]["cost"], 8) == 0.3
assert round(total_usage["total_usage_summary"]["gpt-4"]["cost"], 8) == 0.3

# test when agent doesn't have client
user_proxy = UserProxyAgent(
Expand All @@ -77,7 +77,8 @@ def test_gathering():
default_auto_reply="That's all. Thank you.",
)

total_usage, acutal_usage = gather_usage_summary([user_proxy])
total_usage = gather_usage_summary([user_proxy])
total_usage_summary = total_usage["total_usage_summary"]


@pytest.mark.skipif(skip, reason="openai not installed OR requested to skip")
Expand Down
Loading