Files
new-api/controller/model_meta.go

279 lines
6.5 KiB
Go
Raw Normal View History

🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
package controller
import (
2025-08-10 12:11:31 +08:00
"encoding/json"
"strconv"
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
"strings"
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
2025-08-10 12:11:31 +08:00
"one-api/common"
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
"one-api/constant"
2025-08-10 12:11:31 +08:00
"one-api/model"
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
2025-08-10 12:11:31 +08:00
"github.com/gin-gonic/gin"
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
)
// GetAllModelsMeta 获取模型列表(分页)
func GetAllModelsMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
pageInfo := common.GetPageQuery(c)
modelsMeta, err := model.GetAllModels(pageInfo.GetStartIdx(), pageInfo.GetPageSize())
if err != nil {
common.ApiError(c, err)
return
}
// 填充附加字段
for _, m := range modelsMeta {
fillModelExtra(m)
}
var total int64
model.DB.Model(&model.Model{}).Count(&total)
// 统计供应商计数(全部数据,不受分页影响)
vendorCounts, _ := model.GetVendorModelCounts()
pageInfo.SetTotal(int(total))
pageInfo.SetItems(modelsMeta)
common.ApiSuccess(c, gin.H{
"items": modelsMeta,
"total": total,
"page": pageInfo.GetPage(),
"page_size": pageInfo.GetPageSize(),
"vendor_counts": vendorCounts,
})
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// SearchModelsMeta 搜索模型列表
func SearchModelsMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
keyword := c.Query("keyword")
vendor := c.Query("vendor")
pageInfo := common.GetPageQuery(c)
modelsMeta, total, err := model.SearchModels(keyword, vendor, pageInfo.GetStartIdx(), pageInfo.GetPageSize())
if err != nil {
common.ApiError(c, err)
return
}
for _, m := range modelsMeta {
fillModelExtra(m)
}
pageInfo.SetTotal(int(total))
pageInfo.SetItems(modelsMeta)
common.ApiSuccess(c, pageInfo)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// GetModelMeta 根据 ID 获取单条模型信息
func GetModelMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
common.ApiError(c, err)
return
}
var m model.Model
if err := model.DB.First(&m, id).Error; err != nil {
common.ApiError(c, err)
return
}
fillModelExtra(&m)
common.ApiSuccess(c, &m)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// CreateModelMeta 新建模型
func CreateModelMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
var m model.Model
if err := c.ShouldBindJSON(&m); err != nil {
common.ApiError(c, err)
return
}
if m.ModelName == "" {
common.ApiErrorMsg(c, "模型名称不能为空")
return
}
// 名称冲突检查
if dup, err := model.IsModelNameDuplicated(0, m.ModelName); err != nil {
common.ApiError(c, err)
return
} else if dup {
common.ApiErrorMsg(c, "模型名称已存在")
return
}
if err := m.Insert(); err != nil {
common.ApiError(c, err)
return
}
model.RefreshPricing()
common.ApiSuccess(c, &m)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// UpdateModelMeta 更新模型
func UpdateModelMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
statusOnly := c.Query("status_only") == "true"
var m model.Model
if err := c.ShouldBindJSON(&m); err != nil {
common.ApiError(c, err)
return
}
if m.Id == 0 {
common.ApiErrorMsg(c, "缺少模型 ID")
return
}
if statusOnly {
// 只更新状态,防止误清空其他字段
if err := model.DB.Model(&model.Model{}).Where("id = ?", m.Id).Update("status", m.Status).Error; err != nil {
common.ApiError(c, err)
return
}
} else {
// 名称冲突检查
if dup, err := model.IsModelNameDuplicated(m.Id, m.ModelName); err != nil {
common.ApiError(c, err)
return
} else if dup {
common.ApiErrorMsg(c, "模型名称已存在")
return
}
if err := m.Update(); err != nil {
common.ApiError(c, err)
return
}
}
model.RefreshPricing()
common.ApiSuccess(c, &m)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// DeleteModelMeta 删除模型
func DeleteModelMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
common.ApiError(c, err)
return
}
if err := model.DB.Delete(&model.Model{}, id).Error; err != nil {
common.ApiError(c, err)
return
}
model.RefreshPricing()
common.ApiSuccess(c, nil)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// 辅助函数:填充 Endpoints 和 BoundChannels 和 EnableGroups
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
func fillModelExtra(m *model.Model) {
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
// 若为精确匹配,保持原有逻辑
if m.NameRule == model.NameRuleExact {
if m.Endpoints == "" {
eps := model.GetModelSupportEndpointTypes(m.ModelName)
if b, err := json.Marshal(eps); err == nil {
m.Endpoints = string(b)
}
}
if channels, err := model.GetBoundChannels(m.ModelName); err == nil {
m.BoundChannels = channels
}
m.EnableGroups = model.GetModelEnableGroups(m.ModelName)
m.QuotaType = model.GetModelQuotaType(m.ModelName)
return
}
// 非精确匹配:计算并集
pricings := model.GetPricing()
// 匹配到的模型名称集合
matchedNames := make([]string, 0)
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
// 端点去重集合
endpointSet := make(map[constant.EndpointType]struct{})
// 已绑定渠道去重集合
channelSet := make(map[string]model.BoundChannel)
// 分组去重集合
groupSet := make(map[string]struct{})
// 计费类型(若有任意模型为 1则返回 1
quotaTypeSet := make(map[int]struct{})
for _, p := range pricings {
var matched bool
switch m.NameRule {
case model.NameRulePrefix:
matched = strings.HasPrefix(p.ModelName, m.ModelName)
case model.NameRuleSuffix:
matched = strings.HasSuffix(p.ModelName, m.ModelName)
case model.NameRuleContains:
matched = strings.Contains(p.ModelName, m.ModelName)
}
if !matched {
continue
}
// 记录匹配到的模型名称
matchedNames = append(matchedNames, p.ModelName)
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
// 收集端点
for _, et := range p.SupportedEndpointTypes {
endpointSet[et] = struct{}{}
}
// 收集分组
for _, g := range p.EnableGroup {
groupSet[g] = struct{}{}
}
// 收集计费类型
quotaTypeSet[p.QuotaType] = struct{}{}
// 收集渠道
if channels, err := model.GetBoundChannels(p.ModelName); err == nil {
for _, ch := range channels {
key := ch.Name + "_" + strconv.Itoa(ch.Type)
channelSet[key] = ch
}
}
}
// 序列化端点
if len(endpointSet) > 0 && m.Endpoints == "" {
eps := make([]constant.EndpointType, 0, len(endpointSet))
for et := range endpointSet {
eps = append(eps, et)
}
2025-08-10 12:11:31 +08:00
if b, err := json.Marshal(eps); err == nil {
m.Endpoints = string(b)
}
}
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
// 序列化渠道
if len(channelSet) > 0 {
channels := make([]model.BoundChannel, 0, len(channelSet))
for _, ch := range channelSet {
channels = append(channels, ch)
}
2025-08-10 12:11:31 +08:00
m.BoundChannels = channels
}
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
// 序列化分组
if len(groupSet) > 0 {
groups := make([]string, 0, len(groupSet))
for g := range groupSet {
groups = append(groups, g)
}
m.EnableGroups = groups
}
// 确定计费类型:仅当所有匹配模型计费类型一致时才返回该类型,否则返回 -1 表示未知/不确定
if len(quotaTypeSet) == 1 {
for k := range quotaTypeSet {
m.QuotaType = k
}
} else {
m.QuotaType = -1
}
// 设置匹配信息
m.MatchedModels = matchedNames
m.MatchedCount = len(matchedNames)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}