using System.Text.Json.Serialization; using AIStudio.Provider; using AIStudio.Provider.HuggingFace; using AIStudio.Tools.PluginSystem; using Host = AIStudio.Provider.SelfHosted.Host; namespace AIStudio.Settings; /// /// Data model for configured providers. /// /// The provider's number. /// The provider's ID. /// The provider's instance name. Useful for multiple instances of the same provider, e.g., to distinguish between different OpenAI API keys. /// The provider used. /// Whether the provider is self-hosted. /// The hostname of the provider. Useful for self-hosted providers. /// The LLM model to use for chat. public record Provider( uint Num, string Id, string InstanceName, LLMProviders UsedLLMProvider, Model Model, bool IsSelfHosted = false, bool IsEnterpriseConfiguration = false, Guid EnterpriseConfigurationPluginId = default, string Hostname = "http://localhost:1234", Host Host = Host.NONE, HFInferenceProvider HFInferenceProvider = HFInferenceProvider.NONE) : ISecretId, IConfigurationObject { public static readonly Provider NONE = new(); public Provider() : this( 0, Guid.Empty.ToString(), string.Empty, LLMProviders.NONE, default, false, false, Guid.Empty) { } #region Overrides of ValueType /// /// Returns a string that represents the current provider in a human-readable format. /// We use this to display the provider in the chat UI. /// /// A string that represents the current provider in a human-readable format. public override string ToString() { if(this.IsSelfHosted) return $"{this.InstanceName} ({this.UsedLLMProvider.ToName()}, {this.Host}, {this.Hostname}, {this.Model})"; return $"{this.InstanceName} ({this.UsedLLMProvider.ToName()}, {this.Model})"; } #endregion #region Implementation of ISecretId /// [JsonIgnore] public string SecretId => this.Id; /// [JsonIgnore] public string SecretName => this.InstanceName; #endregion #region Implementation of IConfigurationObject public string Name => this.InstanceName; #endregion }