In today's digital landscape, the demand for instant information access has become increasingly critical.
As visitors navigate through websites, their preference goes more toward obtaining quick answers without the need to go through copious amounts of information.
The solution to this challenge can be a chatbot, designed to comprehend a website's content and provide precise answers to user questions.
This article explores the creation of such a chatbot, leveraging web scraping and conversational AI technologies, using MistralAI on CPU.
This article is a follow-up of the previous article: https://developer-service.blog/how-to-build-an-ai-chatbot-for-q-a-on-any-website/
Example of the ChatBot script with a question about https://developer-service.io/:
Human: what is this site about?
Loading answers...
ChatBot: This site offers content services tailored for startups and emerging businesses in technology industries. They provide industry-specific insights, brand voice development, engaging and informative articles, SEO optimization, and even content strategy and planning assistance. Their mission is to equip businesses with the knowledge they need to thrive in a competitive landscape.
Example of interaction with the ChatBot
What is MistralAI?
Mistral AI is a pioneering company specializing in the development of advanced Artificial Intelligence, particularly in the field of large language models.
Based in Paris, France, the company is committed to pushing the boundaries of AI technology with a focus on ethics, safety, and user well-being.
Mistral AI's team comprises experts in machine learning, natural language processing, and other disciplines, working together to create innovative AI solutions that can understand and generate human-like text.
The company's mission is to build AI systems that can help solve complex problems, facilitate communication, and contribute positively to society.
In this article we will be using MistralAI on the CPU through HuggingFace's TheBloke model.
Get the eBook
Inside, you'll discover a plethora of Python secrets that will guide you through a journey of learning how to write cleaner, faster, and more Pythonic code. Whether it's mastering data structures, understanding the nuances of object-oriented programming, or uncovering Python's hidden features, this ebook has something for everyone.
Recap of the Technology Stack
As a refresher, these are the different components and technologies used in the creation of the ChatBot:
Python: Serving as the foundational programming language, Python is celebrated for its ease of use and extensive library ecosystem.
LangChain and MistralAI: For the conversational AI element, we employ LangChain for its conversational retrieval chains and MistralAI for language embeddings and models.
FAISS: A library that facilitates efficient similarity search within large datasets, empowering the chatbot to locate the most pertinent content. Here we will use it with LangChain.
BeautifulSoup and Requests: These instruments are vital for web scraping, enabling us to systematically navigate and gather content from web pages.
Our project encompasses the following files:
search_links.py
: Manages the search of links within the site.create_index.py
: Tasked with indexing website content.chat_bot.py
: Houses the logic governing the chatbot's interactions.main.py
: The primary entry point for executing the chatbot application.
In the next section, we will check the changes necessary to support running the ChatBot with MistralAI on the CPU.
These changes will be contained in the chat_bot.py
file.
chat_bot.py
: The Conversational Engine, now on the CPU
The chat_bot.py
script is the core of the chatbot application, integrating AI and retrieval technologies to engage users with meaningful, contextually relevant interactions.
This script is pivotal for several reasons:
- Conversational Retrieval Chain: It leverages a retrieval chain to understand user queries and fetch appropriate responses from the indexed content.
- Integration with MistralAI: By incorporating MistralAI on the CPU, the script enhances the chatbot's understanding of natural language, allowing for more nuanced interactions.
- Use of FAISS for Efficient Search: The script employs FAISS to rapidly search through content embeddings, ensuring quick and relevant responses.
- Memory Buffer Management: A memory buffer records the context of the conversation, aiding the chatbot in maintaining a coherent and contextually aware dialogue.
Below is the code of the chat_bot.py
script, illustrating how these components are orchestrated (notice the change from running from the MistralAI API to running on the CPU):
This article is for paid members only
To continue reading this article, upgrade your account to get full access.
Subscribe NowAlready have an account? Sign In