Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Users can add local GenAI models. also remembers execution provider in MRU #263

Merged
merged 32 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
456d796
Starting to add local model support
nmetulev Feb 25, 2025
4bcd26b
Merge branch 'main' into nmetulev/add-local
nmetulev Feb 28, 2025
52a083d
Merge branch 'main' into nmetulev/add-local
nmetulev Mar 2, 2025
5d6e6cd
fixes and improvements in how added models show up
nmetulev Mar 2, 2025
98546a8
Inlcude hardware accelerator in mru and few other quality of life fixes
nmetulev Mar 3, 2025
7a86fdb
ESRGAN add default image
nmetulev Mar 3, 2025
5c214c2
fix for qnn project exporting
nmetulev Mar 3, 2025
9f252c8
Merge branch 'main' into nmetulev/add-local
nmetulev Mar 3, 2025
20010cb
Merge branch 'nmetulev/add-local' of https://github.com/microsoft/ai-…
nmetulev Mar 3, 2025
558ddfa
Merge branch 'main' into nmetulev/add-local
nmetulev Mar 3, 2025
ce45146
merged main
nmetulev Mar 20, 2025
59785d9
updated ver
nmetulev Mar 20, 2025
488c55f
fixed up ort versions
nmetulev Mar 20, 2025
927b831
Minor ux cleanup
nmetulev Mar 20, 2025
08f0c08
merged main
nmetulev Mar 21, 2025
86afa37
Fixing exported projects
nmetulev Mar 21, 2025
c9d44b2
Addressing feedback
nmetulev Mar 21, 2025
d98251d
addressing feedback
nmetulev Mar 21, 2025
9fabc05
fixed failing test
nmetulev Mar 21, 2025
fba3d9d
Merge branch 'main' into nmetulev/add-local
nmetulev Mar 21, 2025
58ae55d
Merge branch 'main' into nmetulev/add-local
nmetulev Mar 28, 2025
e233239
updated ort gena to 0.7.0
nmetulev Mar 28, 2025
62caecc
enable phi4 on arm
nmetulev Mar 28, 2025
e5b1922
Fixed project export.
azchohfi Mar 28, 2025
ab35038
Merge branch 'nmetulev/add-local' of https://github.com/microsoft/ai-…
azchohfi Mar 28, 2025
a1e0abf
pr feedback addressing
nmetulev Mar 28, 2025
4c60a57
removed empty line
nmetulev Mar 28, 2025
c36b74e
Small method rename.
azchohfi Mar 28, 2025
1ba62bc
Using Path.Join.
azchohfi Mar 28, 2025
80e7a79
pr feedback
nmetulev Mar 28, 2025
b2978fd
Merge branch 'nmetulev/add-local' of https://github.com/microsoft/ai-…
nmetulev Mar 28, 2025
c79d250
Merge branch 'main' into nmetulev/add-local
azchohfi Mar 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AIDevGallery.Utils/ModelUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ public static string GetFullUrl(string url)
{
return url;
}
else if (url.StartsWith("local", StringComparison.InvariantCultureIgnoreCase))
{
return url;
}
else
{
return new HuggingFaceUrl(url).FullUrl;
Expand Down
10 changes: 3 additions & 7 deletions AIDevGallery/AIDevGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,8 @@
</ItemGroup>

<ItemGroup Condition="$(Platform) == 'ARM64'">
<PackageReference Include="Microsoft.ML.OnnxRuntime.Qnn" />
<PackageReference Include="Microsoft.ML.OnnxRuntimeGenAI" GeneratePathProperty="true" ExcludeAssets="all" />
<None Include="$(PKGMicrosoft_ML_OnnxRuntimeGenAI)\runtimes\win-arm64\native\onnxruntime-genai.dll">
<Link>onnxruntime-genai.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<PackageReference Include="Microsoft.ML.OnnxRuntime.QNN" />
<PackageReference Include="Microsoft.ML.OnnxRuntimeGenAI.QNN" />
<PackageReference Include="Microsoft.ML.OnnxRuntimeGenAI.Managed" />
</ItemGroup>

Expand Down Expand Up @@ -250,6 +245,7 @@
<None Remove="Assets\ModelIcons\HuggingFace.svg" />
<None Remove="Assets\ModelIcons\Microsoft.svg" />
<None Remove="Assets\ModelIcons\Mistral.svg" />
<None Remove="Assets\ModelIcons\onnx.svg" />
<None Remove="Assets\ModelIcons\OpenAI.png" />
<None Remove="Assets\TileImages\Chat.png" />
<None Remove="Assets\TileImages\ClassifyImage.png" />
Expand Down
12 changes: 12 additions & 0 deletions AIDevGallery/Assets/ModelIcons/onnx.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions AIDevGallery/Controls/ModelSelectionControl.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="AIDevGallery.Controls.ModelSelectionControl"
xmlns:local="using:AIDevGallery.Controls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down Expand Up @@ -122,13 +123,15 @@
Source="{x:Bind utils:AppUtils.GetModelSourceImageFromUrl(ModelDetails.Url)}">
<ToolTipService.ToolTip>
<TextBlock TextWrapping="Wrap">
<Run Text="This model is from" />
<Run Text="{x:Bind utils:AppUtils.GetModelSourceNameFromUrl(ModelDetails.Url)}" />
</TextBlock>
</ToolTipService.ToolTip>
</Image>
<TextBlock Text="• " />
<TextBlock VerticalAlignment="Center" Text="{x:Bind utils:AppUtils.GetLicenseShortNameFromString(ModelDetails.License)}">
<TextBlock Text="• "
Visibility="{x:Bind local:ModelSelectionControl.ShowForDownloadedModelsOnly(ModelDetails)}" />
<TextBlock VerticalAlignment="Center"
Text="{x:Bind utils:AppUtils.GetLicenseShortNameFromString(ModelDetails.License)}"
Visibility="{x:Bind local:ModelSelectionControl.ShowForDownloadedModelsOnly(ModelDetails)}">
<ToolTipService.ToolTip>
<TextBlock TextWrapping="Wrap">
<Run Text="This model is under the" />
Expand Down Expand Up @@ -166,7 +169,7 @@
Icon="{ui:FontIcon Glyph=&#xE8A5;}"
Tag="{x:Bind ModelDetails}"
Text="View model card"
Visibility="{x:Bind ModelDetails.Size, Converter={StaticResource NotZeroToVisibilityConverter}}" />
Visibility="{x:Bind local:ModelSelectionControl.ShowForDownloadedModelsOnly(ModelDetails)}" />
<MenuFlyoutItem
Click="ApiDocumentation_Click"
Icon="{ui:FontIcon Glyph=&#xE8A5;}"
Expand All @@ -178,7 +181,7 @@
Icon="{ui:FontIcon Glyph=&#xE82D;}"
Tag="{x:Bind ModelDetails}"
Text="View license"
Visibility="{x:Bind ModelDetails.Size, Converter={StaticResource NotZeroToVisibilityConverter}}" />
Visibility="{x:Bind local:ModelSelectionControl.ShowForDownloadedModelsOnly(ModelDetails)}" />
<MenuFlyoutSeparator Visibility="{x:Bind ModelDetails.Size, Converter={StaticResource NotZeroToVisibilityConverter}}" />
<MenuFlyoutItem
Click="CopyModelPath_Click"
Expand Down Expand Up @@ -302,7 +305,6 @@
Source="{x:Bind utils:AppUtils.GetModelSourceImageFromUrl(ModelDetails.Url)}">
<ToolTipService.ToolTip>
<TextBlock TextWrapping="Wrap">
<Run Text="This model is from" />
<Run Text="{x:Bind utils:AppUtils.GetModelSourceNameFromUrl(ModelDetails.Url)}" />
</TextBlock>
</ToolTipService.ToolTip>
Expand Down Expand Up @@ -488,7 +490,6 @@
Source="{x:Bind utils:AppUtils.GetModelSourceImageFromUrl(ModelDetails.Url)}">
<ToolTipService.ToolTip>
<TextBlock TextWrapping="Wrap">
<Run Text="This model is from" />
<Run Text="{x:Bind utils:AppUtils.GetModelSourceNameFromUrl(ModelDetails.Url)}" />
</TextBlock>
</ToolTipService.ToolTip>
Expand Down
55 changes: 42 additions & 13 deletions AIDevGallery/Controls/ModelSelectionControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void ResetAndLoadModelList(ModelDetails? selectedModel = null)
if (AvailableModels.Count > 0)
{
var modelIds = AvailableModels.Select(s => s.ModelDetails.Id);
var modelOrApiUsageHistory = App.AppData.UsageHistory.Where(id => modelIds.Contains(id));
var modelOrApiUsageHistory = App.AppData.UsageHistoryV2?.FirstOrDefault(u => modelIds.Contains(u.Id));

ModelDetails? modelToPreselect = null;

Expand All @@ -111,20 +111,33 @@ private void ResetAndLoadModelList(ModelDetails? selectedModel = null)
modelToPreselect = AvailableModels.Where(m => m.ModelDetails.Id == selectedModel.Id).FirstOrDefault()?.ModelDetails;
}

if (modelToPreselect != null)
if (modelToPreselect == null && modelOrApiUsageHistory != default)
{
SetSelectedModel(selectedModel);
}
else if (modelOrApiUsageHistory.Any())
{
// select most recently used if there is one
var modelId = modelOrApiUsageHistory.First();
SetSelectedModel(AvailableModels.Where(s => s.ModelDetails.Id == modelId).First().ModelDetails);
var models = AvailableModels.Where(am => am.ModelDetails.Id == modelOrApiUsageHistory.Id).ToList();
if (models.Count > 0)
{
if (modelOrApiUsageHistory.HardwareAccelerator != null)
{
var model = models.FirstOrDefault(m => m.ModelDetails.HardwareAccelerators.Contains(modelOrApiUsageHistory.HardwareAccelerator.Value));
if (model != null)
{
modelToPreselect = model.ModelDetails;
}
}

if (modelToPreselect == null)
{
modelToPreselect = models.FirstOrDefault()?.ModelDetails;
}
}
}
else

if (modelToPreselect == null)
{
SetSelectedModel(AvailableModels[0].ModelDetails);
modelToPreselect = AvailableModels[0].ModelDetails;
}

SetSelectedModel(modelToPreselect);
}
else
{
Expand All @@ -133,7 +146,7 @@ private void ResetAndLoadModelList(ModelDetails? selectedModel = null)
}
}

