using System.Text.Json.Serialization;
using AIStudio.Provider;
namespace AIStudio.Assistants.ModelComparison;
///
/// Which model took part in a stored comparison.
///
///
/// The statistics count a model across comparisons by its provider, its host, and its ID, not by the provider entry
/// of the settings: the user may delete or rename that entry, and two entries may point to the same model. Only a
/// self-hosted model has a host of its own; two servers may run models of the same name which are not the same.
///
public sealed record ModelComparisonModelIdentity
{
///
/// The kind of provider which ran the model.
///
public LLMProviders LLMProvider { get; set; } = LLMProviders.NONE;
///
/// The address of the server of a self-hosted model; empty for every other provider.
///
public string Hostname { get; set; } = string.Empty;
///
/// The ID of the model at its provider.
///
public string ModelId { get; set; } = string.Empty;
///
/// The name the comparison showed for the model, for the statistics to show it again.
///
public string Label { get; set; } = string.Empty;
///
/// Gets the identity of the model of a provider entry.
///
/// The provider entry, with its model.
/// The identity.
public static ModelComparisonModelIdentity Of(AIStudio.Settings.Provider provider) => new()
{
LLMProvider = provider.UsedLLMProvider,
Hostname = provider.IsSelfHosted ? provider.Hostname : string.Empty,
ModelId = provider.Model.Id,
Label = provider.ToString(),
};
///
/// Gets what tells this model apart from others, whatever the label.
///
[JsonIgnore]
public ModelComparisonModelKey Key => ModelComparisonModelKey.Of(this.LLMProvider, this.Hostname, this.ModelId);
///
/// Whether both identities name the same model, whatever the label.
///
/// The other identity.
public bool IsSameModelAs(ModelComparisonModelIdentity other) => this.Key == other.Key;
}