Skip to content

Commit

Permalink
Fix: local files in the browser (at least for Windows) (All-Hands-AI#839
Browse files Browse the repository at this point in the history
)

* Fix: local files in the browser (at least for Windows)

The Browser works for screenshoting websites, but when the LLM tries to display a local file that he created, it can't access the full directory on Windows.

* Update browse.py

---------

Co-authored-by: Robert Brennan <accounts@rbren.io>
  • Loading branch information
Redrum624 and rbren committed Apr 12, 2024
1 parent 9cd4ad3 commit 9fd95cc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions opendevin/action/browse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import base64
from dataclasses import dataclass
from opendevin.observation import BrowserOutputObservation
Expand All @@ -17,11 +18,14 @@ class BrowseURLAction(ExecutableAction):
action: str = ActionType.BROWSE

async def run(self, controller: "AgentController") -> BrowserOutputObservation: # type: ignore
asked_url = self.url
if not asked_url.startswith("http"):
asked_url = os.path.abspath(os.curdir) + self.url
try:
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
response = await page.goto(self.url)
response = await page.goto(asked_url)
# content = await page.content()
inner_text = await page.evaluate("() => document.body.innerText")
screenshot_bytes = await page.screenshot(full_page=True)
Expand All @@ -31,14 +35,18 @@ async def run(self, controller: "AgentController") -> BrowserOutputObservation:
return BrowserOutputObservation(
content=inner_text, # HTML content of the page
screenshot=screenshot_base64, # Base64-encoded screenshot
url=self.url,
url=asked_url,
status_code=response.status if response else 0, # HTTP status code
)
except Exception as e:
return BrowserOutputObservation(
content=str(e), screenshot="", error=True, url=self.url
content=str(e),
screenshot="",
error=True,
url=asked_url
)


@property
def message(self) -> str:
return f"Browsing URL: {self.url}"

0 comments on commit 9fd95cc

Please sign in to comment.