-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
81 lines (61 loc) · 1.8 KB
/
Copy pathProgram.cs
File metadata and controls
81 lines (61 loc) · 1.8 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
79
80
81
#pragma warning disable SKEXP0070
#pragma warning disable SKEXP0001
using Microsoft.SemanticKernel;
using SemanticKernalNewsAPI.Plugins;
using SemanticKernalNewsAPI.Services;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddOpenApi();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Logging
.ClearProviders()
.AddConsole()
.SetMinimumLevel(LogLevel.Information);
// Add CORS services
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowFrontend", policy =>
{
policy.WithOrigins("http://localhost:3000", // React default
"http://127.0.0.1:5500", // Common Live Server port
"https://your-production-domain.com")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
options.AddPolicy("AllowAll", policy =>
{
policy.WithOrigins("*")
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.Services.AddSingleton<SessionHistoryStore>();
// Configure Semantic Kernel
builder.Services.AddSingleton<Kernel>(serviceProvider =>
{
var kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.AddGoogleAIGeminiChatCompletion(
builder.Configuration["LLM:Model"],
builder.Configuration["LLM:ApiKey"]
);
var kernel = kernelBuilder.Build();
// Register the NewsPlugin
kernel.ImportPluginFromType<NewsPlugin>();
return kernel;
});
var app = builder.Build();
app.UseCors("AllowAll");
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();