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

#251: Added Support for AI Toolkit deeplinks #305

Merged
merged 10 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions AIDevGallery.SourceGenerator/Models/AIToolkitAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Text.Json.Serialization;

namespace AIDevGallery.SourceGenerator.Models;

[JsonConverter(typeof(JsonStringEnumConverter<AIToolkitAction>))]
internal enum AIToolkitAction
{
FineTuning,
PromptBuilder,
BulkRun,
Playground
}
3 changes: 3 additions & 0 deletions AIDevGallery.SourceGenerator/Models/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ internal class Model
[JsonConverter(typeof(SingleOrListOfStringConverter))]
[JsonPropertyName("FileFilter")]
public List<string>? FileFilters { get; init; }
public List<AIToolkitAction>? AIToolkitActions { get; init; }
public string? AIToolkitId { get; init; }
public string? AIToolkitFinetuningId { get; init; }
}
8 changes: 7 additions & 1 deletion AIDevGallery.SourceGenerator/ModelsSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ private void GenerateModelDetails(StringBuilder sourceBuilder, Dictionary<string
var supportedOnQualcomm = modelDefinition.SupportedOnQualcomm.HasValue ? modelDefinition.SupportedOnQualcomm.Value.ToString().ToLower() : "null";
var icon = !string.IsNullOrEmpty(modelDefinition.Icon) ? $"\"{modelDefinition.Icon}\"" : "string.Empty";
var fileFilters = modelDefinition.FileFilters != null ? string.Join(", ", modelDefinition.FileFilters.Select(ff => $"\"{ff}\"")) : string.Empty;
var aiToolkitActions = modelDefinition.AIToolkitActions != null ? string.Join(", ", modelDefinition.AIToolkitActions.Select(action => $"AIToolkitAction.{action}")) : string.Empty;
var aiToolkitId = !string.IsNullOrEmpty(modelDefinition.AIToolkitId) ? $"\"{modelDefinition.AIToolkitId}\"" : "null";
var aiToolkitFinetuningId = !string.IsNullOrEmpty(modelDefinition.AIToolkitFinetuningId) ? $"\"{modelDefinition.AIToolkitFinetuningId}\"" : "null";

sourceBuilder.AppendLine(
$$""""
Expand All @@ -268,7 +271,10 @@ private void GenerateModelDetails(StringBuilder sourceBuilder, Dictionary<string
PromptTemplate = {{promptTemplate}},
Icon = {{icon}},
License = "{{modelDefinition.License}}",
FileFilters = [ {{fileFilters}} ]
FileFilters = [ {{fileFilters}} ],
AIToolkitActions = [ {{aiToolkitActions}} ],
AIToolkitId = {{aiToolkitId}},
AIToolkitFinetuningId = {{aiToolkitFinetuningId}}
}
},
"""");
Expand Down
Binary file added AIDevGallery/Assets/AITKIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions AIDevGallery/Models/Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ internal class ModelDetails
public string? ReadmeUrl { get; set; }
public string? License { get; set; }
public List<string>? FileFilters { get; set; }
public List<AIToolkitAction>? AIToolkitActions { get; set; }
public string? AIToolkitId { get; set; }
public string? AIToolkitFinetuningId { get; set; }

private ModelCompatibility? compatibility;
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
Expand Down Expand Up @@ -174,5 +177,14 @@ internal enum HardwareAccelerator
OLLAMA
}

[JsonConverter(typeof(JsonStringEnumConverter<AIToolkitAction>))]
internal enum AIToolkitAction
{
FineTuning,
PromptBuilder,
BulkRun,
Playground
}

#pragma warning restore SA1402 // File may only contain a single type
#pragma warning restore SA1649 // File name should match first type name
42 changes: 35 additions & 7 deletions AIDevGallery/Pages/Models/ModelPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,44 @@
</Grid.ColumnDefinitions>
<TextBlock
Margin="4,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource SubtitleTextBlockStyle}"
Text="{x:Bind ModelFamily.Name}" />
<controls:CopyButton
<StackPanel
Grid.Column="1"
Height="34"
AutomationProperties.Name="Copy link to page"
Click="CopyButton_Click"
Content="{ui:FontIcon Glyph=&#xE71B;,
FontSize=16}"
ToolTipService.ToolTip="Copy link to page" />
VerticalAlignment="Center"
Orientation="Horizontal"
Spacing="8">
<DropDownButton
x:Name="AIToolkitDropdown"
AutomationProperties.Name="Open in AI Toolkit"
Visibility="Collapsed">
<DropDownButton.Content>
<StackPanel Orientation="Horizontal" Spacing="8">
<Image Width="16">
<Image.Source>
<BitmapImage
DecodePixelHeight="16"
DecodePixelWidth="16"
UriSource="ms-appx:///Assets/AITKIcon.png" />
</Image.Source>
</Image>
<TextBlock Text="Open in AI Toolkit" />
</StackPanel>
</DropDownButton.Content>
<DropDownButton.Flyout>
<MenuFlyout x:Name="AIToolkitFlyout" Placement="Bottom" />
</DropDownButton.Flyout>
</DropDownButton>
<controls:CopyButton
Height="34"
AutomationProperties.Name="Copy link to page"
Click="CopyButton_Click"
Content="{ui:FontIcon Glyph=&#xE71B;,
FontSize=16}"
ToolTipService.ToolTip="Copy link to page" />
</StackPanel>


