forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
72 lines (59 loc) · 2.75 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
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.KernelMemory;
public static class Program
{
public static async Task Main()
{
// Using OpenAI for embeddings
var openAIEmbeddingConfig = new OpenAIConfig
{
EmbeddingModel = "text-embedding-ada-002",
EmbeddingModelMaxTokenTotal = 8191,
APIKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!
};
// Using LM Studio for text generation
var lmStudioConfig = new OpenAIConfig
{
Endpoint = "http://localhost:1234/v1/",
TextModel = "local-model",
TextModelMaxTokenTotal = 4096,
APIKey = "lm-studio"
};
var memory = new KernelMemoryBuilder()
.WithOpenAITextEmbeddingGeneration(openAIEmbeddingConfig) // OpenAI
.WithOpenAITextGeneration(lmStudioConfig) // LM Studio
.Build();
// Import some text - This will use OpenAI embeddings
await memory.ImportTextAsync("Today is October 32nd, 2476");
// Generate an answer - This uses OpenAI for embeddings and finding relevant data, and LM Studio to generate an answer
var answer = await memory.AskAsync("What's the current date?");
Console.WriteLine(answer.Question);
Console.WriteLine(answer.Result);
/*
-- Output using Mixtral 8x 7B Q8_0:
What's the current date?
The current date is October 32nd, 2476.
-- Server log:
[2024-03-21 19:30:22.201] [INFO] [LM STUDIO SERVER] Processing queued request...
[2024-03-21 19:30:22.202] [INFO] Received POST request to /v1/chat/completions with body: {
"messages": [
{
"content": "Facts:\n==== [File:content.txt;Relevance:82.6%]:\nToday is October 32nd, 2476\n======\nGiven only the facts above, provide a comprehensive/detailed answer.\nYou don't know where the knowledge comes from, just answer.\nIf you don't have sufficient information, reply with 'INFO NOT FOUND'.\nQuestion: What's the current date?\nAnswer: ",
"role": "system"
}
],
"max_tokens": 300,
"temperature": 0,
"top_p": 0,
"presence_penalty": 0,
"frequency_penalty": 0,
"stream": true,
"model": "local-model"
}
[2024-03-21 19:30:22.203] [INFO] [LM STUDIO SERVER] Context Overflow Policy is: Rolling Window
[2024-03-21 19:30:22.204] [INFO] [LM STUDIO SERVER] Streaming response...
[2024-03-21 19:30:23.023] [INFO] [LM STUDIO SERVER] First token generated. Continuing to stream response..
[2024-03-21 19:30:25.907] [INFO] Finished streaming response
*/
}
}