Skip to content

Commit

Permalink
Merge pull request #135 from microsoft/zt/131-smart-textbox
Browse files Browse the repository at this point in the history
[SAMPLE] Smart Text Box control
  • Loading branch information
nmetulev authored Jan 30, 2025
2 parents 9404f62 + fa77008 commit 459e3f4
Show file tree
Hide file tree
Showing 6 changed files with 552 additions and 1 deletion.
2 changes: 1 addition & 1 deletion AIDevGallery/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<ResourceDictionary Source="/Styles/SelectorBar.xaml" />
<ResourceDictionary Source="/Controls/CopyButton/CopyButton.xaml" />
<ResourceDictionary Source="/Controls/HomePage/Header/HeaderTile/HeaderTile.xaml" />
<!--<ResourceDictionary Source="/Controls/OpacityMaskView/RedirectVisualView.xaml" />-->
<ResourceDictionary Source="/Samples/SharedCode/SemanticComboBox.xaml" />
<ResourceDictionary Source="/Samples/SharedCode/SmartPasteForm.xaml" />
<ResourceDictionary Source="/Samples/SharedCode/SmartTextBox.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->

Expand Down
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>
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();
}
}
Loading

0 comments on commit 459e3f4

Please sign in to comment.