Skip to content

Commit

Permalink
[apps/browser] log time taken to operate browser
Browse files Browse the repository at this point in the history
  • Loading branch information
javierluraschi committed Sep 11, 2024
1 parent deb35d1 commit b9be684
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apps/browser/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ async def main():

await page.setUserAgent(custom_user_agent)

# Get the input and find the site
prompt = h9.input()
site = site_find(prompt)

print(f"Starting new browser session. Navigating to {site}")
await page.goto(site)

while True:
start_time = time.time()
code = "# No code generated"
try:
code = site_use(prompt, page.url)
Expand All @@ -50,12 +50,15 @@ async def main():

await local_vars['dynamic_async_func'](page)

prompt = h9.input(f"Taking screenshot, what next?")
await take_screenshot(page, i)
except Exception as e:
print(f"Failed to use browser:\n```\n{e}\n```\n")
print(f"Available Memory: {(psutil.virtual_memory().available/ (1024 ** 2)):.2f} MB")

prompt = h9.input(f"Taking screenshot for step {i}/5, what next?")
prompt = h9.input(f"Last request failed, should I retry?")
prompt = f"Failed to run the following code:\n\n{code}\n\nCode triggered the following error:\n\n{e}.\n\nAsked users to retry, user replied: " + prompt

h9.event("command", print(f"[{(time.time()-start_time):.1f}s] {prompt[:30]}"))

await browser.close()

Expand Down

0 comments on commit b9be684

Please sign in to comment.