Skip to content

Commit

Permalink
Improve crossword schema initialization (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
hillary-mutisya authored Dec 13, 2024
1 parent 7a8c027 commit f790c63
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
1 change: 1 addition & 0 deletions ts/packages/agents/browser/src/agent/browserConnector.mts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class BrowserConnector {
parameters: {
fullHTML: false,
downloadAsFile: false,
extractText: false,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ export async function getBoardSchema(

for (let i = 0; i < htmlFragments.length; i++) {
// skip html fragments that are too short to contain crossword
if (
!htmlFragments[i].content ||
htmlFragments[i].content.length < 500 ||
!htmlFragments[i].text ||
htmlFragments[i].text.length < 200
) {
if (!htmlFragments[i].content || htmlFragments[i].content.length < 500) {
continue;
}

Expand Down Expand Up @@ -128,7 +123,7 @@ export async function handleCrosswordAction(

if (selector) {
await browser.clickOn(selector);
await browser.enterTextIn(text);
await browser.enterTextIn(text.replace(/\s/g, "")?.toUpperCase());
message = `OK. Setting the value of ${number} ${direction} to "${text}"`;
} else {
message = `${number} ${direction} is not a valid position for this crossword`;
Expand Down
4 changes: 2 additions & 2 deletions ts/packages/agents/browser/src/agent/crossword/translator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ export class CrosswordPageTranslator<T extends object> {
}

getIsCrosswordPresentPromptSections(fragments?: HtmlFragments[]) {
// const htmlSection = getHtmlPromptSection(fragments);
const htmlSection = getHtmlTextOnlyPromptSection(fragments);
const htmlSection = getHtmlPromptSection(fragments);
// const htmlSection = getHtmlTextOnlyPromptSection(fragments);
const prefixSection = getBootstrapPrefixPromptSection();
const promptSections = [
...prefixSection,
Expand Down
23 changes: 14 additions & 9 deletions ts/packages/agents/browser/src/extension/serviceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ async function getTabHTMLFragments(
targetTab: chrome.tabs.Tab,
fullSize: boolean,
downloadAsFile: boolean,
extractText: boolean,
maxFragmentSize: 16000,
) {
const frames = await chrome.webNavigation.getAllFrames({
Expand All @@ -612,15 +613,18 @@ async function getTabHTMLFragments(
);

if (frameHTML) {
const frameText = await chrome.tabs.sendMessage(
targetTab.id!,
{
type: "get_page_text",
inputHtml: frameHTML,
frameId: frames[i].frameId,
},
{ frameId: frames[i].frameId },
);
let frameText = "";
if (extractText) {
frameText = await chrome.tabs.sendMessage(
targetTab.id!,
{
type: "get_page_text",
inputHtml: frameHTML,
frameId: frames[i].frameId,
},
{ frameId: frames[i].frameId },
);
}

if (downloadAsFile) {
await downloadStringAsFile(
Expand Down Expand Up @@ -1126,6 +1130,7 @@ async function runBrowserAction(action: any) {
targetTab,
action.parameters?.fullHTML,
action.parameters?.downloadAsFile,
action.parameters?.extractText,
16000,
);
break;
Expand Down
27 changes: 17 additions & 10 deletions ts/packages/shell/src/preload/webView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export async function awaitPageLoad() {
*/
}

export async function getTabHTMLFragments(fullSize: boolean) {
export async function getTabHTMLFragments(
fullSize: boolean,
extactText: boolean,
) {
let htmlFragments: any[] = [];
let htmlPromises: Promise<any>[] = [];

Expand Down Expand Up @@ -131,15 +134,18 @@ export async function getTabHTMLFragments(fullSize: boolean) {
for (let i = 0; i < htmlResults.length; i++) {
const frameHTML = htmlResults[i];
if (frameHTML) {
const frameText = await sendScriptAction(
{
type: "get_page_text",
inputHtml: frameHTML,
frameId: i,
},
1000,
frames[i],
);
let frameText = "";
if (extactText) {
frameText = await sendScriptAction(
{
type: "get_page_text",
inputHtml: frameHTML,
frameId: i,
},
1000,
frames[i],
);
}

htmlFragments.push({
frameId: i,
Expand Down Expand Up @@ -303,6 +309,7 @@ async function runBrowserAction(action: any) {
case "getHTML": {
responseObject = await getTabHTMLFragments(
action.parameters.fullHTML,
action.parameters?.extractText,
);

break;
Expand Down

0 comments on commit f790c63

Please sign in to comment.