Skip to content

Commit

Permalink
39 improve hostname handling (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
SommerEngineering authored Jul 24, 2024
1 parent 5250e5d commit 4f58152
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/MindWork AI Studio/Components/Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
<MudTd>
@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)
{
@context.Model
@this.GetProviderModelName(context)
}
else
{
Expand Down
7 changes: 7 additions & 0 deletions app/MindWork AI Studio/Components/Pages/Settings.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,12 @@ private async Task DeleteProvider(AIStudio.Settings.Provider provider)
_ => 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
}
29 changes: 20 additions & 9 deletions app/MindWork AI Studio/Provider/Providers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,25 @@ public static class ExtensionsProvider
/// </summary>
/// <param name="providerSettings">The provider settings.</param>
/// <returns>The provider instance.</returns>
public static IProvider CreateProvider(this Settings.Provider providerSettings) => providerSettings.UsedProvider switch
public static IProvider CreateProvider(this Settings.Provider providerSettings)
{
Providers.OPEN_AI => new ProviderOpenAI { InstanceName = providerSettings.InstanceName },
Providers.ANTHROPIC => new ProviderAnthropic { InstanceName = providerSettings.InstanceName },
Providers.MISTRAL => new ProviderMistral { InstanceName = providerSettings.InstanceName },

Providers.SELF_HOSTED => new ProviderSelfHosted(providerSettings) { InstanceName = providerSettings.InstanceName },

_ => new NoProvider(),
};
try
{
return providerSettings.UsedProvider switch
{
Providers.OPEN_AI => new ProviderOpenAI { InstanceName = providerSettings.InstanceName },
Providers.ANTHROPIC => new ProviderAnthropic { InstanceName = providerSettings.InstanceName },
Providers.MISTRAL => new ProviderMistral { InstanceName = providerSettings.InstanceName },

Providers.SELF_HOSTED => new ProviderSelfHosted(providerSettings) { InstanceName = providerSettings.InstanceName },

_ => new NoProvider(),
};
}
catch (Exception e)
{
Console.WriteLine($"Failed to create provider: {e.Message}");
return new NoProvider();
}
}
}
4 changes: 2 additions & 2 deletions app/MindWork AI Studio/Settings/ProviderDialog.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public partial class ProviderDialog : ComponentBase
UsedProvider = this.DataProvider,
Model = this.DataModel,
IsSelfHosted = this.DataProvider is Providers.SELF_HOSTED,
Hostname = this.DataHostname,
Hostname = this.DataHostname.EndsWith('/') ? this.DataHostname[..^1] : this.DataHostname,
Host = this.DataHost,
};

Expand Down Expand Up @@ -312,7 +312,7 @@ private async Task ReloadModels()
var provider = currentProviderSettings.CreateProvider();
if(provider is NoProvider)
return;

var models = await provider.GetTextModels(this.JsRuntime, this.SettingsManager, this.dataAPIKey);

// Order descending by ID means that the newest models probably come first:
Expand Down
5 changes: 5 additions & 0 deletions app/MindWork AI Studio/wwwroot/changelog/v0.8.3.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4f58152

Please sign in to comment.