temp save

This commit is contained in:
Jicheng Lu 2023-09-01 17:33:36 -05:00
parent 6330335b5d
commit 4e3708e525
20 changed files with 73 additions and 71 deletions

View file

@ -55,7 +55,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.RoutingSpee
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DataStorages", "DataStorages", "{5CD330E1-9E5A-4112-8346-6E31CA98EF78}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.MongoStorage", "src\Plugins\BotSharp.Plugin.MongoRepository\BotSharp.Plugin.MongoStorage.csproj", "{5AEB21CB-02C1-4678-91FA-554EC55E9467}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.MongoStorage", "src\Plugins\BotSharp.Plugin.MongoStorage\BotSharp.Plugin.MongoStorage.csproj", "{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -193,14 +193,14 @@ Global
{631D9C12-86C4-44F0-99C3-D32C0754BF37}.Release|Any CPU.Build.0 = Release|Any CPU
{631D9C12-86C4-44F0-99C3-D32C0754BF37}.Release|x64.ActiveCfg = Release|Any CPU
{631D9C12-86C4-44F0-99C3-D32C0754BF37}.Release|x64.Build.0 = Release|Any CPU
{5AEB21CB-02C1-4678-91FA-554EC55E9467}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5AEB21CB-02C1-4678-91FA-554EC55E9467}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5AEB21CB-02C1-4678-91FA-554EC55E9467}.Debug|x64.ActiveCfg = Debug|Any CPU
{5AEB21CB-02C1-4678-91FA-554EC55E9467}.Debug|x64.Build.0 = Debug|Any CPU
{5AEB21CB-02C1-4678-91FA-554EC55E9467}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5AEB21CB-02C1-4678-91FA-554EC55E9467}.Release|Any CPU.Build.0 = Release|Any CPU
{5AEB21CB-02C1-4678-91FA-554EC55E9467}.Release|x64.ActiveCfg = Release|Any CPU
{5AEB21CB-02C1-4678-91FA-554EC55E9467}.Release|x64.Build.0 = Release|Any CPU
{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}.Debug|x64.ActiveCfg = Debug|Any CPU
{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}.Debug|x64.Build.0 = Debug|Any CPU
{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}.Release|Any CPU.Build.0 = Release|Any CPU
{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}.Release|x64.ActiveCfg = Release|Any CPU
{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -228,7 +228,7 @@ Global
{51AFE054-AE99-497D-A593-69BAEFB5106F} = {2635EC9B-2E5F-4313-AC21-0B847F31F36C}
{631D9C12-86C4-44F0-99C3-D32C0754BF37} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
{5CD330E1-9E5A-4112-8346-6E31CA98EF78} = {2635EC9B-2E5F-4313-AC21-0B847F31F36C}
{5AEB21CB-02C1-4678-91FA-554EC55E9467} = {5CD330E1-9E5A-4112-8346-6E31CA98EF78}
{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C} = {5CD330E1-9E5A-4112-8346-6E31CA98EF78}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

View file

@ -1,6 +1,6 @@
namespace BotSharp.Abstraction.Repositories;
public class MyDatabaseSettings : DatabaseSettings
public class BotSharpDatabaseSettings : DatabaseBasicSettings
{
public string[] Assemblies { get; set; }
public string FileRepository { get; set; }
@ -8,7 +8,7 @@ public class MyDatabaseSettings : DatabaseSettings
public DbConnectionSetting BotSharp { get; set; }
}
public class DatabaseSettings
public class DatabaseBasicSettings
{
public string Default { get; set; }
public DbConnectionSetting DefaultConnection { get; set; }
@ -21,7 +21,6 @@ public class DatabaseSettings
public class DbConnectionSetting
{
public string Master { get; set; }
public string[] Slavers { get; set; }
public DbConnectionSetting()

View file

@ -24,13 +24,13 @@ public partial class AgentService : IAgentService
public string GetDataDir()
{
var dbSettings = _services.GetRequiredService<MyDatabaseSettings>();
var dbSettings = _services.GetRequiredService<BotSharpDatabaseSettings>();
return Path.Combine(dbSettings.FileRepository);
}
public string GetAgentDataDir(string agentId)
{
var dbSettings = _services.GetRequiredService<MyDatabaseSettings>();
var dbSettings = _services.GetRequiredService<BotSharpDatabaseSettings>();
var dir = Path.Combine(dbSettings.FileRepository, _settings.DataDir, agentId);
if (!Directory.Exists(dir))
{

View file

@ -33,11 +33,11 @@ public static class BotSharpServiceCollectionExtensions
services.AddScoped<IConversationService, ConversationService>();
services.AddScoped<IConversationStateService, ConversationStateService>();
var databaseSettings = new DatabaseSettings();
var databaseSettings = new DatabaseBasicSettings();
config.Bind("Database", databaseSettings);
services.AddSingleton((IServiceProvider x) => databaseSettings);
var myDatabaseSettings = new MyDatabaseSettings();
var myDatabaseSettings = new BotSharpDatabaseSettings();
config.Bind("Database", myDatabaseSettings);
services.AddSingleton((IServiceProvider x) => myDatabaseSettings);
@ -72,7 +72,7 @@ public static class BotSharpServiceCollectionExtensions
{
services.AddScoped<IBotSharpRepository>(sp =>
{
var myDatabaseSettings = sp.GetRequiredService<MyDatabaseSettings>();
var myDatabaseSettings = sp.GetRequiredService<BotSharpDatabaseSettings>();
return DataContextHelper.GetDbContext<BotSharpDbContext, DbContext4SqlServer>(myDatabaseSettings, sp);
});
@ -83,7 +83,7 @@ public static class BotSharpServiceCollectionExtensions
{
services.AddScoped<IBotSharpRepository>(sp =>
{
var myDatabaseSettings = sp.GetRequiredService<MyDatabaseSettings>();
var myDatabaseSettings = sp.GetRequiredService<BotSharpDatabaseSettings>();
return new FileRepository(myDatabaseSettings, sp);
});

View file

@ -17,13 +17,13 @@ public class ConversationStateService : IConversationStateService, IDisposable
private readonly IUserIdentity _user;
private readonly IBotSharpRepository _db;
private ConversationState _state;
private MyDatabaseSettings _dbSettings;
private BotSharpDatabaseSettings _dbSettings;
private string _conversationId;
private string _file;
public ConversationStateService(ILogger<ConversationStateService> logger,
IServiceProvider services,
MyDatabaseSettings dbSettings,
BotSharpDatabaseSettings dbSettings,
AgentSettings agentSettings,
IUserIdentity user,
IBotSharpRepository db)
@ -66,12 +66,14 @@ public class ConversationStateService : IConversationStateService, IDisposable
_state = new ConversationState();
_file = GetConversationState(_conversationId);
_file = GetStorageFile(_conversationId);
//_file = GetConversationState(_conversationId);
if (_file != null)
{
//var dict = File.ReadAllLines(_file);
var dict = _file.SplitByNewLine();
var dict = File.ReadAllLines(_file);
//var dict = _file.SplitByNewLine();
foreach (var line in dict)
{
_state[line.Split('=')[0]] = line.Split('=')[1];
@ -144,7 +146,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
var record = new ConversationRecord()
{
Id = ObjectId.GenerateNewId().ToString(),
AgentId = _agentSettings.RouterId,
//AgentId = _agentSettings.RouterId,
UserId = user?.Id ?? ObjectId.GenerateNewId().ToString(),
Title = "New Conversation",
Dialog = string.Empty,

View file

@ -11,12 +11,12 @@ namespace BotSharp.Core.Conversations.Services;
public class ConversationStorage : IConversationStorage
{
private readonly MyDatabaseSettings _dbSettings;
private readonly BotSharpDatabaseSettings _dbSettings;
private readonly AgentSettings _agentSettings;
private readonly IServiceProvider _services;
private readonly IUserIdentity _user;
public ConversationStorage(
MyDatabaseSettings dbSettings,
BotSharpDatabaseSettings dbSettings,
AgentSettings agentSettings,
IServiceProvider services,
IUserIdentity user)
@ -73,8 +73,11 @@ public class ConversationStorage : IConversationStorage
public List<RoleDialogModel> GetDialogs(string conversationId)
{
var conversationFile = GetConversationDialogs(conversationId);
var dialogs = conversationFile.SplitByNewLine();
var conversationFile = GetStorageFile(conversationId);
var dialogs = File.ReadAllLines(conversationFile);
//var conversationFile = GetConversationDialogs(conversationId);
//var dialogs = conversationFile.SplitByNewLine();
var results = new List<RoleDialogModel>();
for (int i = 0; i < dialogs.Length; i += 2)
@ -102,13 +105,13 @@ public class ConversationStorage : IConversationStorage
public void InitStorage(string conversationId)
{
//var file = GetStorageFile(conversationId);
//if (!File.Exists(file))
//{
// File.WriteAllLines(file, new string[0]);
//}
var file = GetStorageFile(conversationId);
if (!File.Exists(file))
{
File.WriteAllLines(file, new string[0]);
}
GetConversationDialogs(conversationId);
//GetConversationDialogs(conversationId);
}
private string GetStorageFile(string conversationId)
@ -131,7 +134,7 @@ public class ConversationStorage : IConversationStorage
var record = new ConversationRecord()
{
Id = ObjectId.GenerateNewId().ToString(),
AgentId = _agentSettings.RouterId,
//AgentId = _agentSettings.RouterId,
UserId = user?.Id ?? ObjectId.GenerateNewId().ToString(),
Title = "New Conversation"
};

View file

@ -7,7 +7,7 @@ namespace BotSharp.Core.Repository;
public static class DataContextHelper
{
public static T GetDbContext<T, Tdb>(MyDatabaseSettings settings, IServiceProvider serviceProvider)
public static T GetDbContext<T, Tdb>(BotSharpDatabaseSettings settings, IServiceProvider serviceProvider)
where T : Database, new()
where Tdb : DataContext
{

View file

@ -7,11 +7,11 @@ namespace BotSharp.Core.Repository;
public class FileRepository : IBotSharpRepository
{
private readonly MyDatabaseSettings _dbSettings;
private readonly BotSharpDatabaseSettings _dbSettings;
private readonly IServiceProvider _services;
private JsonSerializerOptions _options;
public FileRepository(MyDatabaseSettings dbSettings, IServiceProvider services)
public FileRepository(BotSharpDatabaseSettings dbSettings, IServiceProvider services)
{
_dbSettings = dbSettings;
_services = services;

View file

@ -32,7 +32,7 @@ public class Router : IAgentRouting
public RoutingRecord[] GetRoutingRecords()
{
var agentSettings = _services.GetRequiredService<AgentSettings>();
var dbSettings = _services.GetRequiredService<MyDatabaseSettings>();
var dbSettings = _services.GetRequiredService<BotSharpDatabaseSettings>();
var filePath = Path.Combine(dbSettings.FileRepository, agentSettings.DataDir, _settings.RouterId, "route.json");
var records = JsonSerializer.Deserialize<RoutingRecord[]>(File.ReadAllText(filePath));

View file

@ -1,4 +1,4 @@
namespace BotSharp.Plugin.Mongo.Collections;
namespace BotSharp.Plugin.MongoStorage.Collections;
public class AgentCollection : MongoBase
{

View file

@ -1,4 +1,4 @@
namespace BotSharp.Plugin.Mongo.Collections;
namespace BotSharp.Plugin.MongoStorage.Collections;
public class ConversationCollection : MongoBase
{

View file

@ -1,4 +1,4 @@
namespace BotSharp.Plugin.Mongo.Collections;
namespace BotSharp.Plugin.MongoStorage.Collections;
public class UserAgentCollection : MongoBase
{

View file

@ -1,4 +1,4 @@
namespace BotSharp.Plugin.Mongo.Collections;
namespace BotSharp.Plugin.MongoStorage.Collections;
public class UserCollection : MongoBase
{
@ -7,7 +7,7 @@ public class UserCollection : MongoBase
public string Email { get; set; }
public string Salt { get; set; }
public string Password { get; set; }
public string? ExternalId { get; set; }
public string ExternalId { get; set; }
public DateTime CreatedTime { get; set; }
public DateTime UpdatedTime { get; set; }

View file

@ -1,7 +1,7 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.IdGenerators;
namespace BotSharp.Plugin.Mongo;
namespace BotSharp.Plugin.MongoStorage;
[BsonIgnoreExtraElements(Inherited = true)]
public class MongoBase

View file

@ -1,6 +1,6 @@
using BotSharp.Plugin.Mongo.Collections;
using BotSharp.Plugin.MongoStorage.Collections;
namespace BotSharp.Plugin.Mongo;
namespace BotSharp.Plugin.MongoStorage;
public class MongoDbContext
{

View file

@ -1,17 +0,0 @@
using BotSharp.Plugin.Mongo.Repository;
namespace BotSharp.Plugin.Mongo;
public class MongoRepositoryPlugin : IBotSharpPlugin
{
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
services.AddSingleton((IServiceProvider x) =>
{
var databaseSettings = x.GetRequiredService<MyDatabaseSettings>();
return new MongoDbContext(databaseSettings.MongoDb);
});
services.AddScoped<IBotSharpRepository, MongoRepository>();
}
}

View file

@ -0,0 +1,17 @@
using BotSharp.Plugin.MongoStorage.Repository;
namespace BotSharp.Plugin.MongoStorage;
public class MongoStoragePlugin : IBotSharpPlugin
{
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
//services.AddScoped((IServiceProvider x) =>
//{
// var dbSettings = x.GetRequiredService<BotSharpDatabaseSettings>();
// return new MongoDbContext(dbSettings.MongoDb);
//});
//services.AddScoped<IBotSharpRepository, MongoRepository>();
}
}

View file

@ -1,6 +1,6 @@
using BotSharp.Plugin.Mongo.Collections;
using BotSharp.Plugin.MongoStorage.Collections;
namespace BotSharp.Plugin.Mongo.Repository;
namespace BotSharp.Plugin.MongoStorage.Repository;
public class MongoRepository : IBotSharpRepository
{

View file

@ -42,7 +42,7 @@
<ProjectReference Include="..\Plugins\BotSharp.Plugin.HuggingFace\BotSharp.Plugin.HuggingFace.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.LLamaSharp\BotSharp.Plugin.LLamaSharp.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.MetaAI\BotSharp.Plugin.MetaAI.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.MongoRepository\BotSharp.Plugin.MongoStorage.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.MongoStorage\BotSharp.Plugin.MongoStorage.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.PaddleSharp\BotSharp.Plugin.PaddleSharp.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.Qdrant\BotSharp.Plugin.Qdrant.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.RoutingSpeeder\BotSharp.Plugin.RoutingSpeeder.csproj" />

View file

@ -65,9 +65,7 @@
"Database": {
"Default": "FileRepository",
"MongoDb": {
"Master": "mongodb://localhost:27017/chat-ui"
},
"MongoDb": "",
"BotSharp": {
"Master": "Data Source=(localdb)\\ProjectModels;Initial Catalog=BotSharp;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False",
"Slavers": []