Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

88 lignes
2.5 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. PassthroughApplyModelMapping bool `json:"passthrough_apply_model_mapping"`
  32. ThinkingModelBlacklist []string `json:"thinking_model_blacklist"`
  33. ChatCompletionsToResponsesPolicy ChatCompletionsToResponsesPolicy `json:"chat_completions_to_responses_policy"`
  34. EndpointFormatRestrictionEnabled bool `json:"endpoint_format_restriction_enabled"`
  35. }
  36. // 默认配置
  37. var defaultOpenaiSettings = GlobalSettings{
  38. PassThroughRequestEnabled: false,
  39. PassthroughApplyModelMapping: false,
  40. ThinkingModelBlacklist: []string{
  41. "moonshotai/kimi-k2-thinking",
  42. "kimi-k2-thinking",
  43. },
  44. ChatCompletionsToResponsesPolicy: ChatCompletionsToResponsesPolicy{
  45. Enabled: false,
  46. AllChannels: true,
  47. },
  48. EndpointFormatRestrictionEnabled: false,
  49. }
  50. // 全局实例
  51. var globalSettings = defaultOpenaiSettings
  52. func init() {
  53. // 注册到全局配置管理器
  54. config.GlobalConfig.Register("global", &globalSettings)
  55. }
  56. func GetGlobalSettings() *GlobalSettings {
  57. return &globalSettings
  58. }
  59. func IsEndpointFormatRestrictionEnabled() bool {
  60. return globalSettings.EndpointFormatRestrictionEnabled
  61. }
  62. // ShouldPreserveThinkingSuffix 判断模型是否配置为保留 thinking/-nothinking/-low/-high/-medium 后缀
  63. func ShouldPreserveThinkingSuffix(modelName string) bool {
  64. target := strings.TrimSpace(modelName)
  65. if target == "" {
  66. return false
  67. }
  68. for _, entry := range globalSettings.ThinkingModelBlacklist {
  69. if strings.TrimSpace(entry) == target {
  70. return true
  71. }
  72. }
  73. return false
  74. }