Member-only story

Making LLM Web Search Easy: A 5-Minute Guide

Morris Wong
2 min readNov 20, 2024

Photo by Growtika on Unsplash

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(…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Morris Wong
Morris Wong

Written by Morris Wong

Building LLMs and sharing the journey here!

No responses yet

Write a response