forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
35 lines (27 loc) · 1.48 KB
/
Program.cs
File metadata and controls
35 lines (27 loc) · 1.48 KB
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
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.AI.OpenAI;
using Microsoft.KernelMemory.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
var endpoint = Environment.GetEnvironmentVariable("AOAI_ENDPOINT")!;
var apiKey = Environment.GetEnvironmentVariable("AOAI_API_KEY")!;
var chatDeployment = Environment.GetEnvironmentVariable("AOAI_DEPLOYMENT_CHAT")!;
var embeddingDeployment = Environment.GetEnvironmentVariable("AOAI_DEPLOYMENT_EMBEDDING")!;
var config = new SemanticKernelConfig();
var tokenizer = new DefaultGPTTokenizer();
var memory = new KernelMemoryBuilder()
.WithSemanticKernelTextGenerationService(
new AzureOpenAIChatCompletionService(chatDeployment, endpoint, apiKey), config, tokenizer)
.WithSemanticKernelTextEmbeddingGenerationService(
new AzureOpenAITextEmbeddingGenerationService(embeddingDeployment, endpoint, apiKey), config, tokenizer)
.Build<MemoryServerless>();
await memory.ImportWebPageAsync("https://raw.githubusercontent.com/microsoft/kernel-memory/main/COMMUNITY.md", documentId: "doc001");
var question = "How can I join Kernel Memory's Discord?";
Console.WriteLine($"\n\nQuestion: {question}");
var answer = await memory.AskAsync(question);
Console.WriteLine($"\nAnswer: {answer.Result}");
Console.WriteLine("\n\n Sources:\n");
foreach (var x in answer.RelevantSources)
{
Console.WriteLine($" - {x.SourceName} - {x.Link} [{x.Partitions.First().LastUpdate:D}]");
}