mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
fix(tag_management_endpoints.py): return dynamic tags from db on /tag/list
This commit is contained in:
parent
184bbe8742
commit
c5936799b0
3 changed files with 51 additions and 4 deletions
|
@ -25,6 +25,7 @@ from litellm.proxy.management_endpoints.common_daily_activity import (
|
||||||
get_daily_activity,
|
get_daily_activity,
|
||||||
)
|
)
|
||||||
from litellm.types.tag_management import (
|
from litellm.types.tag_management import (
|
||||||
|
LiteLLM_DailyTagSpendTable,
|
||||||
TagConfig,
|
TagConfig,
|
||||||
TagDeleteRequest,
|
TagDeleteRequest,
|
||||||
TagInfoRequest,
|
TagInfoRequest,
|
||||||
|
@ -315,9 +316,33 @@ async def list_tags(
|
||||||
raise HTTPException(status_code=500, detail="Database not connected")
|
raise HTTPException(status_code=500, detail="Database not connected")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
## QUERY STORED TAGS ##
|
||||||
tags_config = await _get_tags_config(prisma_client)
|
tags_config = await _get_tags_config(prisma_client)
|
||||||
list_of_tags = list(tags_config.values())
|
list_of_tags = list(tags_config.values())
|
||||||
return list_of_tags
|
|
||||||
|
## QUERY DYNAMIC TAGS ##
|
||||||
|
dynamic_tags = await prisma_client.db.litellm_dailytagspend.find_many(
|
||||||
|
distinct=["tag"],
|
||||||
|
)
|
||||||
|
|
||||||
|
dynamic_tags_list = [
|
||||||
|
LiteLLM_DailyTagSpendTable(**dynamic_tag.model_dump())
|
||||||
|
for dynamic_tag in dynamic_tags
|
||||||
|
]
|
||||||
|
|
||||||
|
dynamic_tag_config = [
|
||||||
|
TagConfig(
|
||||||
|
name=tag.tag,
|
||||||
|
description="This is just a spend tag that was passed dynamically in a request. It does not control any LLM models.",
|
||||||
|
models=None,
|
||||||
|
created_at=tag.created_at.isoformat(),
|
||||||
|
updated_at=tag.updated_at.isoformat(),
|
||||||
|
)
|
||||||
|
for tag in dynamic_tags_list
|
||||||
|
if tag.tag not in tags_config
|
||||||
|
]
|
||||||
|
|
||||||
|
return list_of_tags + dynamic_tag_config
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from datetime import datetime
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
@ -30,3 +31,23 @@ class TagDeleteRequest(BaseModel):
|
||||||
|
|
||||||
class TagInfoRequest(BaseModel):
|
class TagInfoRequest(BaseModel):
|
||||||
names: List[str]
|
names: List[str]
|
||||||
|
|
||||||
|
|
||||||
|
class LiteLLM_DailyTagSpendTable(BaseModel):
|
||||||
|
id: str
|
||||||
|
tag: str
|
||||||
|
date: str
|
||||||
|
api_key: str
|
||||||
|
model: str
|
||||||
|
model_group: Optional[str]
|
||||||
|
custom_llm_provider: Optional[str]
|
||||||
|
prompt_tokens: int
|
||||||
|
completion_tokens: int
|
||||||
|
cache_read_input_tokens: int
|
||||||
|
cache_creation_input_tokens: int
|
||||||
|
spend: float
|
||||||
|
api_requests: int
|
||||||
|
successful_requests: int
|
||||||
|
failed_requests: int
|
||||||
|
created_at: datetime
|
||||||
|
updated_at: datetime
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
import { AreaChart } from "@tremor/react";
|
import { AreaChart } from "@tremor/react";
|
||||||
|
|
||||||
import { userDailyActivityCall, tagListCall } from "./networking";
|
import { userDailyActivityCall, tagListCall } from "./networking";
|
||||||
|
import { Tag } from "./tag_management/types";
|
||||||
import ViewUserSpend from "./view_user_spend";
|
import ViewUserSpend from "./view_user_spend";
|
||||||
import TopKeyView from "./top_key_view";
|
import TopKeyView from "./top_key_view";
|
||||||
import { ActivityMetrics, processActivityData } from './activity_metrics';
|
import { ActivityMetrics, processActivityData } from './activity_metrics';
|
||||||
|
@ -58,9 +59,9 @@ const NewUsagePage: React.FC<NewUsagePageProps> = ({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const tags = await tagListCall(accessToken);
|
const tags = await tagListCall(accessToken);
|
||||||
setAllTags(Object.keys(tags).map((tag) => ({
|
setAllTags(Object.values(tags).map((tag: Tag) => ({
|
||||||
label: tag,
|
label: tag.name,
|
||||||
value: tag
|
value: tag.name
|
||||||
})));
|
})));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue