From 15ce459971aa89068f9cd4ba18f69d6bb18012ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Tue, 22 Oct 2024 09:05:56 +0800 Subject: [PATCH 01/13] Add a CallingPhone column to the ConversationDocument --- .../BotSharp.Abstraction/Conversations/Models/Conversation.cs | 2 ++ .../BotSharp.Core/Conversations/Services/ConversationService.cs | 2 ++ .../Collections/ConversationDocument.cs | 1 + .../Repository/MongoRepository.Conversation.cs | 1 + 4 files changed, 6 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs index 38734d75..c2be970f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs @@ -28,6 +28,8 @@ public class Conversation public List Tags { get; set; } = new(); + public string CallingPhone { get; set; } + public DateTime UpdatedTime { get; set; } = DateTime.UtcNow; public DateTime CreatedTime { get; set; } = DateTime.UtcNow; } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 97b69d44..a9c56fa9 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -172,10 +172,12 @@ public partial class ConversationService : IConversationService { var state = _services.GetRequiredService(); var channel = state.GetState("channel"); + var callingPhone = state.GetState("calling_phone"); var sess = new Conversation { Id = _conversationId, Channel = channel, + CallingPhone = callingPhone, AgentId = agentId }; converation = await NewConversation(sess); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs index 609d637d..b23f26a4 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs @@ -10,6 +10,7 @@ public class ConversationDocument : MongoBase public string Status { get; set; } public int DialogCount { get; set; } public List Tags { get; set; } + public string CallingPhone { get; set; } public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index ff7cefcd..f0104788 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -17,6 +17,7 @@ public partial class MongoRepository UserId = !string.IsNullOrEmpty(conversation.UserId) ? conversation.UserId : string.Empty, Title = conversation.Title, Channel = conversation.Channel, + CallingPhone = conversation.CallingPhone, TaskId = conversation.TaskId, Status = conversation.Status, Tags = conversation.Tags ?? new(), From ad0b6bb6f41599d1dc417c559113a2812e7dbe31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Tue, 22 Oct 2024 09:19:27 +0800 Subject: [PATCH 02/13] optimize tags init --- .../Repository/FileRepository/FileRepository.Conversation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs index bc9912b3..7da6c849 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs @@ -10,7 +10,7 @@ namespace BotSharp.Core.Repository var utcNow = DateTime.UtcNow; conversation.CreatedTime = utcNow; conversation.UpdatedTime = utcNow; - conversation.Tags = conversation.Tags ?? new(); + conversation.Tags ??= new(); var dir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir, conversation.Id); if (!Directory.Exists(dir)) From 376cc8ff502f4b613b1804a7512d52a417249f49 Mon Sep 17 00:00:00 2001 From: Chaitanya110703 <116812461+Chaitanya110703@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:44:05 +0530 Subject: [PATCH 03/13] Docs: Typo Fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Corrected "algrithm" to "algorithm" in [README.md]. This pull request addresses a minor typo found in repository. The typo has been corrected to improve clarity and maintain the quality of the documentation. This change is purely cosmetic and does not affect functionality. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d80a5abe..a76da541 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ **BotSharp** is an open source machine learning framework for AI Bot platform builder. This project involves natural language understanding, computer vision and audio processing technologies, and aims to promote the development and application of intelligent robot assistants in information systems. Out-of-the-box machine learning algorithms allow ordinary programmers to develop artificial intelligence applications faster and easier. -It's written in C# running on .Net Core that is full cross-platform framework, the plug-in and pipeline flow execution design is adopted to completely decouple the plug-ins. C# is a enterprise grade programming language which is widely used to code business logic in information management related system. More friendly to corporate developers. BotSharp adopts machine learning algrithm in C# directly. That will facilitate the feature of the typed language C#, and be more easier when refactoring code in system scope. +It's written in C# running on .Net Core that is full cross-platform framework, the plug-in and pipeline flow execution design is adopted to completely decouple the plug-ins. C# is a enterprise grade programming language which is widely used to code business logic in information management related system. More friendly to corporate developers. BotSharp adopts machine learning algorithm in C# directly. That will facilitate the feature of the typed language C#, and be more easier when refactoring code in system scope. **BotSharp** is in accordance with components principle strictly, decouples every part that is needed in the platform builder. So you can choose different UI/UX, or pick up a different LLM providers. They are all modulized based on unified interfaces. **BotSharp** provides an advanced Agent abstraction layer to efficiently manage complex application scenarios in enterprises, allowing enterprise developers to efficiently integrate AI into business systems. From b90895cdbd5cdc31ee63e4d6825e6d61dea28744 Mon Sep 17 00:00:00 2001 From: Chaitanya110703 <116812461+Chaitanya110703@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:45:38 +0530 Subject: [PATCH 04/13] Docs: Typo Fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Corrected "Memeory" to "Memory" in [README.md]. This pull request addresses a minor typo found in repository. The typo has been corrected to improve clarity and maintain the quality of the documentation. This change is purely cosmetic and does not affect functionality. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d80a5abe..c1ad92ad 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ It's written in C# running on .Net Core that is full cross-platform framework, t * Built-in multi-agents and conversation with state management. * Support multiple LLM Planning approaches to handle different tasks from simple to complex. -* Built-in RAG related interfaces, Memeory based vector searching. +* Built-in RAG related interfaces, Memory based vector searching. * Support multiple AI platforms (ChatGPT 3.5 / 4.0, PaLM 2, LLaMA 3, Claude Sonnet 3.5, HuggingFace). * Allow multiple agents with different responsibilities cooperate to complete complex tasks. * Build, test, evaluate and audit your LLM agent in one place. From f5cd18d4893e63d049205679c5c9fb266a7b8156 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 22 Oct 2024 12:30:53 -0500 Subject: [PATCH 05/13] add default --- .../BotSharp.Core/Instructs/InstructService.Instruct.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.Instruct.cs b/src/Infrastructure/BotSharp.Core/Instructs/InstructService.Instruct.cs index 76ad3608..93fa64e2 100644 --- a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.Instruct.cs +++ b/src/Infrastructure/BotSharp.Core/Instructs/InstructService.Instruct.cs @@ -69,7 +69,9 @@ public partial class InstructService }; var messages = BuildDialogs(options); - var completion = CompletionProvider.GetChatCompletion(_services, provider: options.Provider, model: options.Model); + var provider = options.Provider ?? agent?.LlmConfig?.Provider ?? "openai"; + var model = options.Model ?? agent?.LlmConfig?.Model ?? "gpt-4o"; + var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model); return await completion.GetChatCompletions(localAgent, messages); } From 62c1d709bfb0940997ee06cadcf40d07b41d73ee Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 22 Oct 2024 15:24:40 -0500 Subject: [PATCH 06/13] fix model --- .../Providers/ChatCompletionProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs index 047cc246..8b90d29f 100644 --- a/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs @@ -37,7 +37,7 @@ public class ChatCompletionProvider : IChatCompletion } var settingsService = _services.GetRequiredService(); - var settings = settingsService.GetSetting("anthropic", agent.LlmConfig?.Model ?? "claude-3-haiku"); + var settings = settingsService.GetSetting(Provider, _model ?? agent.LlmConfig?.Model ?? "claude-3-haiku"); var client = new AnthropicClient(new APIAuthentication(settings.ApiKey)); var (prompt, parameters) = PrepareOptions(agent, conversations, settings); From cce06efdd18a3685b4c3aa451a7551d0d841c71d Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Tue, 22 Oct 2024 20:52:18 -0500 Subject: [PATCH 07/13] create conv with tags --- .../BotSharp.Abstraction/Models/MessageConfig.cs | 5 +++++ .../BotSharp.OpenAPI/Controllers/ConversationController.cs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Models/MessageConfig.cs b/src/Infrastructure/BotSharp.Abstraction/Models/MessageConfig.cs index 9ea5917c..25efefa1 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Models/MessageConfig.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Models/MessageConfig.cs @@ -36,6 +36,11 @@ public class MessageConfig /// public List States { get; set; } = new(); + /// + /// Conversation tags + /// + public List Tags { get; set; } = new(); + /// /// Agent task id /// diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index f5cfc7c8..91617a0f 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -35,6 +35,7 @@ public class ConversationController : ControllerBase { AgentId = agentId, Channel = channel == default ? ConversationChannel.OpenAPI : channel.Value, + Tags = config.Tags ?? new(), TaskId = config.TaskId }; conv = await service.NewConversation(conv); From b780cbd8b889907cd927f45f066b3777fc312feb Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Wed, 23 Oct 2024 00:22:59 -0500 Subject: [PATCH 08/13] add text field in generic element --- .../Models/RichContent/Template/GenericTemplateMessage.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs index daf2e636..3b4a7a17 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs @@ -36,6 +36,9 @@ public class GenericElement [Translate] public string Subtitle { get; set; } + [Translate] + public string Text { get; set; } + [JsonPropertyName("image_url")] public string ImageUrl { get; set; } From 127e694ee9e698473c737cc2c2ea498815701fe7 Mon Sep 17 00:00:00 2001 From: Joanna Ren <101223@smsassist.com> Date: Wed, 23 Oct 2024 16:56:52 -0500 Subject: [PATCH 09/13] Add drop tmp table --- .../BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs | 7 +++++-- .../BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs index f85b5ace..af08194c 100644 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs +++ b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs @@ -90,6 +90,7 @@ namespace BotSharp.Plugin.ExcelHandler.Services { var numTables = workbook.NumberOfSheets; var commandList = new List(); + var state = _services.GetRequiredService(); for (int sheetIdx = 0; sheetIdx < numTables; sheetIdx++) { @@ -109,15 +110,17 @@ namespace BotSharp.Plugin.ExcelHandler.Services commandList.Add(commandResult); continue; } - var (isInsertSuccess, insertMessage) = SqlInsertDataFn(sheet); string table = $"{_database}.{_tableName}"; + state.SetState("tmp_table", table); + + var (isInsertSuccess, insertMessage) = SqlInsertDataFn(sheet); string exampleData = GetInsertExample(table); commandResult = new SqlContextOut { isSuccessful = isInsertSuccess, - Message = $"{insertMessage}\r\nExample Data: {exampleData}", + Message = $"{insertMessage}\r\nExample Data: {exampleData}. \r\n The remaining data contains different values. ", FileName = _currentFileName }; commandList.Add(commandResult); diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs index 99b40a65..d1b21bdc 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs @@ -41,6 +41,12 @@ public class ExecuteQueryFn : IFunctionCallback _ => throw new NotImplementedException($"Database type {settings.DatabaseType} is not supported.") }; + if (refinedArgs.SqlStatements.Length == 1 && refinedArgs.SqlStatements[0].StartsWith("DROP TABLE")) + { + message.Content = "Drop table successfully"; + return true; + } + if (results.Count() == 0) { message.Content = "No record found"; From b4bc506585d35fb580276a67fc5eba93a70717bd Mon Sep 17 00:00:00 2001 From: Joanna Ren <101223@smsassist.com> Date: Wed, 23 Oct 2024 16:59:14 -0500 Subject: [PATCH 10/13] Refined knowledge search, added norm_question, entity type/value parms --- .../knowledge.generation.plain.liquid | 3 ++ .../Functions/PrimaryStagePlanFn.cs | 5 +++- .../Models/PrimaryRequirementRequest.cs | 3 ++ .../functions/plan_primary_stage.json | 29 +++++++++++++++++-- .../templates/two_stage.1st.plan.liquid | 3 +- .../functions/verify_dictionary_term.json | 4 +-- 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.plain.liquid b/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.plain.liquid index 2792595a..a2aba266 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.plain.liquid +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.plain.liquid @@ -3,6 +3,9 @@ You are a knowledge extractor for knowledge base. Extract the answer in "SQL Ans * Skip the question/answer for tmp table. * Don't include tmp table in the answer. * Include all the explanation comments as additional knowledge. +* Don't replace the parameter in the question. +* Replace the specific id in answer based on the question. +* Don't need multiple set of query solutions for the same question. Only keep one. ===== User Questions: diff --git a/src/Plugins/BotSharp.Plugin.Planner/Functions/PrimaryStagePlanFn.cs b/src/Plugins/BotSharp.Plugin.Planner/Functions/PrimaryStagePlanFn.cs index 0024c916..74afc5ff 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/Functions/PrimaryStagePlanFn.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/Functions/PrimaryStagePlanFn.cs @@ -25,11 +25,14 @@ public class PrimaryStagePlanFn : IFunctionCallback state.SetState("max_tokens", "4096"); var task = JsonSerializer.Deserialize(message.FunctionArgs); + var searchQuestions = new List(task.Questions); + searchQuestions.AddRange(task.NormQuestions); + searchQuestions = searchQuestions.Distinct().ToList(); // Get knowledge from vectordb var hooks = _services.GetServices(); var knowledges = new List(); - foreach (var question in task.Questions) + foreach (var question in searchQuestions) { foreach (var hook in hooks) { diff --git a/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/PrimaryRequirementRequest.cs b/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/PrimaryRequirementRequest.cs index 87c05f16..0779a51e 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/PrimaryRequirementRequest.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/PrimaryRequirementRequest.cs @@ -7,4 +7,7 @@ public class PrimaryRequirementRequest [JsonPropertyName("questions")] public string[] Questions { get; set; } = []; + + [JsonPropertyName("norm_questions")] + public string[] NormQuestions { get; set; } = []; } diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_primary_stage.json b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_primary_stage.json index 288c14b2..a934169a 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_primary_stage.json +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_primary_stage.json @@ -10,10 +10,35 @@ }, "questions": { "type": "array", - "description": "Rephrase user requirements in details and in multiple ways, don't miss any information especially for those line items, values and numbers.", + "description": "Break down user requirements in details and in multiple ways, don't miss any entity type/value", "items": { "type": "string", - "description": "Question converted from requirement in different ways to search in the knowledge base, be short and you can refer to the global knowledge.One question should contain only one main topic." + "description": "Question converted from requirement in different ways to search in the knowledge base, be short and you can refer to the global knowledge.One question should contain only one main topic that with one entity type." + } + }, + "norm_questions": { + "type": "array", + "description": "normalize the generated questions, remove specific entity value.", + "items": { + "type": "string", + "description": "Normalized question" + } + }, + "entities": { + "type": "array", + "description": "entities with type and value", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "entity type" + }, + "value": { + "type": "string", + "description": "entity value" + } + } } } }, diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid index 656a6fe4..9ded6e16 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid @@ -8,7 +8,8 @@ Thinking process: - If there is extra knowledge or relationship needed between steps, set the need_breakdown_task to true for both steps. - If the solution mentioned "related solutions" is needed, set the need_breakdown_task to true. - You should find the relationships between data structure based on the task knowledge strictly. If lack of information, set the need_breakdown_task to true. - - If you need to lookup the dictionary to verify or get the enum/term/dictionary value, set the need_lookup_dictionary to true. + - If you need to lookup the dictionary to verify or get the enum/term/dictionary value(exclude example data from attachment), set the need_lookup_dictionary to true. + - Don't set need_lookup_dictionary to true for attachment data. - Seperate the dictionary lookup and need additional information/knowledge into different subtask. 3. Input argument must reference to corresponding variable name that retrieved by previous steps, variable name must start with '@'; 4. Output all the subtasks as much detail as possible in JSON: [{{ response_format }}] diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/verify_dictionary_term.json b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/verify_dictionary_term.json index 3dc21e01..0e79a2fe 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/verify_dictionary_term.json +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/verify_dictionary_term.json @@ -1,6 +1,6 @@ { "name": "verify_dictionary_term", - "description": "Get id from dictionary table by keyword. Call this function only if need_lookup_dictionary is true and is_insert is false", + "description": "Get id from dictionary table by keyword. Call this function only if need_lookup_dictionary is true and is_insert is false. You can only query one table at a time.", "parameters": { "type": "object", "properties": { @@ -18,7 +18,7 @@ }, "tables": { "type": "array", - "description": "all related tables", + "description": "all related dictionary tables", "items": { "type": "string", "description": "table name" From 3d1f91913d2dcf1f1ff22217b6ce52616f4eb9cb Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Thu, 24 Oct 2024 14:36:04 -0500 Subject: [PATCH 11/13] Code Driver init --- .../Agents/Enums/BuiltInAgentId.cs | 8 +++ .../BotSharp.Plugin.CodeDriver.csproj | 37 ++++++++++++++ .../CodeDriverPlugin.cs | 22 +++++++++ .../Functions/SaveSourceCodeFn.cs | 49 +++++++++++++++++++ .../Models/SaveSourceCodeArgs.cs | 12 +++++ .../BotSharp.Plugin.CodeDriver/Using.cs | 2 + .../agent.json | 17 +++++++ .../functions/save_source_code.json | 19 +++++++ .../instructions/instruction.liquid | 19 +++++++ .../SqlDriverPlugin.cs | 6 +++ .../agent.json | 1 + 11 files changed, 192 insertions(+) create mode 100644 src/Plugins/BotSharp.Plugin.CodeDriver/BotSharp.Plugin.CodeDriver.csproj create mode 100644 src/Plugins/BotSharp.Plugin.CodeDriver/CodeDriverPlugin.cs create mode 100644 src/Plugins/BotSharp.Plugin.CodeDriver/Functions/SaveSourceCodeFn.cs create mode 100644 src/Plugins/BotSharp.Plugin.CodeDriver/Models/SaveSourceCodeArgs.cs create mode 100644 src/Plugins/BotSharp.Plugin.CodeDriver/Using.cs create mode 100644 src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/agent.json create mode 100644 src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/functions/save_source_code.json create mode 100644 src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/instructions/instruction.liquid diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs index 55436ae2..56a7e11f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Enums/BuiltInAgentId.cs @@ -37,5 +37,13 @@ public class BuiltInAgentId /// public const string Planner = "282a7128-69a1-44b0-878c-a9159b88f3b9"; + /// + /// SQL statement generation + /// public const string SqlDriver = "beda4c12-e1ec-4b4b-b328-3df4a6687c4f"; + + /// + /// Programming source code generation + /// + public const string CodeDriver = "c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62"; } diff --git a/src/Plugins/BotSharp.Plugin.CodeDriver/BotSharp.Plugin.CodeDriver.csproj b/src/Plugins/BotSharp.Plugin.CodeDriver/BotSharp.Plugin.CodeDriver.csproj new file mode 100644 index 00000000..7b3a8347 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.CodeDriver/BotSharp.Plugin.CodeDriver.csproj @@ -0,0 +1,37 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + + + diff --git a/src/Plugins/BotSharp.Plugin.CodeDriver/CodeDriverPlugin.cs b/src/Plugins/BotSharp.Plugin.CodeDriver/CodeDriverPlugin.cs new file mode 100644 index 00000000..fc4f9d42 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.CodeDriver/CodeDriverPlugin.cs @@ -0,0 +1,22 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace BotSharp.Plugin.CodeDriver; + +public class CodeDriverPlugin : IBotSharpPlugin +{ + public string Id => "c0dedea7-70e3-4c35-a047-18479d7c403e"; + public string Name => "Code Driver"; + public string Description => "Convert the user requirements into corresponding SQL statements"; + public string IconUrl => "https://cdn-icons-png.flaticon.com/512/3176/3176315.png"; + + public string[] AgentIds = + [ + BuiltInAgentId.CodeDriver + ]; + + public void RegisterDI(IServiceCollection services, IConfiguration config) + { + + } +} diff --git a/src/Plugins/BotSharp.Plugin.CodeDriver/Functions/SaveSourceCodeFn.cs b/src/Plugins/BotSharp.Plugin.CodeDriver/Functions/SaveSourceCodeFn.cs new file mode 100644 index 00000000..30b4b1fd --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.CodeDriver/Functions/SaveSourceCodeFn.cs @@ -0,0 +1,49 @@ +using BotSharp.Abstraction.Conversations.Models; +using BotSharp.Abstraction.Functions; +using BotSharp.Plugin.CodeDriver.Models; +using Microsoft.Extensions.DependencyInjection; +using System.Text.Json; + +namespace BotSharp.Plugin.CodeDriver.Functions; + +public class SaveSourceCodeFn : IFunctionCallback +{ + public string Name => "save_source_code"; + + private readonly IServiceProvider _services; + + public SaveSourceCodeFn(IServiceProvider services) + { + _services = services; + } + + public async Task Execute(RoleDialogModel message) + { + var args = JsonSerializer.Deserialize(message.FunctionArgs); + + var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "ai_generated_code"); + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + + var path = Path.GetFullPath(dir, args.FilePath); + var source = args.SourceCode; + + // Delete the file if it exists + File.Delete(path); + + // Create a FileStream with sharing capabilities + using FileStream fs = new FileStream( + path, + FileMode.OpenOrCreate, // Create or overwrite the file + FileAccess.ReadWrite, // Allow read and write operations + FileShare.Read); // Allow other processes to read and write + + // Write some data to the file + using StreamWriter writer = new StreamWriter(fs); + writer.WriteLine(source); + + return true; + } +} diff --git a/src/Plugins/BotSharp.Plugin.CodeDriver/Models/SaveSourceCodeArgs.cs b/src/Plugins/BotSharp.Plugin.CodeDriver/Models/SaveSourceCodeArgs.cs new file mode 100644 index 00000000..9e0a9ae0 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.CodeDriver/Models/SaveSourceCodeArgs.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace BotSharp.Plugin.CodeDriver.Models; + +public class SaveSourceCodeArgs +{ + [JsonPropertyName("file_path")] + public string FilePath { get; set; } = string.Empty; + + [JsonPropertyName("source_code")] + public string SourceCode { get; set; } = string.Empty; +} diff --git a/src/Plugins/BotSharp.Plugin.CodeDriver/Using.cs b/src/Plugins/BotSharp.Plugin.CodeDriver/Using.cs new file mode 100644 index 00000000..73f092b1 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.CodeDriver/Using.cs @@ -0,0 +1,2 @@ +global using BotSharp.Abstraction.Agents.Enums; +global using BotSharp.Abstraction.Plugins; \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/agent.json b/src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/agent.json new file mode 100644 index 00000000..4ed8765c --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/agent.json @@ -0,0 +1,17 @@ +{ + "id": "c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62", + "name": "Code Driver", + "description": "Write executable program code according to user needs, such as HTTP API written in Python.", + "iconUrl": "https://cdn-icons-png.flaticon.com/512/4208/4208366.png", + "type": "task", + "createdDateTime": "2024-10-23T00:00:00Z", + "updatedDateTime": "2024-11-23T00:00:00Z", + "disabled": false, + "isPublic": true, + "profiles": [ "database" ], + "llmConfig": { + "provider": "openai", + "model": "gpt-4o", + "max_recursion_depth": 10 + } +} \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/functions/save_source_code.json b/src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/functions/save_source_code.json new file mode 100644 index 00000000..f0ed5d1b --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/functions/save_source_code.json @@ -0,0 +1,19 @@ +{ + "name": "save_source_code", + "description": "Save the source code to file", + "parameters": { + "type": "object", + "properties": { + "file_path": { + "type": "string", + "description": "source code of file relative path start with project folder name" + }, + + "source_code": { + "type": "string", + "description": "source code" + } + }, + "required": [ "file_path", "source_code" ] + } +} \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/instructions/instruction.liquid b/src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/instructions/instruction.liquid new file mode 100644 index 00000000..92ac6655 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.CodeDriver/data/agents/c0ded7d9-3f9d-4ef6-b7ce-56a892dcef62/instructions/instruction.liquid @@ -0,0 +1,19 @@ +You are a software developer who is good at writing program code according to user needs, such as HTTP API written in Python. + +Current project source code structure is: +my_fastapi_app/ +├── main.py +├── apis/ +│ └── datetime_api.py +├── __init__.py + +You are using below tools and technologies: +* FastAPI framework +* Python programming language +* Swagger Open API + +Your response must meet below requirements: +* Every API should be placed in a separate file under folder of "apis"; +* Call function save_source_code to save the code; +* Write Swagger comments for each API; +* Update main.py to include those updated APIs; diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/SqlDriverPlugin.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/SqlDriverPlugin.cs index 58a382d8..0d4cb96b 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/SqlDriverPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/SqlDriverPlugin.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Agents.Enums; using BotSharp.Abstraction.Planning; namespace BotSharp.Plugin.SqlDriver; @@ -9,6 +10,11 @@ public class SqlDriverPlugin : IBotSharpPlugin public string Description => "Convert the user requirements into corresponding SQL statements"; public string IconUrl => "https://uxwing.com/wp-content/themes/uxwing/download/file-and-folder-type/sql-icon.png"; + public string[] AgentIds = + [ + BuiltInAgentId.SqlDriver + ]; + public void RegisterDI(IServiceCollection services, IConfiguration config) { services.AddScoped(provider => diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/beda4c12-e1ec-4b4b-b328-3df4a6687c4f/agent.json b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/beda4c12-e1ec-4b4b-b328-3df4a6687c4f/agent.json index eb79816f..1d5aca1f 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/beda4c12-e1ec-4b4b-b328-3df4a6687c4f/agent.json +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/beda4c12-e1ec-4b4b-b328-3df4a6687c4f/agent.json @@ -2,6 +2,7 @@ "id": "beda4c12-e1ec-4b4b-b328-3df4a6687c4f", "name": "SQL Driver", "description": "Execute the sql query in database from the latest dialog.", + "iconUrl": "https://cdn-icons-png.flaticon.com/512/3161/3161158.png", "type": "task", "createdDateTime": "2023-11-15T13:49:00Z", "updatedDateTime": "2023-11-15T13:49:00Z", From 127f501771e69dd2959ce3f244348353de0d17ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Fri, 25 Oct 2024 10:12:59 +0800 Subject: [PATCH 12/13] conversation add channelId field --- .../Conversations/Models/Conversation.cs | 7 +++++-- .../Conversations/Services/ConversationService.cs | 4 ++-- .../Collections/ConversationDocument.cs | 2 +- .../Services/TwilioMessageQueueService.cs | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs index c2be970f..5ded2c7c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs @@ -24,12 +24,15 @@ public class Conversation public string Channel { get; set; } = ConversationChannel.OpenAPI; + /// + /// Channel id, like phone number, email address, etc. + /// + public string ChannelId { get; set; } + public int DialogCount { get; set; } public List Tags { get; set; } = new(); - public string CallingPhone { get; set; } - public DateTime UpdatedTime { get; set; } = DateTime.UtcNow; public DateTime CreatedTime { get; set; } = DateTime.UtcNow; } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index a9c56fa9..070f4c59 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -172,12 +172,12 @@ public partial class ConversationService : IConversationService { var state = _services.GetRequiredService(); var channel = state.GetState("channel"); - var callingPhone = state.GetState("calling_phone"); + var channelId = state.GetState("channel_id"); var sess = new Conversation { Id = _conversationId, Channel = channel, - CallingPhone = callingPhone, + ChannelId = channelId, AgentId = agentId }; converation = await NewConversation(sess); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs index b23f26a4..28b0391a 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs @@ -7,10 +7,10 @@ public class ConversationDocument : MongoBase public string? TaskId { get; set; } public string Title { get; set; } public string Channel { get; set; } + public string ChannelId { get; set; } public string Status { get; set; } public int DialogCount { get; set; } public List Tags { get; set; } - public string CallingPhone { get; set; } public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs index fe63ba82..b98f9330 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs @@ -108,6 +108,7 @@ namespace BotSharp.Plugin.Twilio.Services var states = new List { new("channel", ConversationChannel.Phone), + new("channel_id", message.From), new("calling_phone", message.From) }; states.AddRange(message.States.Select(kvp => new MessageState(kvp.Key, kvp.Value))); From f635bbcb496581bc980bc8844fb2150681252682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Fri, 25 Oct 2024 10:18:43 +0800 Subject: [PATCH 13/13] add channelId --- .../Repository/MongoRepository.Conversation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index f0104788..d8159da1 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -17,7 +17,7 @@ public partial class MongoRepository UserId = !string.IsNullOrEmpty(conversation.UserId) ? conversation.UserId : string.Empty, Title = conversation.Title, Channel = conversation.Channel, - CallingPhone = conversation.CallingPhone, + ChannelId = conversation.ChannelId, TaskId = conversation.TaskId, Status = conversation.Status, Tags = conversation.Tags ?? new(),