-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathWebPlugins.cs
47 lines (40 loc) · 1.4 KB
/
WebPlugins.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
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.SemanticKernel.Plugins.Web;
namespace Plugins;
/// <summary>
/// Sample showing how to use the Semantic Kernel web plugins correctly.
/// </summary>
public sealed class WebPlugins(ITestOutputHelper output) : BaseTest(output)
{
/// <summary>
/// Shows how to download to a temporary directory on the local machine.
/// </summary>
[Fact]
public async Task DownloadSKLogoAsync()
{
var uri = new Uri("https://raw.githubusercontent.com/microsoft/semantic-kernel/refs/heads/main/docs/images/sk_logo.png");
var folderPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
var filePath = Path.Combine(folderPath, "sk_logo.png");
try
{
Directory.CreateDirectory(folderPath);
var webFileDownload = new WebFileDownloadPlugin(this.LoggerFactory)
{
AllowedDomains = ["raw.githubusercontent.com"],
AllowedFolders = [folderPath]
};
await webFileDownload.DownloadToFileAsync(uri, filePath);
if (Path.Exists(filePath))
{
Output.WriteLine($"Successfully downloaded to {filePath}");
}
}
finally
{
if (Path.Exists(folderPath))
{
Directory.Delete(folderPath, true);
}
}
}
}