🪞 Frontend: Fixed the bug where the chart size was displayed incorrectly when there was no data.
Browse files🐛 Bug: Fix the bug where the model cannot be retrieved in weight polling after renaming the provider model.
main.py
CHANGED
@@ -1253,10 +1253,6 @@ from fastapi.security import APIKeyHeader
|
|
1253 |
from typing import Optional, List
|
1254 |
|
1255 |
from xue import HTML, Head, Body, Div, xue_initialize, Script, Ul, Li
|
1256 |
-
from xue.components.menubar import (
|
1257 |
-
Menubar, MenubarMenu, MenubarTrigger, MenubarContent,
|
1258 |
-
MenubarItem, MenubarSeparator
|
1259 |
-
)
|
1260 |
from xue.components import input, dropdown, sheet, form, button, checkbox, sidebar, chart
|
1261 |
from xue.components.model_config_row import model_config_row
|
1262 |
# import sys
|
@@ -1423,7 +1419,7 @@ async def root(x_api_key: str = Depends(get_api_key)):
|
|
1423 |
),
|
1424 |
Div(id="sheet-container"), # sheet加载位置
|
1425 |
id="main-content",
|
1426 |
-
class_="ml-[
|
1427 |
),
|
1428 |
class_="flex"
|
1429 |
),
|
@@ -1444,6 +1440,33 @@ async def toggle_sidebar(is_collapsed: bool = False):
|
|
1444 |
active_item="dashboard"
|
1445 |
).render()
|
1446 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1447 |
@frontend_router.get("/data", response_class=HTMLResponse, dependencies=[Depends(frontend_rate_limit_dependency)])
|
1448 |
async def data_page(x_api_key: str = Depends(get_api_key)):
|
1449 |
if not x_api_key:
|
@@ -1500,22 +1523,30 @@ async def data_page(x_api_key: str = Depends(get_api_key)):
|
|
1500 |
"legend": True,
|
1501 |
"tooltip": True
|
1502 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1503 |
|
1504 |
-
result =
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
1516 |
-
|
1517 |
-
)
|
1518 |
-
)
|
1519 |
).render()
|
1520 |
|
1521 |
return result
|
|
|
1253 |
from typing import Optional, List
|
1254 |
|
1255 |
from xue import HTML, Head, Body, Div, xue_initialize, Script, Ul, Li
|
|
|
|
|
|
|
|
|
1256 |
from xue.components import input, dropdown, sheet, form, button, checkbox, sidebar, chart
|
1257 |
from xue.components.model_config_row import model_config_row
|
1258 |
# import sys
|
|
|
1419 |
),
|
1420 |
Div(id="sheet-container"), # sheet加载位置
|
1421 |
id="main-content",
|
1422 |
+
class_="ml-[200px] p-6 transition-[margin] duration-200 ease-in-out"
|
1423 |
),
|
1424 |
class_="flex"
|
1425 |
),
|
|
|
1440 |
active_item="dashboard"
|
1441 |
).render()
|
1442 |
|
1443 |
+
@app.get("/sidebar/update/{active_item}", response_class=HTMLResponse)
|
1444 |
+
async def update_sidebar(active_item: str):
|
1445 |
+
return sidebar.Sidebar(
|
1446 |
+
"zap",
|
1447 |
+
"uni-api",
|
1448 |
+
sidebar_items,
|
1449 |
+
is_collapsed=False,
|
1450 |
+
active_item=active_item
|
1451 |
+
).render()
|
1452 |
+
|
1453 |
+
@frontend_router.get("/dashboard", response_class=HTMLResponse, dependencies=[Depends(frontend_rate_limit_dependency)])
|
1454 |
+
async def data_page(x_api_key: str = Depends(get_api_key)):
|
1455 |
+
if not x_api_key:
|
1456 |
+
return RedirectResponse(url="/login", status_code=303)
|
1457 |
+
|
1458 |
+
result = Div(
|
1459 |
+
Div(
|
1460 |
+
data_table(data_table_columns, app.state.config["providers"], "users-table"),
|
1461 |
+
class_="p-4"
|
1462 |
+
),
|
1463 |
+
Div(id="sheet-container"), # sheet加载位置
|
1464 |
+
id="main-content",
|
1465 |
+
class_="ml-[200px] p-6 transition-[margin] duration-200 ease-in-out"
|
1466 |
+
).render()
|
1467 |
+
|
1468 |
+
return result
|
1469 |
+
|
1470 |
@frontend_router.get("/data", response_class=HTMLResponse, dependencies=[Depends(frontend_rate_limit_dependency)])
|
1471 |
async def data_page(x_api_key: str = Depends(get_api_key)):
|
1472 |
if not x_api_key:
|
|
|
1523 |
"legend": True,
|
1524 |
"tooltip": True
|
1525 |
}
|
1526 |
+
chart_config = {
|
1527 |
+
"stacked": False,
|
1528 |
+
"horizontal": False,
|
1529 |
+
"colors": ["#2563eb", "#60a5fa"],
|
1530 |
+
"grid": True, # 隐藏网格
|
1531 |
+
"legend": True, # 显示图例
|
1532 |
+
"tooltip": True # 启用工具提示
|
1533 |
+
}
|
1534 |
+
print(chart_data)
|
1535 |
+
print(series)
|
1536 |
|
1537 |
+
result = Div(
|
1538 |
+
Div(
|
1539 |
+
"模型使用统计 (24小时)",
|
1540 |
+
class_="text-2xl font-bold mb-4"
|
1541 |
+
),
|
1542 |
+
Div(
|
1543 |
+
chart.bar_chart("basic-chart", chart_data, "month", series, chart_config),
|
1544 |
+
# chart.bar_chart("model-usage-chart", chart_data, "model", series, chart_config),
|
1545 |
+
class_="mb-8" # 设置图表高度
|
1546 |
+
),
|
1547 |
+
id="main-content",
|
1548 |
+
class_="container ml-[200px] mx-auto p-4"
|
1549 |
+
# class_="container ml-[200px] mx-auto p-4"
|
|
|
|
|
1550 |
).render()
|
1551 |
|
1552 |
return result
|
utils.py
CHANGED
@@ -109,9 +109,18 @@ def update_config(config_data, use_config_url=False):
|
|
109 |
for model in api_key.get('model'):
|
110 |
if isinstance(model, dict):
|
111 |
key, value = list(model.items())[0]
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
models.append(key)
|
116 |
if isinstance(model, str):
|
117 |
models.append(model)
|
|
|
109 |
for model in api_key.get('model'):
|
110 |
if isinstance(model, dict):
|
111 |
key, value = list(model.items())[0]
|
112 |
+
provider_name = key.split("/")[0]
|
113 |
+
model_name = key.split("/")[1]
|
114 |
+
|
115 |
+
for provider_item in config_data["providers"]:
|
116 |
+
if provider_item['provider'] != provider_name:
|
117 |
+
continue
|
118 |
+
model_dict = get_model_dict(provider_item)
|
119 |
+
if model_name in model_dict.keys():
|
120 |
+
weights_dict.update({provider_name + "/" + model_dict[model_name]: int(value)})
|
121 |
+
elif model_name == "*":
|
122 |
+
weights_dict.update({provider_name + "/" + model_dict[model_item]: int(value) for model_item in model_dict.keys()})
|
123 |
+
|
124 |
models.append(key)
|
125 |
if isinstance(model, str):
|
126 |
models.append(model)
|