crewAIInc / crewAI-examples

A collection of examples that show how to use CrewAI framework to automate workflows.
2.88k stars 1.1k forks source link

Browserless dependency #22

Closed Guerdal closed 9 months ago

Guerdal commented 10 months ago

Hello,

CrewAI is a magnificent project, I am trying to make it work with as little dependence on online services as possible.

So is it possible to replace the browserless (https://www.browserless.io/) dependency with the docker image browserless/chrome:latest? And if so, how? Thank you in advance.

DannySpringer commented 10 months ago

CrewAI Browserless Integration Guide

Introduction

This guide provides step-by-step instructions on how to replace the browserless.io dependency with the Docker image browserless/chrome:latest in the CrewAI project.

Setup and Configuration

1. Setting Up Docker Container for Browserless

Run the following command to start the Browserless Docker container:

$ docker run -p 8080:3000 --restart always -d --name browserless browserless/chrome

This command maps the local port 8080 to the container's port 3000 and ensures the container restarts automatically. For more details, refer to the Browserless Docker documentation.

2. Verifying the Docker Container Setup

To check if the Browserless service is running, execute the Python script below. Ensure you have websocket-client installed (pip install websocket-client):

import websocket
import json

try:
    ws = websocket.create_connection("ws://localhost:8080")
    ws.send(json.dumps({"id": 1, "method": "Browser.getVersion"}))

    while True:
        response = ws.recv()
        if response:
            print("Received:", response)
            break

except Exception as e:
    print("Exception:", e)
finally:
    ws.close()

3. Integrating with CrewAI

Update the scrape_and_summarize_website function in ./crewAI-examples/trip_planner/tools/browser_tools.py:

class BrowserTools():

    @tool("Scrape website content")
    def scrape_and_summarize_website(website):
        """Scrape and summarize a website's content"""
        # Change from remote Browserless service to local Docker instance
        url = f"http://localhost:8080/content" # Local Docker instance URL

        ...

For reference, visit the CrewAI GitHub repository.

Conclusion

By following these steps, you can successfully integrate the Browserless Docker container into the CrewAI project. For further assistance or queries, feel free to reach out.

Note: This was generated using GPT4.

Biancamazzi commented 9 months ago

If you haven't solved it yet, could you please create an issue at https://github.com/joaomdmoura/crewAI/issues? Let's focus on addressing issues there.

shuther commented 4 months ago

could it be possible to have the url for browserless in .env?