From 975b5720c7f2f116735b45ae7cd50446a7da848b Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 25 Oct 2023 13:02:50 -0500 Subject: [PATCH 1/5] add impact in agent functions --- .../BotSharp.Abstraction/Functions/Models/FunctionDef.cs | 1 + .../Models/FunctionDefMongoElement.cs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionDef.cs b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionDef.cs index 153fb473..d89620a9 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionDef.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionDef.cs @@ -4,6 +4,7 @@ public class FunctionDef { public string Name { get; set; } public string Description { get; set; } + public string? Impact { get; set; } public FunctionParametersDef Parameters { get; set; } = new FunctionParametersDef(); public override string ToString() diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs index ec9699c0..08caa2a4 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs @@ -7,6 +7,7 @@ public class FunctionDefMongoElement { public string Name { get; set; } public string Description { get; set; } + public string? Impact { get; set; } public FunctionParametersDefMongoElement Parameters { get; set; } = new FunctionParametersDefMongoElement(); public FunctionDefMongoElement() @@ -20,6 +21,7 @@ public class FunctionDefMongoElement { Name = function.Name, Description = function.Description, + Impact = function.Impact, Parameters = new FunctionParametersDefMongoElement { Type = function.Parameters.Type, @@ -35,6 +37,7 @@ public class FunctionDefMongoElement { Name = mongoFunction.Name, Description = mongoFunction.Description, + Impact = mongoFunction.Impact, Parameters = new FunctionParametersDef { Type = mongoFunction.Parameters.Type, From 6f7f143e7d658313ed1e56ea4a9a188d1f44383f Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 25 Oct 2023 15:09:21 -0500 Subject: [PATCH 2/5] add impact --- .../BotSharp.Core/Repository/FileRepository.cs | 9 +++++++-- .../Models/AgentResponseMongoElement.cs | 1 + .../Models/AgentTemplateMongoElement.cs | 1 + .../Models/FunctionDefMongoElement.cs | 1 + .../Models/RoutingRuleMongoElement.cs | 1 + src/Plugins/BotSharp.Plugin.MongoStorage/Using.cs | 3 ++- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs index 4d862e7a..f873a827 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs @@ -5,7 +5,6 @@ using BotSharp.Abstraction.Users.Models; using BotSharp.Abstraction.Agents.Models; using MongoDB.Driver; using BotSharp.Abstraction.Routing.Models; -using Amazon.Util; namespace BotSharp.Core.Repository; @@ -380,7 +379,13 @@ public class FileRepository : IBotSharpRepository } var functionText = JsonSerializer.Serialize(functions, _options); - File.WriteAllText(functionFile, functionText); + + using (var sw = File.CreateText(functionFile)) + { + sw.Write(functionText); + } + + //File.WriteAllText(functionFile, functionText); } private void UpdateAgentTemplates(string agentId, List templates) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentResponseMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentResponseMongoElement.cs index ee556549..26ddebbc 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentResponseMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentResponseMongoElement.cs @@ -2,6 +2,7 @@ using BotSharp.Abstraction.Agents.Models; namespace BotSharp.Plugin.MongoStorage.Models; +[BsonIgnoreExtraElements] public class AgentResponseMongoElement { public string Prefix { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentTemplateMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentTemplateMongoElement.cs index 719a11d9..847ec5c9 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentTemplateMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentTemplateMongoElement.cs @@ -2,6 +2,7 @@ using BotSharp.Abstraction.Agents.Models; namespace BotSharp.Plugin.MongoStorage.Models; +[BsonIgnoreExtraElements] public class AgentTemplateMongoElement { public string Name { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs index 08caa2a4..5910661f 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs @@ -3,6 +3,7 @@ using System.Text.Json; namespace BotSharp.Plugin.MongoStorage.Models; +[BsonIgnoreExtraElements] public class FunctionDefMongoElement { public string Name { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs index 9f644c68..1a40b0f7 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs @@ -2,6 +2,7 @@ using BotSharp.Abstraction.Routing.Models; namespace BotSharp.Plugin.MongoStorage.Models; +[BsonIgnoreExtraElements] public class RoutingRuleMongoElement { public string Field { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Using.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Using.cs index 5debd75f..ca13f204 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Using.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Using.cs @@ -10,4 +10,5 @@ global using BotSharp.Abstraction.Plugins; global using Microsoft.Extensions.Configuration; global using Microsoft.Extensions.DependencyInjection; global using MongoDB.Bson; -global using MongoDB.Driver; \ No newline at end of file +global using MongoDB.Driver; +global using MongoDB.Bson.Serialization.Attributes; \ No newline at end of file From 2e3fbc98a97f6b6e146451bd20462b3513d09004 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 25 Oct 2023 15:11:15 -0500 Subject: [PATCH 3/5] remove test code --- .../BotSharp.Core/Repository/FileRepository.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs index f873a827..db801cd5 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs @@ -379,13 +379,7 @@ public class FileRepository : IBotSharpRepository } var functionText = JsonSerializer.Serialize(functions, _options); - - using (var sw = File.CreateText(functionFile)) - { - sw.Write(functionText); - } - - //File.WriteAllText(functionFile, functionText); + File.WriteAllText(functionFile, functionText); } private void UpdateAgentTemplates(string agentId, List templates) From 8cca7361b2cd89507f477afa86c27dc915d2f8aa Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 25 Oct 2023 15:56:50 -0500 Subject: [PATCH 4/5] refine agent update functions --- .../BotSharp.Core/Repository/FileRepository.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs index db801cd5..a1779c34 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs @@ -372,13 +372,7 @@ public class FileRepository : IBotSharpRepository var functionFile = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, "functions.json"); - var functions = new List(); - foreach (var function in inputFunctions) - { - functions.Add(JsonSerializer.Serialize(function, _options)); - } - - var functionText = JsonSerializer.Serialize(functions, _options); + var functionText = JsonSerializer.Serialize(inputFunctions, _options); File.WriteAllText(functionFile, functionText); } From 4041ca8de7239dabbc4e809a8a53970edd654361 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 25 Oct 2023 16:40:36 -0500 Subject: [PATCH 5/5] remove code --- .../BotSharp.Core/Conversations/Services/ConversationService.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 8f3a865e..efcb9cf9 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -54,8 +54,6 @@ public partial class ConversationService : IConversationService public async Task NewConversation(Conversation sess) { var db = _services.GetRequiredService(); - var dbSettings = _services.GetRequiredService(); - var conversationSettings = _services.GetRequiredService(); var user = db.GetUserByExternalId(_user.Id); var foundUserId = user?.Id ?? string.Empty;