From 980138edad3ddaa7d95042bb484f3d380ed47a02 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Wed, 24 Jul 2024 23:08:30 -0500 Subject: [PATCH] refine file selection prompt --- .../BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs | 3 --- .../Functions/HandleEmailRequestFn.cs | 5 +++-- .../templates/select_attachment_prompt.liquid | 10 +++++----- .../templates/select_edit_image_prompt.liquid | 3 +-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs index 99bb19372..5b699b510 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs @@ -1,9 +1,6 @@ using Microsoft.AspNetCore.SignalR; using System.Text.Encodings.Web; using System.Text.Unicode; -using Newtonsoft.Json.Linq; -using JsonConvert = Newtonsoft.Json.JsonConvert; -using JsonSerializerSettings = Newtonsoft.Json.JsonSerializerSettings; namespace BotSharp.Plugin.ChatHub.Hooks; diff --git a/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailRequestFn.cs b/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailRequestFn.cs index 84be6e168..9f8406a8b 100644 --- a/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailRequestFn.cs +++ b/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailRequestFn.cs @@ -95,7 +95,7 @@ private async Task> SelectFiles(IEnumerable { - return $"id: {idx + 1}, file_name: {x.FileName}.{x.FileType}, author: {x.FileSource}, content_type: {x.ContentType}"; + return $"id: {idx + 1}, file_name: {x.FileName}.{x.FileType}, content_type: {x.ContentType}, author: {x.FileSource}"; }).ToList(); var prompt = db.GetAgentTemplate(BuiltInAgentId.UtilityAssistant, "select_attachment_prompt"); prompt = render.Render(prompt, new Dictionary @@ -113,7 +113,8 @@ private async Task> SelectFiles(IEnumerable x == "openai"); var model = llmProviderService.GetProviderModel(provider: provider, id: "gpt-4"); var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model.Name); - var response = await completion.GetChatCompletions(agent, dialogs); + var latest = dialogs.LastOrDefault(); + var response = await completion.GetChatCompletions(agent, new List { latest }); var content = response?.Content ?? string.Empty; var selecteds = JsonSerializer.Deserialize(content); var fids = selecteds?.Selecteds ?? new List(); diff --git a/src/Plugins/BotSharp.Plugin.EmailHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/select_attachment_prompt.liquid b/src/Plugins/BotSharp.Plugin.EmailHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/select_attachment_prompt.liquid index f96e286ae..f4295baa4 100644 --- a/src/Plugins/BotSharp.Plugin.EmailHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/select_attachment_prompt.liquid +++ b/src/Plugins/BotSharp.Plugin.EmailHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/select_attachment_prompt.liquid @@ -9,12 +9,12 @@ Here is the JSON format to use: "selected_ids": a list of id selected from the [FILES] section } -Suppose there are 4 files: +Suppose there are four files: -id: 1, file_name: example_file.jpg, author: user, content_type: image/jpeg -id: 2, file_name: example_file.pdf, author: user, content_type: application/pdf -id: 3, file_name: example_file.png, author: bot, content_type: image/png -id: 4, file_name: example_file.png, author: bot, content_type: image/png +id: 1, file_name: example_file.jpg, content_type: image/jpeg, author: user +id: 2, file_name: example_file.pdf, content_type: application/pdf, author: user +id: 3, file_name: example_file.png, content_type: image/png, author: bot +id: 4, file_name: example_file.png, content_type: image/png, author: bot ===== Example 1: diff --git a/src/Plugins/BotSharp.Plugin.FileHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/select_edit_image_prompt.liquid b/src/Plugins/BotSharp.Plugin.FileHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/select_edit_image_prompt.liquid index 4d0505634..9e67faade 100644 --- a/src/Plugins/BotSharp.Plugin.FileHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/select_edit_image_prompt.liquid +++ b/src/Plugins/BotSharp.Plugin.FileHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/select_edit_image_prompt.liquid @@ -1,5 +1,4 @@ Please take a look at the images in the [IMAGES] section from the conversation and select ONLY one image based on the conversation with user. -Your response must be an interger number. ** Ensure the output is only in JSON format without any additional text. ** You may need to look at the image_name as a reference to find the correct image id. @@ -10,7 +9,7 @@ Here is the JSON format to use: } -Suppose there are three images: +Suppose there are four images: id: 1, image_name: example_image_a.png id: 2, image_name: example_image_b.png