-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (53 loc) · 2.52 KB
/
Copy pathProgram.cs
File metadata and controls
65 lines (53 loc) · 2.52 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
using Faxtract.Hubs;
using Faxtract.Interfaces;
using Faxtract.Models;
using Faxtract.Services;
using LLama.Native;
namespace Faxtract;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddUserSecrets<Program>(optional: true);
// If you set an environment variable LLAMA_PRESET (e.g. via launch profile),
// load appsettings.<preset>.json on top of appsettings.json so it can override values.
var preset = Environment.GetEnvironmentVariable("LLAMA_PRESET")
?? builder.Configuration["LLAMA_PRESET"];
if (!string.IsNullOrEmpty(preset))
{
// Allow only safe filename characters to avoid path traversal.
var safe = new string([.. preset.Where(c => char.IsLetterOrDigit(c) || c == '-' || c == '_' || c == '.')]);
var presetFile = $"appsettings.{safe}.json";
builder.Configuration.AddJsonFile(presetFile, optional: true, reloadOnChange: true);
}
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddSignalR();
builder.Services.AddSingleton<IWorkProvider, MemoryWorkProvider>();
builder.Services.AddSingleton<WorkProcessor>();
builder.Services.AddSingleton<LlamaExecutor>();
builder.Services.AddSingleton<StorageService>();
builder.Services.AddHostedService(sp => sp.GetRequiredService<WorkProcessor>());
NativeLibraryConfig.All
.WithVulkan(builder.Configuration.GetValue<bool>("LLamaConfig:AllowVulkan"))
.WithCuda(builder.Configuration.GetValue<bool>("LLamaConfig:AllowCuda"));
var app = builder.Build();
// Delete the state file if present, in case the model has changed.
File.Delete(Path.Join(AppContext.BaseDirectory, app.Configuration["PrePromptFile"] ?? "preprompt.state"));
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllers();
app.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapHub<WorkHub>("/workhub");
app.Run();
}
}