To be able to get all the data from a website and make sure it is in the cleanest format, we will use Firecrawl. Firecrawl integrates very easily with Langchain as a document loader.Here is how you can load a website with Firecrawl:
Copy
Ask AI
from langchain_community.document_loaders import FireCrawlLoader # Importing the FirecrawlLoaderurl = "https://firecrawl.dev"loader = FirecrawlLoader( api_key="fc-YOUR_API_KEY", # Note: Replace 'YOUR_API_KEY' with your actual FireCrawl API key url=url, # Target URL to crawl mode="crawl" # Mode set to 'crawl' to crawl all accessible subpages)docs = loader.load()
Next, we will setup the vectorstore. The vectorstore is a data structure that allows us to store and query embeddings. We will use the Ollama embeddings and the FAISS vectorstore.
We split the documents into chunks of 1000 characters each, with a 200 character overlap. This is to ensure that the chunks are not too small and not too big - and that it can fit into the LLM model when we query it.
Now that our documents are loaded and the vectorstore is setup, we can, based on user’s question, do a similarity search to retrieve the most relevant documents. That way we can use these documents to be fed to the LLM model.
Copy
Ask AI
question = "What is firecrawl?"docs = vectorstore.similarity_search(query=question)
Last but not least, you can use the Groq to generate a response to a question based on the documents we have loaded.
Copy
Ask AI
from groq import Groqclient = Groq( api_key="YOUR_GROQ_API_KEY",)completion = client.chat.completions.create( model="llama3-8b-8192", messages=[ { "role": "user", "content": f"You are a friendly assistant. Your job is to answer the users question based on the documentation provided below:\nDocs:\n\n{docs}\n\nQuestion: {question}" } ], temperature=1, max_tokens=1024, top_p=1, stream=False, stop=None,)print(completion.choices[0].message)
You have now built a ‘Chat with your website’ bot using Llama 3, Groq Llama 3, Langchain, and Firecrawl. You can now use this bot to answer questions based on the documentation of your website.If you have any questions or need help, feel free to reach out to us at Firecrawl.