Skip to content

Commit

Permalink
[apps/browser] improve navigation to complex website with many action…
Browse files Browse the repository at this point in the history
…s and escape selectors
  • Loading branch information
javierluraschi committed Jan 13, 2025
1 parent 97caacd commit c3424c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion apps/browser/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hal9 as h9
import shutil
import time
import re

from sitefind import site_find
from siteuse import site_use
Expand Down Expand Up @@ -38,7 +39,13 @@ async def main():
await page.setUserAgent(custom_user_agent)

prompt = h9.input()
site = site_find(prompt)

original_url_match = re.search(r"https?://\S+|\b\S+\.com\b", prompt)
if original_url_match:
site = original_url_match.group(0)
prompt = prompt.replace(site, "<URL>", 1)
else:
site = site_find(prompt)

await page.goto(site)
elements = await extract_elements(page)
Expand Down
4 changes: 3 additions & 1 deletion apps/browser/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
let selector = currentElement.tagName.toLowerCase();

if (currentElement.className) {
selector += '.' + currentElement.className.trim().split(/\s+/).join('.');
selector += '.' + currentElement.className.trim().split(/\s+/).map(e => {
return e.replace(/([:.[\]#,+~*'"()\\\/=])/g, '\\$1');
}).join('.');
}

path.unshift(selector);
Expand Down
2 changes: 1 addition & 1 deletion apps/browser/siteuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def site_use(prompt, current, elements):
""" }
]

completion = OpenAI().chat.completions.create(model = "gpt-4", messages = messages)
completion = OpenAI().chat.completions.create(model = "gpt-4-0125-preview", messages = messages)
content = completion.choices[0].message.content
extracted = h9.extract(content, language = "*")
if not extracted or len(extracted) == 0:
Expand Down

0 comments on commit c3424c6

Please sign in to comment.