-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (46 loc) · 1.73 KB
/
Program.cs
File metadata and controls
57 lines (46 loc) · 1.73 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
using elbruno.Extensions.AI.Claude;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Hosting;
using Microsoft.Extensions.AI;
using MAF_AIWebChatApp_FoundryClaude.Components;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
// Load configuration
var config = builder.Configuration;
var endpointClaude = config["endpointClaude"] ?? throw new InvalidOperationException("Missing 'endpointClaude' configuration");
var apiKey = config["apikey"] ?? throw new InvalidOperationException("Missing 'apikey' configuration");
var deploymentName = config["deploymentName"] ?? "claude-haiku-4-5";
// Register IChatClient with Claude integration using elbruno.Extensions.AI.Claude
builder.Services.AddSingleton<IChatClient>(_ =>
{
return new AzureClaudeClient(
endpoint: new Uri(endpointClaude),
modelId: deploymentName,
apiKey: apiKey);
});
// Register AI Agent with dependency injection
builder.Services.AddSingleton<AIAgent>(sp =>
{
var logger = sp.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Configuring AI Agent with Claude model '{Model}'", deploymentName);
var chatClient = sp.GetRequiredService<IChatClient>();
return chatClient.AsAIAgent(
name: "ClaudeChat",
instructions: "You are a helpful and friendly AI assistant."
);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseAntiforgery();
app.UseStaticFiles();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();