Revert all changes

This commit is contained in:
Wenbo Cao 2025-04-01 10:27:31 -05:00
parent d0b4a49a29
commit d2bba95f47
6 changed files with 4 additions and 77 deletions

View file

@ -31,9 +31,6 @@
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-web-close_browser.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-web-extract_data_from_page.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-web-go_to_page.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -106,10 +103,4 @@
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-web-extract-data.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View file

@ -9,11 +9,8 @@ public partial class PlaywrightWebDriver
await Task.Delay(3000);
// Retrieve the page raw html and infer the element path
var pageContent = _instance.GetPage(actionParams.ContextId);
var body = await pageContent.QuerySelectorAsync("body");
var pageUrl = pageContent.Url;
var pageBody = await body.InnerTextAsync();
string content = $"Page URL: `{pageUrl}` <br/> PageBody: {pageBody}";
var body = await _instance.GetPage(actionParams.ContextId).QuerySelectorAsync("body");
var content = await body.InnerTextAsync();
var driverService = _services.GetRequiredService<WebDriverService>();
var answer = await driverService.ExtraData(actionParams.Agent, content, actionParams.Context.Question, actionParams.MessageId);

View file

@ -7,7 +7,6 @@ public class WebUtilityHook : IAgentUtilityHook
private const string GO_TO_PAGE_FN = $"{PREFIX}go_to_page";
private const string LOCATE_ELEMENT_FN = $"{PREFIX}locate_element";
private const string ACTION_ON_ELEMENT_FN = $"{PREFIX}action_on_element";
private const string EXTRACT_DATA_FN = $"{PREFIX}extract_data_from_page";
public void AddUtilities(List<AgentUtility> utilities)
{
@ -21,8 +20,7 @@ public class WebUtilityHook : IAgentUtilityHook
new(CLOSE_BROWSER_FN),
new(GO_TO_PAGE_FN),
new(LOCATE_ELEMENT_FN),
new(ACTION_ON_ELEMENT_FN),
new(EXTRACT_DATA_FN)
new(ACTION_ON_ELEMENT_FN)
],
Templates =
[

View file

@ -45,7 +45,7 @@ public class UtilWebActionOnElementFn : IFunctionCallback
};
var result = await browser.ActionOnElement(msg, locatorArgs, actionArgs);
message.Content = $"{actionArgs.Action} executed {(result.IsSuccess ? "success" : "failed")}";
message.Content = $"{actionArgs.Action} executed {(result.IsSuccess ? "success" : "failed")}. Current page url: '{result.UrlAfterAction}'.";
var path = webDriverService.GetScreenshotFilePath(message.MessageId);

View file

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Playwright;
namespace BotSharp.Plugin.WebDriver.UtilFunctions
{
public class UtilWebExtractDataFn : IFunctionCallback
{
public string Name => "util-web-extract_data_from_page";
public string Indication => "Util Web Extract Data from web page";
private readonly IServiceProvider _services;
public UtilWebExtractDataFn(
IServiceProvider services)
{
_services = services;
}
public async Task<bool> Execute(RoleDialogModel message)
{
var convService = _services.GetRequiredService<IConversationService>();
var args = JsonSerializer.Deserialize<BrowsingContextIn>(message.FunctionArgs);
var agentService = _services.GetRequiredService<IAgentService>();
var agent = await agentService.LoadAgent(message.CurrentAgentId);
var _browser = _services.GetRequiredService<IWebBrowser>();
var webDriverService = _services.GetRequiredService<WebDriverService>();
var contextId = webDriverService.GetMessageContext(message);
var browerActionParams = new BrowserActionParams(agent, args, contextId, message.MessageId);
message.Content = await _browser.ExtractData(browerActionParams);
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
message.Data = await _browser.ScreenshotAsync(new MessageInfo
{
AgentId = message.CurrentAgentId,
ContextId = contextId,
MessageId = message.MessageId
}, path);
return true;
}
}
}

View file

@ -1,14 +0,0 @@
{
"name": "util-web-extract_data_from_page",
"description": "Extract data from current web page.",
"parameters": {
"type": "object",
"properties": {
"question": {
"type": "string",
"description": "the information user wants to know"
}
},
"required": [ "question" ]
}
}