-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (58 loc) · 2.64 KB
/
Program.cs
File metadata and controls
74 lines (58 loc) · 2.64 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
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
using Leisure.Chat;
using Leisure.Configuration;
using Leisure.Storage;
using Microsoft.Agents.AspNetAuthentication;
using Microsoft.Agents.Builder;
using Microsoft.Agents.Builder.App;
using Microsoft.Agents.Hosting.AspNetCore;
using Microsoft.Agents.Storage;
using Microsoft.AspNetCore.Http.Timeouts;
using Qdrant.Client;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Add AgentApplicationOptions from appsettings section "AgentApplication".
builder.AddAgentApplicationOptions();
var llmSection = builder.Configuration.GetSection(LLMSettings.Name).Get<LLMSettings>() ?? throw new ApplicationException("LLM configuration is bad");
var vectorStoreSection = builder.Configuration.GetSection(VectorStoreSettings.Name).Get<VectorStoreSettings>() ?? throw new ApplicationException("misconfigured");
var qdrantClient = new QdrantClient(vectorStoreSection.HostName, vectorStoreSection.Port);
builder.Services.AddSingleton(qdrantClient);
builder.AddAgent<LeisureAgent>();
builder.Services.AddTransient<ILLMClientFactory, LlamaFactory>();
builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.Services.AddTransient<DataIngestJob>();
builder.Services.AddControllers();
builder.Services.AddAgentAspNetAuthentication(builder.Configuration);
builder.BindOptions<LLMSettings>(LLMSettings.Name);
builder.BindOptions<VectorStoreSettings>(VectorStoreSettings.Name);
builder.Services.AddTransient<IDataIngestJob, DataIngestJob>();
builder.Services.AddSingleton<IVectorStore, QdrantVectorStore>();
builder.Services.AddHttpClient<LlamaFactory>(client =>
{
client.BaseAddress = new Uri(llmSection.BaseUrl);
client.Timeout = TimeSpan.FromMinutes(15);
});
WebApplication app = builder.Build();
// Enable AspNet authentication and authorization
app.UseAuthentication();
app.UseAuthorization();
app.MapGet("/", () => "Microsoft Agents SDK Sample");
// This receives incoming messages from Azure Bot Service or other SDK Agents
var incomingRoute = app.MapPost("/api/messages", async (HttpRequest request, HttpResponse response, IAgentHttpAdapter adapter, IAgent agent, CancellationToken cancellationToken) =>
{
await adapter.ProcessAsync(request, response, agent, cancellationToken);
});
var updateStoreRoute = app.MapPut("/api/ingest", async (HttpRequest request, HttpResponse response, IDataIngestJob job, CancellationToken cancellationToken) =>
{
await job.Ingest();
});
if (!app.Environment.IsDevelopment())
{
incomingRoute.RequireAuthorization();
updateStoreRoute.RequireAuthorization();
}
else
{
// Hardcoded for brevity and ease of testing.
// In production, this should be set in configuration.
app.Urls.Add($"http://localhost:3978");
}
app.Run();