model_extra.go 917 B

12345678910111213141516171819202122232425262728293031323334
  1. package model
  2. // GetModelEnableGroups 返回指定模型名称可用的用户分组列表。
  3. // 使用在 updatePricing() 中维护的缓存映射,O(1) 读取,适合高并发场景。
  4. func GetModelEnableGroups(modelName string) []string {
  5. // 确保缓存最新
  6. GetPricing()
  7. if modelName == "" {
  8. return make([]string, 0)
  9. }
  10. modelEnableGroupsLock.RLock()
  11. groups, ok := modelEnableGroups[modelName]
  12. modelEnableGroupsLock.RUnlock()
  13. if !ok {
  14. return make([]string, 0)
  15. }
  16. return groups
  17. }
  18. // GetModelQuotaType 返回指定模型的计费类型(quota_type)。
  19. // 同样使用缓存映射,避免每次遍历定价切片。
  20. func GetModelQuotaType(modelName string) int {
  21. GetPricing()
  22. modelEnableGroupsLock.RLock()
  23. quota, ok := modelQuotaTypeMap[modelName]
  24. modelEnableGroupsLock.RUnlock()
  25. if !ok {
  26. return 0
  27. }
  28. return quota
  29. }