-
Notifications
You must be signed in to change notification settings - Fork 313
/
Program.cs
39 lines (32 loc) · 1.48 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
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.AI.Anthropic;
using Microsoft.KernelMemory.DocumentStorage.DevTools;
using Microsoft.KernelMemory.MemoryStorage.DevTools;
var anthropicConfig = new AnthropicConfig();
var azureOpenAIEmbeddingConfig = new AzureOpenAIConfig();
new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.development.json", optional: true)
.AddJsonFile("appsettings.Development.json", optional: true)
.AddEnvironmentVariables()
.Build()
.BindSection("KernelMemory:Services:Anthropic", anthropicConfig)
.BindSection("KernelMemory:Services:AzureOpenAIEmbedding", azureOpenAIEmbeddingConfig);
var memory = new KernelMemoryBuilder()
// Generate answers using Anthropic
.WithAnthropicTextGeneration(anthropicConfig)
// Generate embeddings using Azure OpenAI
.WithAzureOpenAITextEmbeddingGeneration(azureOpenAIEmbeddingConfig)
// Persist memory on disk
.WithSimpleFileStorage(SimpleFileStorageConfig.Persistent)
.WithSimpleVectorDb(SimpleVectorDbConfig.Persistent)
.Build<MemoryServerless>();
// Import a document in memory
await memory.ImportDocumentAsync("file5-NASA-news.pdf", "file5-NASA-news.pdf");
Console.WriteLine("Document imported");
// now ask a question
var question = "What is orion?";
var answer = await memory.AskAsync(question);
Console.WriteLine($"Question: {question}");
Console.WriteLine($"Answer: {answer.Result}");