2025-08-04 15:38:01 +08:00
|
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
|
|
// GetModelEnableGroups 返回指定模型名称可用的用户分组列表。
|
2025-08-05 22:26:19 +08:00
|
|
|
|
// 使用在 updatePricing() 中维护的缓存映射,O(1) 读取,适合高并发场景。
|
2025-08-04 15:38:01 +08:00
|
|
|
|
func GetModelEnableGroups(modelName string) []string {
|
2025-08-05 22:26:19 +08:00
|
|
|
|
// 确保缓存最新
|
|
|
|
|
|
GetPricing()
|
|
|
|
|
|
|
|
|
|
|
|
if modelName == "" {
|
|
|
|
|
|
return make([]string, 0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
modelEnableGroupsLock.RLock()
|
|
|
|
|
|
groups, ok := modelEnableGroups[modelName]
|
|
|
|
|
|
modelEnableGroupsLock.RUnlock()
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
return make([]string, 0)
|
2025-08-04 15:38:01 +08:00
|
|
|
|
}
|
2025-08-05 22:26:19 +08:00
|
|
|
|
return groups
|
2025-08-04 15:38:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetModelQuotaType 返回指定模型的计费类型(quota_type)。
|
2025-08-05 22:26:19 +08:00
|
|
|
|
// 同样使用缓存映射,避免每次遍历定价切片。
|
2025-08-04 15:38:01 +08:00
|
|
|
|
func GetModelQuotaType(modelName string) int {
|
2025-08-05 22:26:19 +08:00
|
|
|
|
GetPricing()
|
|
|
|
|
|
|
|
|
|
|
|
modelEnableGroupsLock.RLock()
|
|
|
|
|
|
quota, ok := modelQuotaTypeMap[modelName]
|
|
|
|
|
|
modelEnableGroupsLock.RUnlock()
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
return 0
|
2025-08-04 15:38:01 +08:00
|
|
|
|
}
|
2025-08-05 22:26:19 +08:00
|
|
|
|
return quota
|
2025-08-04 15:38:01 +08:00
|
|
|
|
}
|