Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a2a3759
add mongo repository
Aug 26, 2023
eeb3ace
Merge branch 'master' into features/add-mongo-implementation
Aug 26, 2023
00d6150
add missing using
Aug 26, 2023
d7d0af2
add create agent and update agent
Aug 28, 2023
1bf8ecd
refine get agent
Aug 28, 2023
60c2aa7
add external user
Aug 28, 2023
2194300
add basic mongo store
Aug 28, 2023
45baed5
merge with master
Aug 28, 2023
1bf4dd1
resolve conflicts
Aug 28, 2023
7dc43f7
merge with master
Sep 1, 2023
6330335
sync with master
Sep 1, 2023
4e3708e
temp save
Sep 1, 2023
f581991
add create user, create/update agent
Sep 2, 2023
5531944
add routing item and routing profile
Sep 2, 2023
ca6f606
add routing item and profile
Sep 3, 2023
ba96bd8
add get agent response
Sep 3, 2023
be5f9f2
update conversation record
Sep 3, 2023
c897209
depend on default repository
Sep 3, 2023
4cc74e5
add conversation collection
Sep 3, 2023
0acf60b
merge with master
Sep 3, 2023
b5c90c0
resove conflicts
Sep 3, 2023
f381208
use list extension
Sep 3, 2023
d1d1853
add user id
Sep 4, 2023
a882689
sync ispublic
Sep 4, 2023
f2e0fb0
merge with dev
Sep 4, 2023
dc755e3
merge with remote
Sep 6, 2023
1981b0f
resolve conflicts
Sep 6, 2023
9d6a7ba
split dialog and state
Sep 6, 2023
ad8b9a3
minor change
Sep 6, 2023
5b543e6
merge with remote
Sep 6, 2023
45ed8d6
remove record reference
Sep 7, 2023
4f9595f
refine code
Sep 8, 2023
a84f58a
merge with master
Sep 8, 2023
24be8e7
resolve conflict
Sep 8, 2023
9f918c6
fix file bugs
Sep 8, 2023
56eb31d
merge with master
Sep 9, 2023
5e9f910
resove conflicts
Sep 9, 2023
43d7d8b
remove comments
Sep 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions BotSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RAGs", "RAGs", "{4F346DCE-0
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.KnowledgeBase", "src\Plugins\BotSharp.Plugin.KnowledgeBase\BotSharp.Plugin.KnowledgeBase.csproj", "{298AC787-A104-414C-B114-82BE764FBD9C}"
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.MongoStorage\BotSharp.Plugin.MongoStorage.csproj", "{DB3DE37B-1208-4ED3-9615-A52AD0AAD69C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public virtual bool OnInstructionLoaded(string template, Dictionary<string, obje
return true;
}

public virtual bool OnFunctionsLoaded(ref string functions)
public virtual bool OnFunctionsLoaded(ref List<string> functions)
{
_agent.Functions = functions;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface IAgentHook

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

bool OnFunctionsLoaded(ref string functions);
bool OnFunctionsLoaded(ref List<string> functions);

bool OnSamplesLoaded(ref string samples);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public interface IAgentRouting
{
string AgentId { get; }
Task<Agent> LoadRouter();
RoutingRecord[] GetRoutingRecords();
RoutingRecord GetRecordByName(string name);
RoutingItem[] GetRoutingRecords();
RoutingItem GetRecordByName(string name);
}
72 changes: 70 additions & 2 deletions src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Agent
{
public string Id { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string? Description { get; set; }
public string Description { get; set; }
public DateTime CreatedDateTime { get; set; }
public DateTime UpdatedDateTime { get; set; }

Expand All @@ -21,13 +21,81 @@ public class Agent
/// <summary>
/// Functions
/// </summary>
public string Functions { get; set; }
public List<string> Functions { get; set; }

/// <summary>
/// Responses
/// </summary>
public List<string> Responses { get; set; }

/// <summary>
/// Domain knowledges
/// </summary>
public string Knowledges { get; set; }

public bool IsPublic { get; set; }

public override string ToString()
=> $"{Name} {Id}";


public static Agent Clone(Agent agent)
{
return new Agent
{
Id = agent.Id,
Name = agent.Name,
Description = agent.Description,
Instruction = agent.Instruction,
Functions = agent.Functions,
Responses = agent.Responses,
Samples = agent.Samples,
Knowledges = agent.Knowledges,
IsPublic = agent.IsPublic,
CreatedDateTime = agent.CreatedDateTime,
UpdatedDateTime = agent.UpdatedDateTime,
};
}

public Agent SetInstruction(string instruction)
{
Instruction = instruction;
return this;
}

public Agent SetFunctions(List<string> functions)
{
Functions = functions ?? new List<string>();
return this;
}

public Agent SetResponses(List<string> responses)
{
Responses = responses ?? new List<string>(); ;
return this;
}

public Agent SetId(string id)
{
Id = id;
return this;
}

public Agent SetName(string name)
{
Name = name;
return this;
}

public Agent SetDescription(string description)
{
Description = description;
return this;
}

public Agent SetIsPublic(bool isPublic)
{
IsPublic = isPublic;
return this;
}
}
10 changes: 10 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Agents/Models/UserAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BotSharp.Abstraction.Agents.Models;

public class UserAgent
{
public string Id { get; set; } = string.Empty;
public string UserId { get; set; } = string.Empty;
public string AgentId { get; set; } = string.Empty;
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Text.Json.Serialization;

namespace BotSharp.Abstraction.Conversations.Models;

public class Conversation
Expand All @@ -6,9 +8,11 @@ public class Conversation
public string AgentId { get; set; } = string.Empty;
public string UserId { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
[JsonIgnore]
public string Dialog { get; set; } = string.Empty;
[JsonIgnore]
public ConversationState States { get; set; }

public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;

public ConversationState State { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
using BotSharp.Abstraction.Repositories.Models;

namespace BotSharp.Abstraction.Conversations.Models;

public class ConversationState : Dictionary<string, string>
{
public ConversationState()
{

}

public ConversationState(List<KeyValueModel> pairs)
{
foreach (var pair in pairs)
{
this[pair.Key] = pair.Value;
}
}

public List<KeyValueModel> ToKeyValueList()
{
return this.Select(x => new KeyValueModel(x.Key, x.Value)).ToList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace BotSharp.Abstraction.Repositories;

public class BotSharpDatabaseSettings : DatabaseBasicSettings
{
public string[] Assemblies { get; set; }
public string FileRepository { get; set; }
public string MongoDb { get; set; }
public DbConnectionSetting BotSharp { get; set; }
}

public class DatabaseBasicSettings
{
public string Default { get; set; }
public DbConnectionSetting DefaultConnection { get; set; }
public bool EnableSqlLog { get; set; }
public bool EnableSensitiveDataLogging { get; set; }
public bool EnableRetryOnFailure { get; set; }
public bool UseCamelCase { get; set; }
}

public class DbConnectionSetting
{
public string Master { get; set; }
public string[] Slavers { get; set; }

public DbConnectionSetting()
{
Slavers = new string[0];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using BotSharp.Abstraction.Repositories.Models;
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Abstraction.Users.Models;

namespace BotSharp.Abstraction.Repositories;

public interface IBotSharpRepository
{
IQueryable<User> Users { get; }
IQueryable<Agent> Agents { get; }
IQueryable<UserAgent> UserAgents { get; }
IQueryable<Conversation> Conversations { get; }
IQueryable<RoutingItem> RoutingItems { get; }
IQueryable<RoutingProfile> RoutingProfiles { get; }

int Transaction<TTableInterface>(Action action);
void Add<TTableInterface>(object entity);

User GetUserByEmail(string email);
void CreateUser(User user);
void UpdateAgent(Agent agent);

List<RoutingItem> CreateRoutingItems(List<RoutingItem> routingItems);
List<RoutingProfile> CreateRoutingProfiles(List<RoutingProfile> profiles);
void DeleteRoutingItems();
void DeleteRoutingProfiles();

Agent GetAgent(string agentId);
List<string> GetAgentResponses(string agentId);

void CreateNewConversation(Conversation conversation);
string GetConversationDialog(string conversationId);
void UpdateConversationDialog(string conversationId, string dialogs);

List<KeyValueModel> GetConversationStates(string conversationId);
void UpdateConversationStates(string conversationId, List<KeyValueModel> states);

Conversation GetConversation(string conversationId);
List<Conversation> GetConversations(string userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BotSharp.Abstraction.Repositories;

public interface IBotSharpTable
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

namespace BotSharp.Abstraction.Repositories.Models;

public class KeyValueModel
{
public string Key { get; set; }
public string Value { get; set; }

public KeyValueModel()
{

}

public KeyValueModel(string key, string value)
{
Key = key;
Value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using BotSharp.Abstraction.Utilities;

namespace BotSharp.Abstraction.Repositories.Records;

public class AgentRecord : RecordBase
{
[Required]
[MaxLength(64)]
public string Name { get; set; } = string.Empty;

[MaxLength(512)]
public string? Description { get; set; }

public string Instruction { get; set; }

public List<string> Functions { get; set; }

public List<string> Responses { get; set; }

public string Samples { get; set; }
public bool IsPublic { get; set; }

[Required]
public DateTime CreatedTime { get; set; }

[Required]
public DateTime UpdatedTime { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using BotSharp.Abstraction.Repositories.Models;
using System.Text.Json.Serialization;

namespace BotSharp.Abstraction.Repositories.Records;

public class ConversationRecord : RecordBase
{
[Required]
[MaxLength(36)]
public Guid AgentId { get; set; } = Guid.Empty;

[Required]
[MaxLength(36)]
public Guid UserId { get; set; } = Guid.Empty;

[MaxLength(64)]
public string Title { get; set; } = string.Empty;

[JsonIgnore]
public string Dialog { get; set; }

[JsonIgnore]
public List<KeyValueModel> States { get; set; }

[Required]
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;

[Required]
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BotSharp.Abstraction.Repositories.Records;

public class RecordBase
{
public Guid Id { get; set; } = Guid.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Abstraction.Utilities;

namespace BotSharp.Abstraction.Repositories.Records;

public class RoutingItemRecord : RecordBase
{
public Guid AgentId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<string> RequiredFields { get; set; } = new List<string>();
public string? RedirectTo { get; set; }
public bool Disabled { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using BotSharp.Abstraction.Routing.Models;

namespace BotSharp.Abstraction.Repositories.Records;

public class RoutingProfileRecord : RecordBase
{
public string Name { get; set; }
public List<string> AgentIds { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using BotSharp.Abstraction.Users.Models;

namespace BotSharp.Abstraction.Repositories.Records;

public class UserAgentRecord : RecordBase
{
[Required]
[StringLength(36)]
public string UserId { get; set; } = string.Empty;

[Required]
[MaxLength(36)]
public string AgentId { get; set; } = string.Empty;

[Required]
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;

[Required]
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
}
Loading