BotSharp/src/Infrastructure/BotSharp.Core/Conversations/SessionService.cs

51 lines
1.3 KiB
C#
Raw Normal View History

2023-06-03 02:07:30 +00:00
using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Conversations.Models;
2023-06-03 14:57:08 +00:00
using BotSharp.Core.Repository;
2023-06-07 00:59:32 +00:00
using BotSharp.Core.Repository.Collections;
using EntityFrameworkCore.BootKit;
2023-06-03 14:57:08 +00:00
using Microsoft.Extensions.DependencyInjection;
2023-06-07 00:59:32 +00:00
using MongoDB.Bson;
using MongoDB.Driver;
2023-06-03 02:07:30 +00:00
namespace BotSharp.Core.Conversations;
public class SessionService : ISessionService
{
2023-06-03 14:57:08 +00:00
private readonly IServiceProvider _services;
2023-06-03 02:07:30 +00:00
2023-06-03 14:57:08 +00:00
public SessionService(IServiceProvider services)
2023-06-03 02:07:30 +00:00
{
2023-06-03 14:57:08 +00:00
_services = services;
2023-06-03 02:07:30 +00:00
}
public void DeleteSession(string sessionId)
{
throw new NotImplementedException();
}
public List<string> GetAllSessions(string userId)
{
throw new NotImplementedException();
}
2023-06-07 00:59:32 +00:00
public async Task<SessionModel> NewSession(string userId)
2023-06-03 02:07:30 +00:00
{
2023-06-03 14:57:08 +00:00
var mongo = _services.CreateScope().ServiceProvider.GetRequiredService<MongoDbContext>();
2023-06-07 00:59:32 +00:00
var record = new Conversation
{
CreatedAt = DateTime.UtcNow,
Messages = new List<MessageModel>(),
UserId = "anonymous",
Model = "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"
};
await mongo.Conversations.InsertOneAsync(record);
2023-06-03 02:07:30 +00:00
return new SessionModel
{
2023-06-07 00:59:32 +00:00
SessionId = record.Id.ToString(),
UserId = record.UserId
2023-06-03 02:07:30 +00:00
};
}
}