Improved model display while configuring a provider when the provider supports display names

This commit is contained in:
Thorsten Sommer 2024-11-09 22:01:23 +01:00
parent 2ae40c59a3
commit cc44e45725
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
4 changed files with 36 additions and 14 deletions

View File

@ -147,18 +147,18 @@ public sealed class ProviderAnthropic(ILogger logger) : BaseProvider("https://ap
{ {
return Task.FromResult(new[] return Task.FromResult(new[]
{ {
new Model("claude-3-5-sonnet-latest"), new Model("claude-3-5-sonnet-latest", "Claude 3.5 Sonnet (latest)"),
new Model("claude-3-5-sonnet-20240620"), new Model("claude-3-5-sonnet-20240620", "Claude 3.5 Sonnet (20. June 2024)"),
new Model("claude-3-5-sonnet-20241022"), new Model("claude-3-5-sonnet-20241022", "Claude 3.5 Sonnet (22. October 2024)"),
new Model("claude-3-5-haiku-latest"), new Model("claude-3-5-haiku-latest", "Claude 3.5 Haiku (latest)"),
new Model("claude-3-5-heiku-20241022"), new Model("claude-3-5-heiku-20241022", "Claude 3.5 Haiku (22. October 2024)"),
new Model("claude-3-opus-20240229"), new Model("claude-3-opus-20240229", "Claude 3.0 Opus (29. February 2024)"),
new Model("claude-3-opus-latest"), new Model("claude-3-opus-latest", "Claude 3.0 Opus (latest)"),
new Model("claude-3-sonnet-20240229"), new Model("claude-3-sonnet-20240229", "Claude 3.0 Sonnet (29. February 2024)"),
new Model("claude-3-haiku-20240307"), new Model("claude-3-haiku-20240307", "Claude 3.0 Haiku (7. March 2024)"),
}.AsEnumerable()); }.AsEnumerable());
} }

View File

@ -173,7 +173,7 @@ public sealed class ProviderMistral(ILogger logger) : BaseProvider("https://api.
return modelResponse.Data.Where(n => return modelResponse.Data.Where(n =>
!n.Id.StartsWith("code", StringComparison.InvariantCulture) && !n.Id.StartsWith("code", StringComparison.InvariantCulture) &&
!n.Id.Contains("embed", StringComparison.InvariantCulture)) !n.Id.Contains("embed", StringComparison.InvariantCulture))
.Select(n => new Provider.Model(n.Id)); .Select(n => new Provider.Model(n.Id, null));
} }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously

View File

@ -4,11 +4,33 @@ namespace AIStudio.Provider;
/// The data model for the model to use. /// The data model for the model to use.
/// </summary> /// </summary>
/// <param name="Id">The model's ID.</param> /// <param name="Id">The model's ID.</param>
public readonly record struct Model(string Id) /// <param name="DisplayName">The model's display name.</param>
public readonly record struct Model(string Id, string? DisplayName)
{ {
#region Overrides of ValueType #region Overrides of ValueType
public override string ToString() => string.IsNullOrWhiteSpace(this.Id) ? "no model selected" : this.Id; public override string ToString()
{
if(!string.IsNullOrWhiteSpace(this.DisplayName))
return this.DisplayName;
if(!string.IsNullOrWhiteSpace(this.Id))
return this.Id;
return "no model selected";
}
#endregion
#region Implementation of IEquatable<Model?>
public bool Equals(Model? other)
{
if(other is null)
return false;
return this.Id == other.Value.Id;
}
#endregion #endregion
} }

View File

@ -164,7 +164,7 @@ public sealed class ProviderSelfHosted(ILogger logger, Settings.Provider provide
case Host.LLAMACPP: case Host.LLAMACPP:
// Right now, llama.cpp only supports one model. // Right now, llama.cpp only supports one model.
// There is no API to list the model(s). // There is no API to list the model(s).
return [ new Provider.Model("as configured by llama.cpp") ]; return [ new Provider.Model("as configured by llama.cpp", null) ];
case Host.LM_STUDIO: case Host.LM_STUDIO:
case Host.OLLAMA: case Host.OLLAMA:
@ -188,7 +188,7 @@ public sealed class ProviderSelfHosted(ILogger logger, Settings.Provider provide
return []; return [];
var lmStudioModelResponse = await lmStudioResponse.Content.ReadFromJsonAsync<ModelsResponse>(token); var lmStudioModelResponse = await lmStudioResponse.Content.ReadFromJsonAsync<ModelsResponse>(token);
return lmStudioModelResponse.Data.Select(n => new Provider.Model(n.Id)); return lmStudioModelResponse.Data.Select(n => new Provider.Model(n.Id, null));
} }
return []; return [];