crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
21.15k stars 2.94k forks source link

[Not a issue] Add local tools for CrewAI example instragram #218

Closed Guerdal closed 9 months ago

Guerdal commented 9 months ago

CrewAI is a fantastic project. However, I tried to work on the instagram_post example (https://github.com/joaomdmoura/crewAI-examples/tree/main/instagram_post) to make it run with minimal cloud-dependent tools.

Here are some ideas, tools and code modifications of the example that allow it to work locally.

The base example works with ChatGPT, so I made a simple first modification (other examples work this way) to work with Ollama and the Openchat2.5 model.

In the agents.py file:

line 13 : self.llm = Ollama(base_url='http://IP_of_Ollama_Server:11434',model='openchat')

Then the example uses two online tools: browserless.io and serper.dev.

To replace them, I installed the Docker version of browserless.io (https://www.browserless.io/docs/docker-quickstart) and openserp (https://github.com/karust/openserp)

Browserless will be accessible via the URL http://IP_server:9222 and Openserp will be accessible via the URL http://IP_server:7000

To make it work, I modified the following files:

browsertools.py

line 17 : url = f"http://IP_Server:9222/content"

line 32 : llm=Ollama(base_url='http://IP_of_Ollama_Server:11434',model='openchat'),

search_tools.py

starting from line 23:

def search(query, n_results=5): url = "http://IP_server:7000/google/search?limit=20&lang=FR&text="+query

response = requests.request("GET", url)
results = response.json()
stirng = []
for result in results[:n_results]:
  try:
    stirng.append('\n'.join([
        f"Title: {result['title']}", f"Link: {result['url']}",
        f"Snippet: {result['description']}", "\n-----------------"
    ]))
  except KeyError:
    next

Openserp works with GET, so I modified the search function that used POST.

If some people want to exchange or have ideas for improvement or tools that can run locally (ideally in Docker), they don't hesitate to contribute to this great tool which is CrewAI.

joaomdmoura commented 9 months ago

I like it, sounds like a good example, maybe you could open a PR with it int eh examples repo so we can add it there?