forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
86 lines (71 loc) · 3.64 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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.Prompts;
public static class Program
{
// ReSharper disable InconsistentNaming
public static async Task Main()
{
var azureOpenAITextConfig = new AzureOpenAIConfig();
var azureOpenAIEmbeddingConfig = new AzureOpenAIConfig();
var openAIConfig = new OpenAIConfig();
var searchClientConfig = new SearchClientConfig();
new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.Development.json", optional: true)
.Build()
.BindSection("KernelMemory:Services:OpenAI", openAIConfig)
.BindSection("KernelMemory:Services:AzureOpenAIText", azureOpenAITextConfig)
.BindSection("KernelMemory:Services:AzureOpenAIEmbedding", azureOpenAIEmbeddingConfig)
.BindSection("KernelMemory:Retrieval:SearchClient", searchClientConfig);
var memory = new KernelMemoryBuilder()
.WithCustomPromptProvider(new MyPromptProvider())
// .WithOpenAIDefaults(Env.Var("OPENAI_API_KEY"))
// .WithOpenAI(openAICfg)
.WithAzureOpenAITextGeneration(azureOpenAITextConfig)
.WithAzureOpenAITextEmbeddingGeneration(azureOpenAIEmbeddingConfig)
.Build<MemoryServerless>();
await memory.ImportTextAsync("NASA space probe Lucy flies by asteroid 152830 Dinkinesh, the first of eight asteroids planned to be visited by the spacecraft.");
var statement = "Lucy flied by an asteroid";
var verification = await memory.AskAsync(statement);
Console.WriteLine($"{statement} => {verification.Result}");
statement = "Lucy landed on an asteroid";
verification = await memory.AskAsync(statement);
Console.WriteLine($"{statement} => {verification.Result}");
statement = "Lucy is powered by a nuclear engine";
verification = await memory.AskAsync(statement);
Console.WriteLine($"{statement} => {verification.Result}");
/* OUTPUT *
Lucy flied by an asteroid => TRUE
Lucy landed on an asteroid => FALSE
Lucy is powered by a nuclear engine => NEED MORE INFO
*/
}
}
public class MyPromptProvider : IPromptProvider
{
private const string VerificationPrompt = """
Facts:
{{$facts}}
======
Given only the facts above, verify the fact below.
You don't know where the knowledge comes from, just answer.
If you have sufficient information to verify, reply only with 'TRUE', nothing else.
If you have sufficient information to deny, reply only with 'FALSE', nothing else.
If you don't have sufficient information, reply with 'NEED MORE INFO'.
User: {{$input}}
Verification:
""";
private readonly EmbeddedPromptProvider _fallbackProvider = new();
public string ReadPrompt(string promptName)
{
switch (promptName)
{
case Constants.PromptNamesAnswerWithFacts:
return VerificationPrompt;
default:
// Fall back to the default
return this._fallbackProvider.ReadPrompt(promptName);
}
}
}