CrewAI + OpenAI, Ollama, or LM Studio.

Michael Wahl
5 min readJan 17, 2024

This is a quick walkthrough on CrewAI using Ollama, and LM Studio to avoid the costs with OpenAI keys. The code below also contains some samples where we can use tools in terms of search (google or Duckduckgo) for research. Along with scrapping helpful info from Reddit.

Create a new environment, and install Crewai and Duckduckgo. Additional info here about CrewAI https://github.com/joaomdmoura/crewai

python3 -m venv .venv

source .venv/bin/activate

pip install crewai

pip install duckduckgo

A listing of the local models is here https://ollama.ai/library/dolphin-mixtral along with instructions to install on MacOS and Windows.

from langchain.llms import Ollama
from langchain.tools import DuckDuckGoSearchRun
from langchain.tools import tool
from langchain.agents import Tool
from langchain.utilities import GoogleSerperAPIWrapper
from crewai import Agent, Task, Crew, Process
from langchain.chat_models import ChatOpenAI as OpenAI
import os
import praw
import time

#OpenAI API Key
#os.environ["OPENAI_API_KEY"] = "sk-12345ABCD54321"
#os.environ["SERPER_API_KEY"] = "12345ABC54321"

#search = DuckDuckGoSearchRun()
#search = GoogleSerperAPIWrapper()

#Local-MODEL
#Ollama_openhermes = Ollama(model="openhermes")
#Ollama_llama2 = Ollama(model="llama2")

local_openai_client = OpenAI(
base_url="http://localhost:5001/v1", api_key="null", temperature=0
)

#search_tool = Tool(
# name="Immediate Answer",
# func=search.run,
# description="Search the…

--

--

Michael Wahl

Husband | Dad | VP of IT | MBA | Author | AI | #AWSCommunityBuilder | Opinions expressed here are my own | https://michaelwahl.carrd.co