private void SetSelectedModel(ModelDetails? modelDetails)
private void SetSelectedModel(ModelDetails? modelDetails, HardwareAccelerator? accelerator = null)
{
if (modelDetails != null)
{
Expand Down Expand Up @@ -166,7 +179,13 @@ private void SetViewSelection(ModelDetails modelDetails)
if (IsSelectionEnabled)
{
ModelSelectionItemsView.DeselectAll();
ModelSelectionItemsView.Select(AvailableModels.IndexOf(AvailableModels.First(a => a.ModelDetails.Id == modelDetails.Id)));

var models = AvailableModels.Where(a => a.ModelDetails == modelDetails).ToList();

if (models.Count != 0)
{
ModelSelectionItemsView.Select(AvailableModels.IndexOf(models.First()));
}
}
}

Expand Down Expand Up @@ -545,4 +564,14 @@ public void HideDownloadDialog()
{
DownloadDialog?.Hide();
}

public static Visibility ShowForDownloadedModelsOnly(ModelDetails details)
{
if (!details.HardwareAccelerators.Contains(HardwareAccelerator.WCRAPI) && !details.IsUserAdded)
{
return Visibility.Visible;
}

return Visibility.Collapsed;
}
}
4 changes: 4 additions & 0 deletions AIDevGallery/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public void NavigateToPage(object? obj)
{
NavigateToApiOrModelPage(modelTypes[0]);
}
else if (obj is ModelDetails)
{
Navigate("Models", obj);
}
else
{
Navigate("Home");
Expand Down
7 changes: 6 additions & 1 deletion AIDevGallery/Models/BaseSampleNavigationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal abstract class BaseSampleNavigationParameters(TaskCompletionSource samp
public TaskCompletionSource SampleLoadedCompletionSource { get; set; } = sampleLoadedCompletionSource;

protected abstract string ChatClientModelPath { get; }
protected abstract HardwareAccelerator ChatClientHardwareAccelerator { get; }
protected abstract LlmPromptTemplate? ChatClientPromptTemplate { get; }

public void NotifyCompletion()
Expand All @@ -28,7 +29,11 @@ public void NotifyCompletion()
return await PhiSilicaClient.CreateAsync(CancellationToken).ConfigureAwait(false);
}

return await GenAIModel.CreateAsync(ChatClientModelPath, ChatClientPromptTemplate, CancellationToken).ConfigureAwait(false);
return await GenAIModel.CreateAsync(
ChatClientModelPath,
ChatClientPromptTemplate,
ChatClientHardwareAccelerator == HardwareAccelerator.QNN ? "qnn" : null,
CancellationToken).ConfigureAwait(false);
}

