Skip to content

Commit 5f27c9c

Browse files
authored
Merge pull request #119 from iceljc/features/add-mongo-implementation
Features/add mongo implementation
2 parents e83aa5c + 43d7d8b commit 5f27c9c

File tree

81 files changed

+2161
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2161
-533
lines changed

BotSharp.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RAGs", "RAGs", "{4F346DCE-0
5757
EndProject
5858
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.KnowledgeBase", "src\Plugins\BotSharp.Plugin.KnowledgeBase\BotSharp.Plugin.KnowledgeBase.csproj", "{298AC787-A104-414C-B114-82BE764FBD9C}"
5959
EndProject
60+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DataStorages", "DataStorages", "{5CD330E1-9E5A-4112-8346-6E31CA98EF78}"
61+
EndProject
62+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.MongoStorage", "src\Plugins\BotSharp.Plugin.MongoStorage\BotSharp.Plugin.MongoStorage.csproj", "{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}"
63+
EndProject
6064
Global
6165
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6266
Debug|Any CPU = Debug|Any CPU

src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public virtual bool OnInstructionLoaded(string template, Dictionary<string, obje
3434
return true;
3535
}
3636

37-
public virtual bool OnFunctionsLoaded(ref string functions)
37+
public virtual bool OnFunctionsLoaded(ref List<string> functions)
3838
{
3939
_agent.Functions = functions;
4040
return true;

src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IAgentHook
1515

1616
bool OnInstructionLoaded(string template, Dictionary<string, object> dict);
1717

18-
bool OnFunctionsLoaded(ref string functions);
18+
bool OnFunctionsLoaded(ref List<string> functions);
1919

2020
bool OnSamplesLoaded(ref string samples);
2121

src/Infrastructure/BotSharp.Abstraction/Agents/IAgentRouting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public interface IAgentRouting
66
{
77
string AgentId { get; }
88
Task<Agent> LoadRouter();
9-
RoutingRecord[] GetRoutingRecords();
10-
RoutingRecord GetRecordByName(string name);
9+
RoutingItem[] GetRoutingRecords();
10+
RoutingItem GetRecordByName(string name);
1111
}

src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class Agent
44
{
55
public string Id { get; set; } = string.Empty;
66
public string Name { get; set; } = string.Empty;
7-
public string? Description { get; set; }
7+
public string Description { get; set; }
88
public DateTime CreatedDateTime { get; set; }
99
public DateTime UpdatedDateTime { get; set; }
1010

@@ -21,13 +21,81 @@ public class Agent
2121
/// <summary>
2222
/// Functions
2323
/// </summary>
24-
public string Functions { get; set; }
24+
public List<string> Functions { get; set; }
25+
26+
/// <summary>
27+
/// Responses
28+
/// </summary>
29+
public List<string> Responses { get; set; }
2530

2631
/// <summary>
2732
/// Domain knowledges
2833
/// </summary>
2934
public string Knowledges { get; set; }
3035

36+
public bool IsPublic { get; set; }
37+
3138
public override string ToString()
3239
=> $"{Name} {Id}";
40+
41+
42+
public static Agent Clone(Agent agent)
43+
{
44+
return new Agent
45+
{
46+
Id = agent.Id,
47+
Name = agent.Name,
48+
Description = agent.Description,
49+
Instruction = agent.Instruction,
50+
Functions = agent.Functions,
51+
Responses = agent.Responses,
52+
Samples = agent.Samples,
53+
Knowledges = agent.Knowledges,
54+
IsPublic = agent.IsPublic,
55+
CreatedDateTime = agent.CreatedDateTime,
56+
UpdatedDateTime = agent.UpdatedDateTime,
57+
};
58+
}
59+
60+
public Agent SetInstruction(string instruction)
61+
{
62+
Instruction = instruction;
63+
return this;
64+
}
65+
66+
public Agent SetFunctions(List<string> functions)
67+
{
68+
Functions = functions ?? new List<string>();
69+
return this;
70+
}
71+
72+
public Agent SetResponses(List<string> responses)
73+
{
74+
Responses = responses ?? new List<string>(); ;
75+
return this;
76+
}
77+
78+
public Agent SetId(string id)
79+
{
80+
Id = id;
81+
return this;
82+
}
83+
84+
public Agent SetName(string name)
85+
{
86+
Name = name;
87+
return this;
88+
}
89+
90+
public Agent SetDescription(string description)
91+
{
92+
Description = description;
93+
return this;
94+
}
95+
96+
public Agent SetIsPublic(bool isPublic)
97+
{
98+
IsPublic = isPublic;
99+
return this;
100+
}
33101
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace BotSharp.Abstraction.Agents.Models;
2+
3+
public class UserAgent
4+
{
5+
public string Id { get; set; } = string.Empty;
6+
public string UserId { get; set; } = string.Empty;
7+
public string AgentId { get; set; } = string.Empty;
8+
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
9+
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
10+
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Text.Json.Serialization;
2+
13
namespace BotSharp.Abstraction.Conversations.Models;
24

35
public class Conversation
@@ -6,9 +8,11 @@ public class Conversation
68
public string AgentId { get; set; } = string.Empty;
79
public string UserId { get; set; } = string.Empty;
810
public string Title { get; set; } = string.Empty;
11+
[JsonIgnore]
12+
public string Dialog { get; set; } = string.Empty;
13+
[JsonIgnore]
14+
public ConversationState States { get; set; }
915

1016
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
1117
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
12-
13-
public ConversationState State { get; set; }
1418
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1+
using BotSharp.Abstraction.Repositories.Models;
2+
13
namespace BotSharp.Abstraction.Conversations.Models;
24

35
public class ConversationState : Dictionary<string, string>
46
{
7+
public ConversationState()
8+
{
9+
10+
}
11+
12+
public ConversationState(List<KeyValueModel> pairs)
13+
{
14+
foreach (var pair in pairs)
15+
{
16+
this[pair.Key] = pair.Value;
17+
}
18+
}
19+
20+
public List<KeyValueModel> ToKeyValueList()
21+
{
22+
return this.Select(x => new KeyValueModel(x.Key, x.Value)).ToList();
23+
}
524
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace BotSharp.Abstraction.Repositories;
2+
3+
public class BotSharpDatabaseSettings : DatabaseBasicSettings
4+
{
5+
public string[] Assemblies { get; set; }
6+
public string FileRepository { get; set; }
7+
public string MongoDb { get; set; }
8+
public DbConnectionSetting BotSharp { get; set; }
9+
}
10+
11+
public class DatabaseBasicSettings
12+
{
13+
public string Default { get; set; }
14+
public DbConnectionSetting DefaultConnection { get; set; }
15+
public bool EnableSqlLog { get; set; }
16+
public bool EnableSensitiveDataLogging { get; set; }
17+
public bool EnableRetryOnFailure { get; set; }
18+
public bool UseCamelCase { get; set; }
19+
}
20+
21+
public class DbConnectionSetting
22+
{
23+
public string Master { get; set; }
24+
public string[] Slavers { get; set; }
25+
26+
public DbConnectionSetting()
27+
{
28+
Slavers = new string[0];
29+
}
30+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using BotSharp.Abstraction.Repositories.Models;
2+
using BotSharp.Abstraction.Routing.Models;
3+
using BotSharp.Abstraction.Users.Models;
4+
5+
namespace BotSharp.Abstraction.Repositories;
6+
7+
public interface IBotSharpRepository
8+
{
9+
IQueryable<User> Users { get; }
10+
IQueryable<Agent> Agents { get; }
11+
IQueryable<UserAgent> UserAgents { get; }
12+
IQueryable<Conversation> Conversations { get; }
13+
IQueryable<RoutingItem> RoutingItems { get; }
14+
IQueryable<RoutingProfile> RoutingProfiles { get; }
15+
16+
int Transaction<TTableInterface>(Action action);
17+
void Add<TTableInterface>(object entity);
18+
19+
User GetUserByEmail(string email);
20+
void CreateUser(User user);
21+
void UpdateAgent(Agent agent);
22+
23+
List<RoutingItem> CreateRoutingItems(List<RoutingItem> routingItems);
24+
List<RoutingProfile> CreateRoutingProfiles(List<RoutingProfile> profiles);
25+
void DeleteRoutingItems();
26+
void DeleteRoutingProfiles();
27+
28+
Agent GetAgent(string agentId);
29+
List<string> GetAgentResponses(string agentId);
30+
31+
void CreateNewConversation(Conversation conversation);
32+
string GetConversationDialog(string conversationId);
33+
void UpdateConversationDialog(string conversationId, string dialogs);
34+
35+
List<KeyValueModel> GetConversationStates(string conversationId);
36+
void UpdateConversationStates(string conversationId, List<KeyValueModel> states);
37+
38+
Conversation GetConversation(string conversationId);
39+
List<Conversation> GetConversations(string userId);
40+
}

0 commit comments

Comments
 (0)