Skip to content

Commit

Permalink
return 0 when there is no value for cost or tokens, version update
Browse files Browse the repository at this point in the history
  • Loading branch information
victordibia committed Jun 19, 2024
1 parent f701245 commit d00467c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion samples/apps/autogen-studio/autogenstudio/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = "0.1.1"
VERSION = "0.1.2"
__version__ = VERSION
APP_NAME = "autogenstudio"
8 changes: 4 additions & 4 deletions samples/apps/autogen-studio/autogenstudio/workflowmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ def _get_agent_usage(self, agent: autogen.Agent):
agent_usage = agent.client.total_usage_summary if agent.client else default_usage
agent_usage = {
"agent": agent.name,
"total_cost": find_key_value(agent_usage, "total_cost"),
"total_tokens": find_key_value(agent_usage, "total_tokens"),
"total_cost": find_key_value(agent_usage, "total_cost") or 0,
"total_tokens": find_key_value(agent_usage, "total_tokens") or 0,
}
final_usage.append(agent_usage)

Expand All @@ -362,8 +362,8 @@ def _get_agent_usage(self, agent: autogen.Agent):
agent_usage = agent.client.total_usage_summary if agent.client else default_usage or default_usage
agent_usage = {
"agent": agent.name,
"total_cost": find_key_value(agent_usage, "total_cost"),
"total_tokens": find_key_value(agent_usage, "total_tokens"),
"total_cost": find_key_value(agent_usage, "total_cost") or 0,
"total_tokens": find_key_value(agent_usage, "total_tokens") or 0,
}
final_usage.append(agent_usage)
return final_usage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { message } from "antd";
import { Tooltip, message } from "antd";
import * as React from "react";
import { IStatus, IChatMessage } from "../../../types";
import { fetchJSON, getServerUrl } from "../../../utils";
import { appContext } from "../../../../hooks/provider";
import { InformationCircleIcon } from "@heroicons/react/24/outline";

const BarChartViewer = React.lazy(() => import("./charts/bar"));

Expand Down Expand Up @@ -72,18 +73,18 @@ const ProfilerView = ({
{usage.agent}
</div>
<div className="bg-tertiary p-3 rounded-b inline-flex gap-2 w-full">
{usage.total_tokens != 0 && (
{usage.total_tokens && usage.total_tokens != 0 && (
<div className="flex flex-col text-center w-full">
<div className="w-full px-2 text-2xl ">
{usage.total_tokens}
</div>
<div className="w-full text-xs">tokens</div>
</div>
)}
{usage.total_cost != 0 && (
{usage.total_cost && usage.total_cost != 0 && (
<div className="flex flex-col text-center w-full">
<div className="w-full px-2 text-2xl ">
{usage.total_cost.toFixed(3)}
{usage.total_cost?.toFixed(3)}
</div>
<div className="w-full text-xs">USD</div>
</div>
Expand All @@ -94,7 +95,7 @@ const ProfilerView = ({
</div>
));
return (
<div className="inline-flex gap-3 flex-wrap">{usage && usageRows}</div>
<div className="inline-flex gap-3 flex-wrap">{usage && usageRows}</div>
);
};

Expand All @@ -105,7 +106,16 @@ const ProfilerView = ({
{profile && <BarChartViewer data={profile} />}

<div className="mt-4">
<div className="mt-4 hidden mb-2 font-semibold txt">LLM Costs</div>
<div className="mt-4 mb-4 txt">
LLM Costs
<Tooltip
title={
"LLM tokens below based on data returned by the model. Support for exact costs may vary."
}
>
<InformationCircleIcon className="ml-1 text-gray-400 inline-block w-4 h-4" />
</Tooltip>
</div>
{profile && profile.usage && <UsageViewer usage={profile.usage} />}
</div>
</div>
Expand Down

0 comments on commit d00467c

Please sign in to comment.