You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 line
2.3KB

  1. package domain
  2. import "strings"
  3. const (
  4. LLMProviderOpenAI = "openai"
  5. LLMProviderAnthropic = "anthropic"
  6. LLMProviderGoogle = "google"
  7. LLMProviderXAI = "xai"
  8. LLMProviderOllama = "ollama"
  9. )
  10. type LLMModelOption struct {
  11. Value string
  12. Label string
  13. }
  14. type LLMProviderOption struct {
  15. Value string
  16. Label string
  17. Models []LLMModelOption
  18. }
  19. func DefaultLLMProvider() string {
  20. return LLMProviderOpenAI
  21. }
  22. func LLMProviderOptions() []LLMProviderOption {
  23. return []LLMProviderOption{
  24. {
  25. Value: LLMProviderOpenAI,
  26. Label: "OpenAI",
  27. Models: []LLMModelOption{
  28. {Value: "gpt-5.2", Label: "gpt-5.2"},
  29. {Value: "gpt-5.4", Label: "gpt-5.4"},
  30. },
  31. },
  32. {
  33. Value: LLMProviderAnthropic,
  34. Label: "Anthropic",
  35. Models: []LLMModelOption{
  36. {Value: "claude-sonnet-4-5", Label: "claude-sonnet-4-5"},
  37. {Value: "claude-opus-4-1", Label: "claude-opus-4-1"},
  38. },
  39. },
  40. {
  41. Value: LLMProviderGoogle,
  42. Label: "Google",
  43. Models: []LLMModelOption{
  44. {Value: "gemini-2.5-pro", Label: "gemini-2.5-pro"},
  45. {Value: "gemini-2.5-flash", Label: "gemini-2.5-flash"},
  46. },
  47. },
  48. {
  49. Value: LLMProviderXAI,
  50. Label: "xAI",
  51. Models: []LLMModelOption{
  52. {Value: "grok-4", Label: "grok-4"},
  53. {Value: "grok-3-mini", Label: "grok-3-mini"},
  54. },
  55. },
  56. {
  57. Value: LLMProviderOllama,
  58. Label: "Ollama",
  59. Models: []LLMModelOption{
  60. {Value: "llama3.2", Label: "llama3.2"},
  61. {Value: "qwen2.5", Label: "qwen2.5"},
  62. {Value: "mistral", Label: "mistral"},
  63. },
  64. },
  65. }
  66. }
  67. func LLMModelsByProvider(provider string) []LLMModelOption {
  68. normalized := NormalizeLLMProvider(provider)
  69. for _, option := range LLMProviderOptions() {
  70. if option.Value == normalized {
  71. out := make([]LLMModelOption, len(option.Models))
  72. copy(out, option.Models)
  73. return out
  74. }
  75. }
  76. return nil
  77. }
  78. func NormalizeLLMProvider(provider string) string {
  79. value := strings.ToLower(strings.TrimSpace(provider))
  80. for _, option := range LLMProviderOptions() {
  81. if option.Value == value {
  82. return value
  83. }
  84. }
  85. return DefaultLLMProvider()
  86. }
  87. func NormalizeLLMModel(provider, model string) string {
  88. models := LLMModelsByProvider(provider)
  89. if len(models) == 0 {
  90. return ""
  91. }
  92. value := strings.TrimSpace(model)
  93. for _, option := range models {
  94. if option.Value == value {
  95. return value
  96. }
  97. }
  98. return models[0].Value
  99. }