<ScrollViewer
x:Name="RootScroller"
Expand Down
94 changes: 92 additions & 2 deletions AIDevGallery/Pages/Models/ModelPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using AIDevGallery.Utils;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
Expand All @@ -22,6 +23,7 @@ internal sealed partial class ModelPage : Page
{
public ModelFamily? ModelFamily { get; set; }
private ModelType? modelFamilyType;
private List<ModelDetails> models = new();
private string? readme;

public ModelPage()
Expand Down Expand Up @@ -51,12 +53,14 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
modelFamilyType = modelType;
ModelFamily = modelFamilyDetails;

modelSelectionControl.SetModels(GetAllSampleDetails().ToList());
models = GetAllSampleDetails().ToList();
modelSelectionControl.SetModels(models);
}
else if (e.Parameter is ModelDetails details)
{
// this is likely user added model
modelSelectionControl.SetModels([details]);
models = [details];
modelSelectionControl.SetModels(models);

ModelFamily = new ModelFamily
{
Expand All @@ -80,6 +84,11 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
DocumentationCard.Visibility = Visibility.Collapsed;
}

if(models.Count > 0)
{
BuildAIToolkitButton();
}

EnableSampleListIfModelIsDownloaded();
App.ModelCache.CacheStore.ModelsChanged += CacheStore_ModelsChanged;
}
Expand Down Expand Up @@ -155,6 +164,87 @@ private IEnumerable<ModelDetails> GetAllSampleDetails()
}
}

private void BuildAIToolkitButton()
{
bool isAiToolkitActionAvailable = false;
Dictionary<AIToolkitAction, MenuFlyoutSubItem> actionSubmenus = new();

foreach(ModelDetails modelDetails in models)
{
if(modelDetails.AIToolkitActions == null)
{
continue;
}

foreach(AIToolkitAction action in modelDetails.AIToolkitActions)
{
if(modelDetails.ValidateAction(action))
{
continue;
}

MenuFlyoutSubItem? actionFlyoutItem;
if (!actionSubmenus.TryGetValue(action, out actionFlyoutItem))
{
actionFlyoutItem = new MenuFlyoutSubItem()
{
Text = AIToolkitHelper.AIToolkitActionInfos[action].DisplayName
};
actionSubmenus.Add(action, actionFlyoutItem);
AIToolkitFlyout.Items.Add(actionFlyoutItem);
}

isAiToolkitActionAvailable = true;
MenuFlyoutItem modelFlyoutItem = new MenuFlyoutItem()
{
Tag = (action, modelDetails),
Text = modelDetails.Name,
Icon = new ImageIcon()
{
Source = new BitmapImage(new Uri(modelDetails.Icon))
}
};

modelFlyoutItem.Click += ToolkitActionFlyoutItem_Click;
actionFlyoutItem.Items.Add(modelFlyoutItem);
}
}

AIToolkitDropdown.Visibility = isAiToolkitActionAvailable ? Visibility.Visible : Visibility.Collapsed;
}

private void ToolkitActionFlyoutItem_Click(object sender, RoutedEventArgs e)
{
if(sender is MenuFlyoutItem actionFlyoutItem)
{
(AIToolkitAction action, ModelDetails modelDetails) = ((AIToolkitAction, ModelDetails))actionFlyoutItem.Tag;

string toolkitDeeplink = modelDetails.CreateAiToolkitDeeplink(action);
bool wasDeeplinkSuccesful = true;
try
{
Process.Start(new ProcessStartInfo()
{
FileName = toolkitDeeplink,
UseShellExecute = true
});
}
catch
{
Process.Start(new ProcessStartInfo()
{
FileName = "https://learn.microsoft.com/en-us/windows/ai/toolkit/",
UseShellExecute = true
});
wasDeeplinkSuccesful = false;
}
finally
{
AIToolkitActionClickedEvent.Log(AIToolkitHelper.AIToolkitActionInfos[action].QueryName, modelDetails.Name, wasDeeplinkSuccesful);
}
}
}

