/ src / settings-ui / Settings.UI.Library / AIServiceTypeRegistry.cs
AIServiceTypeRegistry.cs
  1  // Copyright (c) Microsoft Corporation
  2  // The Microsoft Corporation licenses this file to you under the MIT license.
  3  // See the LICENSE file in the project root for more information.
  4  
  5  using System;
  6  using System.Collections.Generic;
  7  using System.Linq;
  8  
  9  namespace Microsoft.PowerToys.Settings.UI.Library;
 10  
 11  /// <summary>
 12  /// Centralized registry for AI service type metadata.
 13  /// </summary>
 14  public static class AIServiceTypeRegistry
 15  {
 16      private static readonly Dictionary<AIServiceType, AIServiceTypeMetadata> MetadataMap = new()
 17      {
 18          [AIServiceType.AzureAIInference] = new AIServiceTypeMetadata
 19          {
 20              ServiceType = AIServiceType.AzureAIInference,
 21              DisplayName = "Azure AI Inference",
 22              IconPath = "ms-appx:///Assets/Settings/Icons/Models/Azure.svg",
 23              IsOnlineService = true,
 24              LegalDescription = "AdvancedPaste_AzureAIInference_LegalDescription",
 25              TermsLabel = "AdvancedPaste_AzureAIInference_TermsLabel",
 26              TermsUri = new Uri("https://azure.microsoft.com/support/legal/"),
 27              PrivacyLabel = "AdvancedPaste_AzureAIInference_PrivacyLabel",
 28              PrivacyUri = new Uri("https://privacy.microsoft.com/privacystatement"),
 29          },
 30          [AIServiceType.AzureOpenAI] = new AIServiceTypeMetadata
 31          {
 32              ServiceType = AIServiceType.AzureOpenAI,
 33              DisplayName = "Azure OpenAI",
 34              IconPath = "ms-appx:///Assets/Settings/Icons/Models/AzureAI.svg",
 35              IsOnlineService = true,
 36              LegalDescription = "AdvancedPaste_AzureOpenAI_LegalDescription",
 37              TermsLabel = "AdvancedPaste_AzureOpenAI_TermsLabel",
 38              TermsUri = new Uri("https://azure.microsoft.com/support/legal/"),
 39              PrivacyLabel = "AdvancedPaste_AzureOpenAI_PrivacyLabel",
 40              PrivacyUri = new Uri("https://privacy.microsoft.com/privacystatement"),
 41          },
 42          [AIServiceType.FoundryLocal] = new AIServiceTypeMetadata
 43          {
 44              ServiceType = AIServiceType.FoundryLocal,
 45              DisplayName = "Foundry Local",
 46              IconPath = "ms-appx:///Assets/Settings/Icons/Models/FoundryLocal.svg",
 47              IsOnlineService = false,
 48              IsLocalModel = true,
 49              LegalDescription = "AdvancedPaste_FoundryLocal_LegalDescription", // Resource key for localized description
 50          },
 51          [AIServiceType.Google] = new AIServiceTypeMetadata
 52          {
 53              ServiceType = AIServiceType.Google,
 54              DisplayName = "Google",
 55              IconPath = "ms-appx:///Assets/Settings/Icons/Models/Gemini.svg",
 56              IsOnlineService = true,
 57              LegalDescription = "AdvancedPaste_Google_LegalDescription",
 58              TermsLabel = "AdvancedPaste_Google_TermsLabel",
 59              TermsUri = new Uri("https://ai.google.dev/gemini-api/terms"),
 60              PrivacyLabel = "AdvancedPaste_Google_PrivacyLabel",
 61              PrivacyUri = new Uri("https://support.google.com/gemini/answer/13594961"),
 62          },
 63          [AIServiceType.Mistral] = new AIServiceTypeMetadata
 64          {
 65              ServiceType = AIServiceType.Mistral,
 66              DisplayName = "Mistral",
 67              IconPath = "ms-appx:///Assets/Settings/Icons/Models/Mistral.svg",
 68              IsOnlineService = true,
 69              LegalDescription = "AdvancedPaste_Mistral_LegalDescription",
 70              TermsLabel = "AdvancedPaste_Mistral_TermsLabel",
 71              TermsUri = new Uri("https://mistral.ai/terms-of-service/"),
 72              PrivacyLabel = "AdvancedPaste_Mistral_PrivacyLabel",
 73              PrivacyUri = new Uri("https://mistral.ai/privacy-policy/"),
 74          },
 75          [AIServiceType.ML] = new AIServiceTypeMetadata
 76          {
 77              ServiceType = AIServiceType.ML,
 78              DisplayName = "Windows ML",
 79              IconPath = "ms-appx:///Assets/Settings/Icons/Models/WindowsML.svg",
 80              LegalDescription = "AdvancedPaste_LocalModel_LegalDescription",
 81              IsAvailableInUI = false,
 82              IsOnlineService = false,
 83              IsLocalModel = true,
 84          },
 85          [AIServiceType.Ollama] = new AIServiceTypeMetadata
 86          {
 87              ServiceType = AIServiceType.Ollama,
 88              DisplayName = "Ollama",
 89              IconPath = "ms-appx:///Assets/Settings/Icons/Models/Ollama.svg",
 90  
 91              // Ollama provide online service, but we treat it as local model at first version since it can is known for local model.
 92              IsOnlineService = false,
 93              IsLocalModel = true,
 94              LegalDescription = "AdvancedPaste_LocalModel_LegalDescription",
 95              TermsLabel = "AdvancedPaste_Ollama_TermsLabel",
 96              TermsUri = new Uri("https://ollama.org/terms"),
 97              PrivacyLabel = "AdvancedPaste_Ollama_PrivacyLabel",
 98              PrivacyUri = new Uri("https://ollama.org/privacy"),
 99          },
100          [AIServiceType.Onnx] = new AIServiceTypeMetadata
101          {
102              ServiceType = AIServiceType.Onnx,
103              DisplayName = "ONNX",
104              LegalDescription = "AdvancedPaste_LocalModel_LegalDescription",
105              IconPath = "ms-appx:///Assets/Settings/Icons/Models/Onnx.svg",
106              IsOnlineService = false,
107              IsAvailableInUI = false,
108          },
109          [AIServiceType.OpenAI] = new AIServiceTypeMetadata
110          {
111              ServiceType = AIServiceType.OpenAI,
112              DisplayName = "OpenAI",
113              IconPath = "ms-appx:///Assets/Settings/Icons/Models/OpenAI.light.svg",
114              IsOnlineService = true,
115              LegalDescription = "AdvancedPaste_OpenAI_LegalDescription",
116              TermsLabel = "AdvancedPaste_OpenAI_TermsLabel",
117              TermsUri = new Uri("https://openai.com/terms"),
118              PrivacyLabel = "AdvancedPaste_OpenAI_PrivacyLabel",
119              PrivacyUri = new Uri("https://openai.com/privacy"),
120          },
121          [AIServiceType.Unknown] = new AIServiceTypeMetadata
122          {
123              ServiceType = AIServiceType.Unknown,
124              DisplayName = "Unknown",
125              IconPath = "ms-appx:///Assets/Settings/Icons/Models/OpenAI.light.svg",
126              IsOnlineService = false,
127              IsAvailableInUI = false,
128          },
129      };
130  
131      /// <summary>
132      /// Get metadata for a specific service type.
133      /// </summary>
134      public static AIServiceTypeMetadata GetMetadata(AIServiceType serviceType)
135      {
136          return MetadataMap.TryGetValue(serviceType, out var metadata)
137              ? metadata
138              : MetadataMap[AIServiceType.Unknown];
139      }
140  
141      /// <summary>
142      /// Get metadata for a service type from its string representation.
143      /// </summary>
144      public static AIServiceTypeMetadata GetMetadata(string serviceType)
145      {
146          var type = serviceType.ToAIServiceType();
147          return GetMetadata(type);
148      }
149  
150      /// <summary>
151      /// Get icon path for a service type.
152      /// </summary>
153      public static string GetIconPath(AIServiceType serviceType)
154      {
155          return GetMetadata(serviceType).IconPath;
156      }
157  
158      /// <summary>
159      /// Get icon path for a service type from its string representation.
160      /// </summary>
161      public static string GetIconPath(string serviceType)
162      {
163          return GetMetadata(serviceType).IconPath;
164      }
165  
166      /// <summary>
167      /// Get all service types available in the UI.
168      /// </summary>
169      public static IEnumerable<AIServiceTypeMetadata> GetAvailableServiceTypes()
170      {
171          return MetadataMap.Values.Where(m => m.IsAvailableInUI);
172      }
173  
174      /// <summary>
175      /// Get all online service types available in the UI.
176      /// </summary>
177      public static IEnumerable<AIServiceTypeMetadata> GetOnlineServiceTypes()
178      {
179          return GetAvailableServiceTypes().Where(m => m.IsOnlineService);
180      }
181  
182      /// <summary>
183      /// Get all local service types available in the UI.
184      /// </summary>
185      public static IEnumerable<AIServiceTypeMetadata> GetLocalServiceTypes()
186      {
187          return GetAvailableServiceTypes().Where(m => m.IsLocalModel);
188      }
189  }