39 improve hostname handling (#42)

This commit is contained in:
Thorsten Sommer 2024-07-24 19:27:25 +02:00 committed by GitHub
parent 5250e5d2fb
commit 4f5815272a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 13 deletions

View File

@ -29,11 +29,11 @@
<MudTd> <MudTd>
@if (context.UsedProvider is not Providers.SELF_HOSTED) @if (context.UsedProvider is not Providers.SELF_HOSTED)
{ {
@context.Model @this.GetProviderModelName(context)
} }
else if (context.UsedProvider is Providers.SELF_HOSTED && context.Host is not Host.LLAMACPP) else if (context.UsedProvider is Providers.SELF_HOSTED && context.Host is not Host.LLAMACPP)
{ {
@context.Model @this.GetProviderModelName(context)
} }
else else
{ {

View File

@ -111,5 +111,12 @@ public partial class Settings : ComponentBase
_ => string.Empty, _ => string.Empty,
}; };
private string GetProviderModelName(AIStudio.Settings.Provider provider)
{
const int MAX_LENGTH = 36;
var modelName = provider.Model.ToString();
return modelName.Length > MAX_LENGTH ? "[...] " + modelName[^Math.Min(MAX_LENGTH, modelName.Length)..] : modelName;
}
#endregion #endregion
} }

View File

@ -47,7 +47,11 @@ public static class ExtensionsProvider
/// </summary> /// </summary>
/// <param name="providerSettings">The provider settings.</param> /// <param name="providerSettings">The provider settings.</param>
/// <returns>The provider instance.</returns> /// <returns>The provider instance.</returns>
public static IProvider CreateProvider(this Settings.Provider providerSettings) => providerSettings.UsedProvider switch public static IProvider CreateProvider(this Settings.Provider providerSettings)
{
try
{
return providerSettings.UsedProvider switch
{ {
Providers.OPEN_AI => new ProviderOpenAI { InstanceName = providerSettings.InstanceName }, Providers.OPEN_AI => new ProviderOpenAI { InstanceName = providerSettings.InstanceName },
Providers.ANTHROPIC => new ProviderAnthropic { InstanceName = providerSettings.InstanceName }, Providers.ANTHROPIC => new ProviderAnthropic { InstanceName = providerSettings.InstanceName },
@ -58,3 +62,10 @@ public static class ExtensionsProvider
_ => new NoProvider(), _ => new NoProvider(),
}; };
} }
catch (Exception e)
{
Console.WriteLine($"Failed to create provider: {e.Message}");
return new NoProvider();
}
}
}

View File

@ -102,7 +102,7 @@ public partial class ProviderDialog : ComponentBase
UsedProvider = this.DataProvider, UsedProvider = this.DataProvider,
Model = this.DataModel, Model = this.DataModel,
IsSelfHosted = this.DataProvider is Providers.SELF_HOSTED, IsSelfHosted = this.DataProvider is Providers.SELF_HOSTED,
Hostname = this.DataHostname, Hostname = this.DataHostname.EndsWith('/') ? this.DataHostname[..^1] : this.DataHostname,
Host = this.DataHost, Host = this.DataHost,
}; };

View File

@ -0,0 +1,5 @@
# v0.8.3 (WIP)
- Migrated UI framework from MudBlazor v6.x.x to v7.x.x
- Added an option to configure the behavior of the navigation bar in the settings
- Improved the handling of self-hosted provider hostnames
- Improved the configured provider table: long model names are now truncated