private void ModelSelectionControl_SelectedModelChanged(object sender, ModelDetails? modelDetails)
{
// if we don't have a modelType, we are in a user added language model, use same samples as Phi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"Icon": "Microsoft.svg",
"ParameterSize": "3.8B",
"PromptTemplate": "Phi3",
"License": "mit"
"License": "mit",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "Phi-4-mini-gpu-int4-rtn-block-32"
},
"Phi4MiniCPU": {
"Id": "69252aa6-0138-4bc0-b2d3-ef8d72f5380e",
Expand All @@ -34,7 +36,9 @@
"Icon": "Microsoft.svg",
"ParameterSize": "3.8B",
"PromptTemplate": "Phi3",
"License": "mit"
"License": "mit",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "Phi-4-mini-cpu-int4-rtn-block-32-acc-level-4-onnx"
}
},
"ReadmeUrl": "https://huggingface.co/microsoft/Phi-4-mini-instruct-onnx/blob/main/README.md"
Expand All @@ -55,7 +59,9 @@
"Icon": "Microsoft.svg",
"ParameterSize": "3.8B",
"PromptTemplate": "Phi3",
"License": "mit"
"License": "mit",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "Phi-3.5-mini-cpu-int4-awq-block-128-acc-level-4-onnx"
}
},
"ReadmeUrl": "https://huggingface.co/microsoft/Phi-3.5-mini-instruct-onnx/blob/main/README.md"
Expand All @@ -76,7 +82,9 @@
"Icon": "Microsoft.svg",
"ParameterSize": "3.8B",
"PromptTemplate": "Phi3",
"License": "mit"
"License": "mit",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "Phi-3-mini-4k-directml-int4-awq-block-128-onnx"
},
"Phi3MiniCPU": {
"Id": "69252aa6-0137-4bc0-b2d3-ef8d72f5380e",
Expand All @@ -88,7 +96,9 @@
"Icon": "Microsoft.svg",
"ParameterSize": "3.8B",
"PromptTemplate": "Phi3",
"License": "mit"
"License": "mit",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "Phi-3-mini-4k-cpu-int4-rtn-block-32-onnx"
},
"Phi3MiniCPUACC4": {
"Id": "f4eba19c-b93f-4a4b-b003-0cfd1322ebad",
Expand All @@ -100,7 +110,9 @@
"Icon": "Microsoft.svg",
"ParameterSize": "3.8B",
"PromptTemplate": "Phi3",
"License": "mit"
"License": "mit",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "Phi-3-mini-4k-cpu-int4-rtn-block-32-acc-level-4-onnx"
}
},
"ReadmeUrl": "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/blob/main/README.md"
Expand Down Expand Up @@ -154,7 +166,9 @@
"Icon": "Mistral.svg",
"ParameterSize": "7B",
"PromptTemplate": "Mistral",
"License": "apache-2.0"
"License": "apache-2.0",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "mistral-7b-v02-int4-directml"
},
"Mistral7BInstruct02CPU": {
"Id": "4e01634b-1c52-4e59-9f0f-0994a0730548",
Expand All @@ -178,7 +192,9 @@
"Icon": "Mistral.svg",
"ParameterSize": "7B",
"PromptTemplate": "Mistral",
"License": "apache-2.0"
"License": "apache-2.0",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "mistral-7b-v02-int4-cpu"
}
},
"ReadmeUrl": "https://huggingface.co/microsoft/mistral-7b-instruct-v0.2-ONNX/blob/main/README.md"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"Size": 3220615084,
"Icon": "Microsoft.svg",
"ParameterSize": "4.2B",
"License": "mit"
"License": "mit",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "Phi-3-vision-128k-cpu-int4-rtn-block-32-acc-level-4-onnx"
}
},
"ReadmeUrl": "https://huggingface.co/microsoft/Phi-3-vision-128k-instruct-onnx/blob/main/README.md"
Expand All @@ -40,7 +42,9 @@
"Size": 3220612860,
"Icon": "Microsoft.svg",
"ParameterSize": "4.2B",
"License": "mit"
"License": "mit",
"AIToolkitActions": [ "BulkRun", "Playground", "PromptBuilder" ],
"AIToolkitId": "Phi-3.5-vision-cpu-int4-rtn-block-32-acc-level-4-onnx"
}
},
"ReadmeUrl": "https://huggingface.co/microsoft/Phi-3-vision-128k-instruct-onnx/blob/main/README.md"
Expand Down
Loading