2023-06-11 23:46:02 +00:00
|
|
|
using BotSharp.Abstraction.Agents;
|
2023-06-03 02:07:30 +00:00
|
|
|
using BotSharp.Abstraction.Conversations;
|
2023-06-11 23:46:02 +00:00
|
|
|
using BotSharp.Abstraction.Users;
|
|
|
|
|
using BotSharp.Core.Agents.Services;
|
2023-06-12 13:28:49 +00:00
|
|
|
using BotSharp.Core.Conversations.Services;
|
2023-06-11 23:46:02 +00:00
|
|
|
using BotSharp.Core.Users.Services;
|
|
|
|
|
using BotSharp.Plugins.LLamaSharp;
|
2023-05-27 01:58:31 +00:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
2023-06-03 02:07:30 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2023-05-27 01:58:31 +00:00
|
|
|
|
|
|
|
|
namespace BotSharp.Core;
|
|
|
|
|
|
|
|
|
|
public static class BotSharpServiceCollectionExtensions
|
|
|
|
|
{
|
2023-06-03 14:57:08 +00:00
|
|
|
public static IServiceCollection AddBotSharp(this IServiceCollection services, IConfiguration config)
|
2023-05-27 01:58:31 +00:00
|
|
|
{
|
2023-06-11 23:46:02 +00:00
|
|
|
services.AddScoped<ICurrentUser, CurrentUser>();
|
|
|
|
|
services.AddScoped<IUserService, UserService>();
|
|
|
|
|
services.AddScoped<IAgentService, AgentService>();
|
2023-06-12 13:28:49 +00:00
|
|
|
services.AddScoped<ISessionService, SessionService>();
|
|
|
|
|
services.AddScoped<IConversationService, ConversationService>();
|
2023-06-03 02:07:30 +00:00
|
|
|
|
2023-06-03 14:57:08 +00:00
|
|
|
RegisterRepository(services, config);
|
2023-06-10 02:56:04 +00:00
|
|
|
|
|
|
|
|
RegisterPlugins(services, config);
|
|
|
|
|
|
2023-05-27 01:58:31 +00:00
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ConfigureBotSharp(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IApplicationBuilder UseBotSharp(this IApplicationBuilder app)
|
|
|
|
|
{
|
|
|
|
|
if (app == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(app));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|
}
|
2023-06-03 02:07:30 +00:00
|
|
|
|
2023-06-03 14:57:08 +00:00
|
|
|
public static void RegisterRepository(IServiceCollection services, IConfiguration config)
|
2023-06-03 02:07:30 +00:00
|
|
|
{
|
|
|
|
|
var databaseSettings = new DatabaseSettings();
|
|
|
|
|
config.Bind("Database", databaseSettings);
|
|
|
|
|
services.AddSingleton((IServiceProvider x) =>
|
|
|
|
|
{
|
|
|
|
|
return databaseSettings;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var myDatabaseSettings = new MyDatabaseSettings();
|
|
|
|
|
config.Bind("Database", myDatabaseSettings);
|
|
|
|
|
services.AddSingleton((IServiceProvider x) =>
|
|
|
|
|
{
|
|
|
|
|
return databaseSettings;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
services.AddScoped((IServiceProvider x) =>
|
|
|
|
|
{
|
|
|
|
|
return DataContextHelper.GetDbContext<MongoDbContext>(myDatabaseSettings, x);
|
|
|
|
|
});
|
2023-06-07 00:59:32 +00:00
|
|
|
|
2023-06-11 23:46:02 +00:00
|
|
|
services.AddScoped((IServiceProvider x) =>
|
2023-06-07 00:59:32 +00:00
|
|
|
{
|
2023-06-11 23:46:02 +00:00
|
|
|
return DataContextHelper.GetDbContext<AgentDbContext>(myDatabaseSettings, x);
|
2023-06-07 00:59:32 +00:00
|
|
|
});
|
2023-06-03 02:07:30 +00:00
|
|
|
}
|
2023-06-10 02:56:04 +00:00
|
|
|
|
|
|
|
|
public static void RegisterPlugins(IServiceCollection services, IConfiguration config)
|
|
|
|
|
{
|
2023-06-11 23:46:02 +00:00
|
|
|
var settings = new LlamaSharpSettings();
|
|
|
|
|
config.Bind("LlamaSharp", settings);
|
|
|
|
|
services.AddSingleton(x =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// services.AddSingleton<IChatCompletionProvider, ChatCompletionProvider>();
|
2023-06-10 02:56:04 +00:00
|
|
|
}
|
2023-05-27 01:58:31 +00:00
|
|
|
}
|