(fix) show correct spend on ui

This commit is contained in:
Ishaan Jaff 2024-03-29 09:41:00 -07:00
parent 6233351b01
commit 7df2d7cb33
4 changed files with 6 additions and 18 deletions

View file

@ -4881,13 +4881,7 @@ async def global_spend():
if user_response is not None: if user_response is not None:
if isinstance(user_response, list) and len(user_response) > 0: if isinstance(user_response, list) and len(user_response) > 0:
total_proxy_budget = user_response[0].get("max_budget", 0.0) total_proxy_budget = user_response[0].get("max_budget", 0.0)
litellm_proxy_budget_spend = user_response[0].get("spend", None)
if (
litellm_proxy_budget_spend is not None
and litellm_proxy_budget_spend > 0.0
):
# if the user has spend on litellm-proxy-budget, use that to show $spend/max budget
total_spend = litellm_proxy_budget_spend
return {"spend": total_spend, "max_budget": total_proxy_budget} return {"spend": total_spend, "max_budget": total_proxy_budget}

View file

@ -276,17 +276,10 @@ const CreateKey: React.FC<CreateKeyProps> = ({
{apiKey != null ? ( {apiKey != null ? (
<div> <div>
<Text>API Key: {apiKey}</Text> <Text>API Key: {apiKey}</Text>
<Title className="mt-6">Budgets</Title>
<Text>Soft Limit Budget: ${softBudget}</Text>
<Button className="mt-3" onClick={sendSlackAlert}> <Button className="mt-3" onClick={sendSlackAlert}>
Test Slack Alert Test Key
</Button> </Button>
<Text className="mt-2">
(LiteLLM Docs -
<a href="https://docs.litellm.ai/docs/proxy/alerting" target="_blank" className="text-blue-500">
Set Up Slack Alerting)
</a>
</Text>
</div> </div>
) : ( ) : (
<Text>Key being created, this might take 30s</Text> <Text>Key being created, this might take 30s</Text>

View file

@ -231,7 +231,8 @@ export const getTotalSpendCall = async (
} }
const data = await response.json(); const data = await response.json();
//message.info("Received model data"); message.info("global spend", data);
console.log("global soend", data)
return data; return data;
// Handle success - you might want to update some state or UI based on the created key // Handle success - you might want to update some state or UI based on the created key
} catch (error) { } catch (error) {

View file

@ -55,7 +55,7 @@ const ViewUserSpend: React.FC<ViewUserSpendProps> = ({ userID, userSpendData, us
const displayMaxBudget = maxBudget !== null ? `$${maxBudget} limit` : "No limit"; const displayMaxBudget = maxBudget !== null ? `$${maxBudget} limit` : "No limit";
const roundedSpend = spend !== undefined ? spend.toFixed(4) : null; const roundedSpend = spend !== undefined ? spend.toFixed(5) : null;
return ( return (
<> <>