langchain: DOC: Documented example doesn't work
Issue with current documentation:
This is for the documentation page: https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html This does not work in Jupyter or if you download it to a .py file and run it. You do get 2 different errors though. When you run this in Jupyter you get this error:
---------------------------------------------------------------------------
ConfigError Traceback (most recent call last)
Cell In[29], line 3
1 async_browser = create_async_playwright_browser()
2 # sync_browser = None # create_sync_playwright_browser()
----> 3 browser_toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser)
4 tools = browser_toolkit.get_tools()
File ~/Google Drive/PycharmProjectsLocal/pythonProject2/venv/lib/python3.8/site-packages/langchain/agents/agent_toolkits/playwright/toolkit.py:83, in PlayWrightBrowserToolkit.from_browser(cls, sync_browser, async_browser)
81 # This is to raise a better error than the forward ref ones Pydantic would have
82 lazy_import_playwright_browsers()
---> 83 return cls(sync_browser=sync_browser, async_browser=async_browser)
File ~/Google Drive/PycharmProjectsLocal/pythonProject2/venv/lib/python3.8/site-packages/pydantic/main.py:339, in pydantic.main.BaseModel.__init__()
File ~/Google Drive/PycharmProjectsLocal/pythonProject2/venv/lib/python3.8/site-packages/pydantic/main.py:1076, in pydantic.main.validate_model()
File ~/Google Drive/PycharmProjectsLocal/pythonProject2/venv/lib/python3.8/site-packages/pydantic/fields.py:860, in pydantic.fields.ModelField.validate()
ConfigError: field "sync_browser" not yet prepared so type is still a ForwardRef, you might need to call PlayWrightBrowserToolkit.update_forward_refs().
When you run it as a .py file you get this error:
Connected to pydev debugger (build 231.9011.38)
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1496, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/greggwcasey/Google Drive/PycharmProjectsLocal/pythonProject2/structured_chat.py", line 76
response = await agent_chain.arun(input="Hi I'm Erica.")
^
SyntaxError: 'await' outside function
python-BaseException
Idea or request for content:
I would like to have a working example that I could download and run on my Jupyter server or Colab and it work as-is.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 5
- Comments: 15 (5 by maintainers)
Right! In notebooks there is already an event loop running, but in the exported python script that breaks down, so you’d have to either wrap in an async call or function or use a sync browser
Hello folks, I am getting the error while using PlayWrightBrowserToolkit in Google Colab notebook.
##Code:
async_browser = create_async_playwright_browser()
async_browser = create_async_playwright_browser() PlayWrightBrowserToolkit.update_forward_refs() toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser) tools = toolkit.get_tools() tools
##Error NameError Traceback (most recent call last) <ipython-input-17-9143a2bad1f2> in <cell line: 3>() 1 # async_browser = create_async_playwright_browser() 2 async_browser = create_async_playwright_browser() ----> 3 PlayWrightBrowserToolkit.update_forward_refs() 4 toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser) 5 tools = toolkit.get_tools()
9 frames /usr/local/lib/python3.10/dist-packages/langchain/agents/agent_toolkits/playwright/toolkit.py in <module>
NameError: name ‘SyncBrowser’ is not defined
NameError Traceback (most recent call last) <ipython-input-18-9143a2bad1f2> in <cell line: 3>() 1 # async_browser = create_async_playwright_browser() 2 async_browser = create_async_playwright_browser() ----> 3 PlayWrightBrowserToolkit.update_forward_refs() 4 toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser) 5 tools = toolkit.get_tools()
9 frames /usr/local/lib/python3.10/dist-packages/langchain/agents/agent_toolkits/playwright/toolkit.py in <module>
NameError: name ‘SyncBrowser’ is not defined
Can anybody explain, how we can solve this issue??
@kakkar87 No I have not. I am currently looking for another way to pull data from HTML since I think PlayWright is not complete. If you would like to work together on getting something working, DM me. I want to get a tool working that will allow an Agent to get data from a provided url and use it as input to future tasks. I am testing something now but need to fix an unrelated problem first.
Both errors come from your environment and not the code in itself.
The first is related to your
playwright
configuration.The second is related to the iPython version since inline await was a feature added in version 7.