stitionai / devika

Devika is an Agentic AI Software Engineer that can understand high-level human instructions, break them down into steps, research relevant information, and write code to achieve the given objective. Devika aims to be a competitive open-source alternative to Devin by Cognition AI.
MIT License
18.37k stars 2.38k forks source link

Problems with playwright in Docker #279

Open Guerdal opened 6 months ago

Guerdal commented 6 months ago

Describe the bug By launching a new project with the latest version published on March 31 at 2:22 PM, access to the model via ollama works fine. Devika gives me a plan to create the snake game code in python then tries to search the Internet with DuckDuckGo and at this point an error message appears in console :

devika-backend-engine-1  | research ::  {'queries': ['Python Turtle Module Documentation', 'How to generate random locations on a game window in Python'], 'ask_user': ''} 
devika-backend-engine-1  | 
devika-backend-engine-1  | 24.03.31 18:22:29: root: INFO   : SOCKET server-message MESSAGE: {'messages': {'from_devika': True, 'message': 'I am browsing the web to research the following queries: Python Turtle Module Documentation, How to generate random locations on a game window in Python.\n If I need anything, I will make sure to ask you.', 'timestamp': '2024-03-31 18:22:29'}}
devika-backend-engine-1  | 24.03.31 18:22:29: root: INFO   : SOCKET agent-state MESSAGE: [{'internal_monologue': None, 'browser_session': {'url': None, 'screenshot': None}, 'terminal_session': {'command': None, 'output': None, 'title': None}, 'step': None, 'message': None, 'completed': False, 'agent_is_active': True, 'token_usage': 2300, 'timestamp': '2024-03-31 18:22:09'}, {'internal_monologue': "I'm currently working on creating a Python Snake Game following your instructions. I first need to understand the basics of python programming and game development principles to get started with this project. The main goal is to create an interactive, educational experience for users.", 'browser_session': {'url': None, 'screenshot': None}, 'terminal_session': {'command': None, 'output': None, 'title': None}, 'step': None, 'message': None, 'completed': False, 'agent_is_active': True, 'token_usage': 1141, 'timestamp': '2024-03-31 18:22:26'}]
devika-backend-engine-1  | 24.03.31 18:22:29: root: INFO   : Search : duckduckgo
devika-backend-engine-1  | Exception in thread Thread-5 (<lambda>):
devika-backend-engine-1  | Traceback (most recent call last):
devika-backend-engine-1  |   File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
devika-backend-engine-1  |     self.run()
devika-backend-engine-1  |   File "/usr/lib/python3.11/threading.py", line 975, in run
devika-backend-engine-1  |     self._target(*self._args, **self._kwargs)
devika-backend-engine-1  |   File "/home/nonroot/devika/devika.py", line 94, in <lambda>
devika-backend-engine-1  |     thread = Thread(target=lambda: agent.execute(message, project_name, search_engine))
devika-backend-engine-1  |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/src/agents/agent.py", line 336, in execute
devika-backend-engine-1  |     search_results = self.search_queries(queries, project_name, engine)
devika-backend-engine-1  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/src/agents/agent.py", line 82, in search_queries
devika-backend-engine-1  |     browser = Browser()
devika-backend-engine-1  |               ^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/src/browser/browser.py", line 13, in __init__
devika-backend-engine-1  |     self.playwright = sync_playwright().start()
devika-backend-engine-1  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/sync_api/_context_manager.py", line 85, in start
devika-backend-engine-1  |     return self.__enter__()
devika-backend-engine-1  |            ^^^^^^^^^^^^^^^^
devika-backend-engine-1  |   File "/home/nonroot/devika/.venv/lib/python3.11/site-packages/playwright/sync_api/_context_manager.py", line 48, in __enter__
devika-backend-engine-1  |     raise Error(
devika-backend-engine-1  | playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
devika-backend-engine-1  | Please use the Async API instead.

To Reproduce Steps to reproduce the behavior:

  1. Launcher devika in docker : docker compose up -d
  2. Click on New Project
  3. Select DuckDuckGo in WebSearch
  4. Select an Ollama Model (Deppseekcoder for me)
  5. Write 'Write a snake game in python'
  6. Wait the process and See error

Expected behavior Devika use Chromium or Firefox to made searches

Screenshots No screenshots

Desktop (please complete the following information):

darcome commented 6 months ago

I got the same erorr too... any suggestion?

schueszy commented 6 months ago

@darcome @Guerdal

Can you replace in the devika.dockerfile

RUN playwright install --with-deps

to:

RUN playwright install
RUN playwright install-deps

and between:

USER nonroot
WORKDIR /home/nonroot/devika

add:

RUN playwright install

should looks like:

USER nonroot
RUN playwright install
WORKDIR /home/nonroot/devika

then run:

docker compose up --build

Please let me know if it works.

source: https://github.com/microsoft/playwright-python/issues/462

Guerdal commented 6 months ago

Hello I have already made this change in devika.dockerfile, I think the problem came with #24 and the use of socket.io. But maybe I'm wrong. And my lack of skills in python code can't help me to correct this :-)

darcome commented 6 months ago

I am running devika without docker and I have run those commands manually but it didn't solve the problem.

Let me know if you want me to run some commands to give you some logs or info

ARajgor commented 5 months ago

So current has the async playwright so it is working but not sure about docker file. I'll update when we have perfect docker files