internal abstract void SendSampleInteractionEvent(string? customInfo = null);
Expand Down
8 changes: 7 additions & 1 deletion AIDevGallery/Models/CachedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public CachedModel(ModelDetails details, string path, bool isFile, long modelSiz
Url = details.Url;
Source = CachedModelSource.GitHub;
}
else if (details.Url.StartsWith("local", StringComparison.InvariantCulture))
{
Url = details.Url;
Source = CachedModelSource.Local;
}
else
{
Url = new HuggingFaceUrl(details.Url).FullUrl;
Expand All @@ -42,5 +47,6 @@ public CachedModel(ModelDetails details, string path, bool isFile, long modelSiz
internal enum CachedModelSource
{
GitHub,
HuggingFace
HuggingFace,
Local
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class MultiModelSampleNavigationParameters(
public HardwareAccelerator[] HardwareAccelerators { get; } = hardwareAccelerators;

protected override string ChatClientModelPath => ModelPaths[0];
protected override HardwareAccelerator ChatClientHardwareAccelerator => HardwareAccelerators[0];
protected override LlmPromptTemplate? ChatClientPromptTemplate => promptTemplates[0];

internal override void SendSampleInteractionEvent(string? customInfo = null)
Expand Down
1 change: 1 addition & 0 deletions AIDevGallery/Models/SampleNavigationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class SampleNavigationParameters(
public string SampleId => sampleId;

protected override string ChatClientModelPath => ModelPath;
protected override HardwareAccelerator ChatClientHardwareAccelerator => HardwareAccelerator;
protected override LlmPromptTemplate? ChatClientPromptTemplate => promptTemplate;

internal override void SendSampleInteractionEvent(string? customInfo = null)
Expand Down
4 changes: 4 additions & 0 deletions AIDevGallery/Models/Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public string Icon
icon = "GitHub.dark.svg";
}
}
else if (Url.StartsWith("local", StringComparison.InvariantCultureIgnoreCase))
{
icon = "onnx.svg";
}
else
{
icon = "HuggingFace.svg";
Expand Down
4 changes: 4 additions & 0 deletions AIDevGallery/Pages/Models/AddModelPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
IsEnabled="{Binding ElementName=SearchTextBox, Path=Text, Converter={StaticResource EmptyStringToObjectConverter}}"
Style="{StaticResource AccentButtonStyle}" />
</Grid>
<HyperlinkButton Content="or add a local model"
Margin="0,8,0,0"
HorizontalAlignment="Center"
Click="AddLocalClicked"></HyperlinkButton>
</StackPanel>

<ProgressBar
Expand Down
Loading
Loading