Files
new-api/model/model_extra.go
t0ng7u 5e70274003 💰 feat: Add model billing type (quota_type) support across backend & frontend
Summary
• Backend
  1. model/model_meta.go
     – Added `QuotaType` field to `Model` struct (JSON only, gorm `-`).
  2. model/model_groups.go
     – Implemented `GetModelQuotaType(modelName)` leveraging cached pricing map.
  3. controller/model_meta.go
     – Enhanced `fillModelExtra` to populate `QuotaType` using new helper.

• Frontend
  1. web/src/components/table/models/ModelsColumnDefs.js
     – Introduced `renderQuotaType` helper that visualises billing mode with coloured tags (`teal = per-call`, `violet = per-token`).
     – Added “计费类型” column (`quota_type`) to models table.

Why
Providing the billing mode alongside existing pricing/group information gives administrators instant visibility into whether each model is priced per call or per token, aligning UI with new backend metadata.

Notes
No database migration required – `quota_type` is transient, delivered via API. Frontend labels/colours can be adjusted via i18n or theme tokens if necessary.
2025-08-04 15:38:01 +08:00

25 lines
745 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
// GetModelEnableGroups 返回指定模型名称可用的用户分组列表。
// 复用缓存的定价映射,避免额外的数据库查询。
func GetModelEnableGroups(modelName string) []string {
for _, p := range GetPricing() {
if p.ModelName == modelName {
return p.EnableGroup
}
}
return make([]string, 0)
}
// GetModelQuotaType 返回指定模型的计费类型quota_type
// 复用缓存的定价映射,避免额外数据库查询。
// 如果未找到对应模型,默认返回 0。
func GetModelQuotaType(modelName string) int {
for _, p := range GetPricing() {
if p.ModelName == modelName {
return p.QuotaType
}
}
return 0
}