forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
32 lines (24 loc) · 1.05 KB
/
Copy pathProgram.cs
File metadata and controls
32 lines (24 loc) · 1.05 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
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.KernelMemory;
/* The following code shows how to create a custom handler, attached
* to a queue and listening for work to do. You can also add multiple handlers
* the same way.
*/
// Usual .NET web app builder
var appBuilder = WebApplication.CreateBuilder();
/* ... setup your handler dependencies ... */
// builder.Services.AddSingleton...
// builder.Services.AddTransient...
// Define the handlers to host
appBuilder.Services.AddHandlerAsHostedService<MyHandler>("mypipelinestep");
// builder.Services.AddHandlerAsHostedService<MyHandler2>("mypipelinestep-2");
// builder.Services.AddHandlerAsHostedService<MyHandler3>("mypipelinestep-3");
// Build the memory instance injecting its dependencies into the current app
var _ = new KernelMemoryBuilder(appBuilder.Services)
.WithOpenAIDefaults(Env.Var("OPENAI_API_KEY"))
.Build();
// Build and run .NET web app as usual
Console.WriteLine("Starting service...");
var app = appBuilder.Build();
app.Run();
Console.WriteLine("Service stopped");