No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

86 líneas
2.3 KiB

  1. package model_setting
  2. import (
  3. "slices"
  4. "strings"
  5. "github.com/QuantumNous/new-api/setting/config"
  6. )
  7. type ChatCompletionsToResponsesPolicy struct {
  8. Enabled bool `json:"enabled"`
  9. AllChannels bool `json:"all_channels"`
  10. ChannelIDs []int `json:"channel_ids,omitempty"`
  11. ChannelTypes []int `json:"channel_types,omitempty"`
  12. ModelPatterns []string `json:"model_patterns,omitempty"`
  13. }
  14. func (p ChatCompletionsToResponsesPolicy) IsChannelEnabled(channelID int, channelType int) bool {
  15. if !p.Enabled {
  16. return false
  17. }
  18. if p.AllChannels {
  19. return true
  20. }
  21. if channelID > 0 && len(p.ChannelIDs) > 0 && slices.Contains(p.ChannelIDs, channelID) {
  22. return true
  23. }
  24. if channelType > 0 && len(p.ChannelTypes) > 0 && slices.Contains(p.ChannelTypes, channelType) {
  25. return true
  26. }
  27. return false
  28. }
  29. type GlobalSettings struct {
  30. PassThroughRequestEnabled bool `json:"pass_through_request_enabled"`
  31. ThinkingModelBlacklist []string `json:"thinking_model_blacklist"`
  32. ChatCompletionsToResponsesPolicy ChatCompletionsToResponsesPolicy `json:"chat_completions_to_responses_policy"`
  33. EndpointFormatRestrictionEnabled bool `json:"endpoint_format_restriction_enabled"`
  34. }
  35. // 默认配置
  36. var defaultOpenaiSettings = GlobalSettings{
  37. PassThroughRequestEnabled: false,
  38. ThinkingModelBlacklist: []string{
  39. "moonshotai/kimi-k2-thinking",
  40. "kimi-k2-thinking",
  41. },
  42. ChatCompletionsToResponsesPolicy: ChatCompletionsToResponsesPolicy{
  43. Enabled: false,
  44. AllChannels: true,
  45. },
  46. EndpointFormatRestrictionEnabled: false,
  47. }
  48. // 全局实例
  49. var globalSettings = defaultOpenaiSettings
  50. func init() {
  51. // 注册到全局配置管理器
  52. config.GlobalConfig.Register("global", &globalSettings)
  53. }
  54. func GetGlobalSettings() *GlobalSettings {
  55. return &globalSettings
  56. }
  57. func IsEndpointFormatRestrictionEnabled() bool {
  58. return globalSettings.EndpointFormatRestrictionEnabled
  59. }
  60. // ShouldPreserveThinkingSuffix 判断模型是否配置为保留 thinking/-nothinking/-low/-high/-medium 后缀
  61. func ShouldPreserveThinkingSuffix(modelName string) bool {
  62. target := strings.TrimSpace(modelName)
  63. if target == "" {
  64. return false
  65. }
  66. for _, entry := range globalSettings.ThinkingModelBlacklist {
  67. if strings.TrimSpace(entry) == target {
  68. return true
  69. }
  70. }
  71. return false
  72. }