-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (56 loc) · 2.15 KB
/
Program.cs
File metadata and controls
71 lines (56 loc) · 2.15 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
global using Microsoft.Extensions.Options;
global using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TelegramAIBot.AI.Gug;
using TelegramAIBot.AI.OpenAI;
using TelegramAIBot.Telegram;
using TelegramAIBot.UserData;
using TelegramAIBot.UserData.InMemory;
using TomLonghurst.ReadableTimeSpan;
using TelegramAIBot.AI.Abstractions;
using TelegramAIBot.RAG;
namespace TelegramAIBot
{
class Program
{
public static readonly EventId GugClientUsedLOG = new EventId(12, nameof(GugClientUsedLOG)).Form();
public static void Main(string[] args)
{
ReadableTimeSpan.EnableConfigurationBinding();
var config = new ConfigurationBuilder().AddJsonFile("config.json").Build();
var serviceCollection = new ServiceCollection()
.AddSingleton<IUserDataRepository, InMemoryUserDataRepository>()
.AddSingleton<ITelegramModule, TelegramModule>()
.AddLogging(sb => sb.AddConsole().SetMinimumLevel(LogLevel.Trace))
.Configure<TelegramClient.Configuration>(config.GetSection("Telegram"))
.AddSingleton<TelegramClient>()
.AddTransient<TextExtractor>()
.Configure<RAGProcessor.Configuration>(config.GetSection("RAG"))
.AddTransient<RAGProcessor.TextEmbeddingGenerator>(sp => async (text) => await sp.GetRequiredService<IAIClient>().CreateEmbeddingAsync("gpt-3.5-turbo", text))
.AddTransient<RAGProcessor>()
;
var isGugClientImplementationUsed = args.Contains("--useGugClient");
if (isGugClientImplementationUsed)
{
serviceCollection
.Configure<GugClient.Configuration>(config.GetSection("AI:Gug"))
.AddSingleton<IAIClient, GugClient>()
;
}
else
{
serviceCollection
.Configure<OpenAIClient.Configuration>(config.GetSection("AI:OpenAI"))
.AddSingleton<IAIClient, OpenAIClient>()
;
}
var services = serviceCollection.BuildServiceProvider();
var logger = services.GetRequiredService<ILogger<Program>>();
if (isGugClientImplementationUsed)
logger.Log(LogLevel.Information, GugClientUsedLOG, "Using gug version of ai client");
services.GetRequiredService<TelegramClient>().Start();
Thread.Sleep(-1);
}
}
}