-
Notifications
You must be signed in to change notification settings - Fork 309
/
Program.cs
43 lines (36 loc) · 1.3 KB
/
Program.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
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.DataFormats.WebPages;
public class MyWebScraper : IWebScraper
{
public Task<WebScraperResult> GetContentAsync(string url, CancellationToken cancellationToken = default)
{
// Sample code
Console.WriteLine($"Processing page {url} with {nameof(MyWebScraper)}...");
// Your logic here
var content = new BinaryData("...content page here...");
// recommended: leave encoding out, include just the MIME/media type
var contentType = "text/html";
return Task.FromResult(new WebScraperResult
{
Content = content,
ContentType = contentType,
Success = true,
Error = string.Empty
});
}
}
public static class Program
{
public static async Task Main(string[] args)
{
var memory = new KernelMemoryBuilder()
// .WithCustomWebScraper<MyWebScraper>()
.WithOpenAIDefaults("no key")
.Build();
// Note: using custom "steps" to avoid LLM calls, and test just the custom web scraper
await memory.ImportWebPageAsync(
"https://raw.githubusercontent.com/microsoft/kernel-memory/main/README.md",
steps: ["extract"]);
}
}