-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathProgram.cs
More file actions
159 lines (140 loc) · 4.2 KB
/
Program.cs
File metadata and controls
159 lines (140 loc) · 4.2 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using MaIN.Core;
using MaIN.Domain.Configuration;
using MaIN.Domain.Models;
using Microsoft.FluentUI.AspNetCore.Components;
using MaIN.InferPage.Components;
using Utils = MaIN.InferPage.Utils;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddFluentUIComponents();
try
{
var modelArg = builder.Configuration["model"];
var modelPathArg = builder.Configuration["path"];
var backendArg = builder.Configuration["backend"];
if (!string.IsNullOrEmpty(modelArg))
{
Utils.Model = modelArg;
if (string.IsNullOrEmpty(modelPathArg))
{
Console.WriteLine("Error: A model path must be provided using --path when a model is specified.");
return;
}
Utils.Path = modelPathArg;
var envModelsPath = Environment.GetEnvironmentVariable("MaIN_ModelsPath");
if (string.IsNullOrEmpty(envModelsPath))
{
Console.Write("Please enter the MaIN_ModelsPath: ");
envModelsPath = Console.ReadLine();
Environment.SetEnvironmentVariable("MaIN_ModelsPath", envModelsPath);
}
}
else
{
Console.WriteLine("No model argument provided. Continuing without model configuration.");
}
if (backendArg != null)
{
var apiKeyVariable = "";
var apiName = "";
switch (backendArg.ToLower())
{
case "openai":
Utils.OpenAi = true;
apiKeyVariable = "OPENAI_API_KEY";
apiName = "OpenAI";
break;
case "gemini":
Utils.Gemini = true;
apiKeyVariable = "GEMINI_API_KEY";
apiName = "Gemini";
break;
case "deepseek":
Utils.DeepSeek = true;
apiKeyVariable = "DEEPSEEK_API_KEY";
apiName = "Deepseek";
break;
case "groqcloud":
Utils.GroqCloud = true;
apiKeyVariable = "GROQ_API_KEY";
apiName = "GroqCloud";
break;
case "anthropic":
Utils.Anthropic = true;
apiKeyVariable = "ANTHROPIC_API_KEY";
apiName = "Anthropic";
break;
}
var key = Environment.GetEnvironmentVariable(apiKeyVariable);
if (string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(apiName) && !string.IsNullOrEmpty(apiKeyVariable))
{
Console.Write($"Please enter your {apiName} API key: ");
key = Console.ReadLine();
Environment.SetEnvironmentVariable(apiKeyVariable, key);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error during parameter processing: " + ex.Message);
return;
}
if (Utils.OpenAi)
{
builder.Services.AddMaIN(builder.Configuration, settings =>
{
settings.BackendType = BackendType.OpenAi;
});
}
else if (Utils.Gemini)
{
builder.Services.AddMaIN(builder.Configuration, settings =>
{
settings.BackendType = BackendType.Gemini;
});
}
else if (Utils.DeepSeek)
{
builder.Services.AddMaIN(builder.Configuration, settings =>
{
settings.BackendType = BackendType.DeepSeek;
});
}
else if (Utils.GroqCloud)
{
builder.Services.AddMaIN(builder.Configuration, settings =>
{
settings.BackendType = BackendType.GroqCloud;
});
}
else if(Utils.Anthropic)
{
builder.Services.AddMaIN(builder.Configuration, settings =>
{
settings.BackendType = BackendType.Anthropic;
});
}
else
{
if (Utils.Path == null && !KnownModels.IsModelSupported(Utils.Model!))
{
Console.WriteLine($"Model: {Utils.Model} is not supported");
Environment.Exit(0);
}
builder.Services.AddMaIN(builder.Configuration);
}
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.Services.UseMaIN();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();