Member-only story
Making LLM Web Search Easy: A 5-Minute Guide
Building an LLM that can search the web is surprisingly straightforward. This guide will show you how to do it in just five minutes.
Installation: Quick Setup
First, install the necessary Python packages:
%%capture
%pip install -qU langchain-groq
%pip install -qU langchain
%pip install -qU langchain-community
%pip install -qU duckduckgo-search
LLM Setup: Leveraging Groq’s Speed
We’ll use Groq for this example due to its speed. Here’s the setup code:
import os
from langchain_groq import ChatGroq
os.environ["GROQ_API_KEY"] = "API_KEY"
llm = ChatGroq(
model="mixtral-8x7b-32768",
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
)
This code initializes the ChatGroq LLM, setting parameters for model, temperature, and retries.
Tool Integration: DuckDuckGo Search
Next, we’ll integrate the DuckDuckGo search engine as a tool:
from langchain.agents import initialize_agent
from langchain_community.tools import Tool, DuckDuckGoSearchRun, DuckDuckGoSearchResults
from langchain.agents import Tool
ddg_search = DuckDuckGoSearchResults()
tools = [
Tool(…