-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathSmartPaste.xaml.cs
69 lines (60 loc) · 1.67 KB
/
SmartPaste.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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.Collections.Generic;
using System.Threading.Tasks;
namespace AIDevGallery.Samples.OpenSourceModels.LanguageModels;
[GallerySample(
Name = "Smart Paste",
Model1Types = [ModelType.LanguageModels, ModelType.PhiSilica],
Id = "cdd824f9-2472-4aac-bce9-f2b06f7e6b14",
Icon = "\uE8D4",
Scenario = ScenarioType.SmartControlsSmartPaste,
NugetPackageReferences = [
"CommunityToolkit.Mvvm",
"Microsoft.Extensions.AI"
],
SharedCode = [
SharedCodeEnum.SmartPasteFormCs,
SharedCodeEnum.SmartPasteFormXaml
])]
internal sealed partial class SmartPaste : BaseSamplePage
{
private IChatClient? model;
public List<string> FieldLabels { get; set; } = ["Name", "Address", "City", "State", "Zip"];
public SmartPaste()
{
this.Unloaded += (s, e) => CleanUp();
try
{
this.InitializeComponent();
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
}
protected override async Task LoadModelAsync(SampleNavigationParameters sampleParams)
{
try
{
model = await sampleParams.GetIChatClientAsync();
}
catch (Exception ex)
{
ShowException(ex);
}
if (model != null)
{
this.SmartForm.Model = model;
}
sampleParams.NotifyCompletion();
}
private void CleanUp()
{
model?.Dispose();
}
}