channel_affinity_setting.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package operation_setting
  2. import "github.com/QuantumNous/new-api/setting/config"
  3. type ChannelAffinityKeySource struct {
  4. Type string `json:"type"` // context_int, context_string, gjson
  5. Key string `json:"key,omitempty"`
  6. Path string `json:"path,omitempty"`
  7. }
  8. type ChannelAffinityRule struct {
  9. Name string `json:"name"`
  10. ModelRegex []string `json:"model_regex"`
  11. PathRegex []string `json:"path_regex"`
  12. UserAgentInclude []string `json:"user_agent_include,omitempty"`
  13. KeySources []ChannelAffinityKeySource `json:"key_sources"`
  14. ValueRegex string `json:"value_regex"`
  15. TTLSeconds int `json:"ttl_seconds"`
  16. IncludeUsingGroup bool `json:"include_using_group"`
  17. IncludeRuleName bool `json:"include_rule_name"`
  18. }
  19. type ChannelAffinitySetting struct {
  20. Enabled bool `json:"enabled"`
  21. SwitchOnSuccess bool `json:"switch_on_success"`
  22. MaxEntries int `json:"max_entries"`
  23. DefaultTTLSeconds int `json:"default_ttl_seconds"`
  24. Rules []ChannelAffinityRule `json:"rules"`
  25. }
  26. var channelAffinitySetting = ChannelAffinitySetting{
  27. Enabled: false,
  28. SwitchOnSuccess: true,
  29. MaxEntries: 100_000,
  30. DefaultTTLSeconds: 3600,
  31. Rules: []ChannelAffinityRule{},
  32. }
  33. func init() {
  34. config.GlobalConfig.Register("channel_affinity_setting", &channelAffinitySetting)
  35. }
  36. func GetChannelAffinitySetting() *ChannelAffinitySetting {
  37. return &channelAffinitySetting
  38. }