-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from microsoft/zt/131-smart-textbox
[SAMPLE] Smart Text Box control
- Loading branch information
Showing
6 changed files
with
552 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
AIDevGallery/Samples/Open Source Models/Language Models/SmartText.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<samples:BaseSamplePage | ||
xmlns:samples="using:AIDevGallery.Samples" | ||
x:Class="AIDevGallery.Samples.OpenSourceModels.LanguageModels.SmartText" | ||
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" | ||
xmlns:local="using:AIDevGallery.Samples.OpenSourceModels.LanguageModels" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:shared="using:AIDevGallery.Samples.SharedCode" | ||
mc:Ignorable="d"> | ||
|
||
<Grid> | ||
<shared:SmartTextBox | ||
x:Name="SmartTextBox" | ||
Text="This is the Smart Text Box control. It exposes generative AI actions through a selection flyout menu. Try it out by highlighting some text to display the menu." | ||
Margin="0,32,0,0"/> | ||
</Grid> | ||
</samples:BaseSamplePage> |
59 changes: 59 additions & 0 deletions
59
AIDevGallery/Samples/Open Source Models/Language Models/SmartText.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using AIDevGallery.Models; | ||
using AIDevGallery.Samples.Attributes; | ||
using Microsoft.Extensions.AI; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace AIDevGallery.Samples.OpenSourceModels.LanguageModels; | ||
|
||
[GallerySample( | ||
Name = "Smart Text Box", | ||
Model1Types = [ModelType.LanguageModels], | ||
Id = "6663205f-af6e-4608-a95c-03264b6cfc34", | ||
Icon = "\uE8D4", | ||
Scenario = ScenarioType.SmartControlsSmartTextBox, | ||
NugetPackageReferences = [ | ||
"Microsoft.ML.OnnxRuntimeGenAI.DirectML", | ||
"Microsoft.Extensions.AI.Abstractions" | ||
], | ||
SharedCode = [ | ||
SharedCodeEnum.SmartTextBoxCs, | ||
SharedCodeEnum.SmartTextBoxXaml, | ||
SharedCodeEnum.GenAIModel | ||
])] | ||
internal sealed partial class SmartText : BaseSamplePage | ||
{ | ||
private IChatClient? _model; | ||
|
||
public SmartText() | ||
{ | ||
this.Unloaded += (s, e) => CleanUp(); | ||
try | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
catch (Exception e) | ||
{ | ||
System.Diagnostics.Debug.WriteLine(e.Message); | ||
} | ||
} | ||
|
||
protected override async Task LoadModelAsync(SampleNavigationParameters sampleParams) | ||
{ | ||
_model = await sampleParams.GetIChatClientAsync(); | ||
if (_model != null) | ||
{ | ||
this.SmartTextBox.ChatClient = _model; | ||
} | ||
|
||
sampleParams.NotifyCompletion(); | ||
} | ||
|
||
private void CleanUp() | ||
{ | ||
_model?.Dispose(); | ||
} | ||
} |
Oops, something went wrong.