channel_affinity_setting.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. SkipRetryOnFailure bool `json:"skip_retry_on_failure,omitempty"`
  17. IncludeUsingGroup bool `json:"include_using_group"`
  18. IncludeRuleName bool `json:"include_rule_name"`
  19. }
  20. type ChannelAffinitySetting struct {
  21. Enabled bool `json:"enabled"`
  22. SwitchOnSuccess bool `json:"switch_on_success"`
  23. MaxEntries int `json:"max_entries"`
  24. DefaultTTLSeconds int `json:"default_ttl_seconds"`
  25. Rules []ChannelAffinityRule `json:"rules"`
  26. }
  27. var channelAffinitySetting = ChannelAffinitySetting{
  28. Enabled: false,
  29. SwitchOnSuccess: true,
  30. MaxEntries: 100_000,
  31. DefaultTTLSeconds: 3600,
  32. Rules: []ChannelAffinityRule{},
  33. }
  34. func init() {
  35. config.GlobalConfig.Register("channel_affinity_setting", &channelAffinitySetting)
  36. }
  37. func GetChannelAffinitySetting() *ChannelAffinitySetting {
  38. return &channelAffinitySetting
  39. }