-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (64 loc) · 2.46 KB
/
Copy pathProgram.cs
File metadata and controls
78 lines (64 loc) · 2.46 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
74
75
76
77
78
using Microsoft.AspNetCore.Components.Server;
using Plaza.Components;
using Plaza.Hubs;
using Plaza.Services;
var builder = WebApplication.CreateBuilder(args);
// Register Razor components
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
// Configure LiteLLM Named HttpClient with endpoint suffix trimming and multi-auth headers
var baseUrl = builder.Configuration["LiteLLM:BaseUrl"] ?? "http://localhost:4000";
if (baseUrl.EndsWith("/chat/completions"))
{
baseUrl = baseUrl.Substring(0, baseUrl.Length - "/chat/completions".Length);
}
else if (baseUrl.EndsWith("/responses"))
{
baseUrl = baseUrl.Substring(0, baseUrl.Length - "/responses".Length);
}
if (!baseUrl.EndsWith("/"))
{
baseUrl += "/";
}
builder.Services.AddHttpClient("litellm", client =>
{
client.BaseAddress = new Uri(baseUrl);
var apiKey = builder.Configuration["LiteLLM:ApiKey"];
if (!string.IsNullOrEmpty(apiKey))
{
// Add headers for both Azure AI Foundry and standard OpenAI/LiteLLM compatibility
client.DefaultRequestHeaders.Add("api-key", apiKey);
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiKey);
}
});
// Configure custom stores and services
builder.Services.AddSingleton<IAgentStore, AgentStore>();
builder.Services.AddSingleton<IAgentSessionStore, AgentSessionStore>();
builder.Services.AddSingleton<IShareTokenStore, ShareTokenStore>();
builder.Services.AddSingleton<SessionLockManager>();
builder.Services.AddSingleton<ILiteLLMService, LiteLLMService>();
builder.Services.AddSingleton<Microsoft.Extensions.AI.IChatClient>(sp => (LiteLLMService)sp.GetRequiredService<ILiteLLMService>());
builder.Services.AddHostedService<SessionCleanupService>();
// SignalR Configuration
builder.Services.AddSignalR();
// Circuit Lifespan settings
builder.Services.Configure<CircuitOptions>(options =>
{
options.DisconnectedCircuitRetentionPeriod = TimeSpan.FromMinutes(5);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseHsts();
}
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseHttpsRedirection();
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
// Map Plaza Collaborative SignalR Hub
app.MapHub<PlazaHub>("/plazahub");
app.Run();