One of the most time-consuming aspects of customer support is finding the right information and providing precise answers. To streamline this, I recently developed a smart support system that combines a chatbot powered by GPT-3.5-turbo, document retrieval for context-aware responses, automatic email generation, and an added capability to track sources for each response.
This project was built to tackle the everyday frustrations that customer service teams face—answering repetitive questions, searching through internal documents, and drafting follow-up emails. By integrating advanced document retrieval and email generation features, this system not only responds to customer queries but also pulls information directly from documents and websites, ensuring responses are accurate and well-supported. And to ensure accountability, every response the bot gives is traceable back to its source, so the user can always verify where the information came from.
Let’s walk through the motivation, implementation, and step-by-step breakdown of this project.
In my experience, customer support teams often struggle with three key pain points:
This system was designed to streamline all three tasks:
At the core of this system is a GPT-3.5-turbo-powered chatbot. What makes it stand out is its ability to answer customer questions not just with generic responses, but by retrieving and using information from uploaded documents or web URLs. This makes the answers highly relevant and trustworthy.
@app.route('/', methods=['POST']) def index(): question = data.get('question') docs_and_scores = vector_search.similarity_search(question, k=10) # Perform search in docs context = "".join([doc.page_content for doc, _ in docs_and_scores]) # Use GPT to respond with this context response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[{"role": "system", "content": f"Context: {context}"}, {"role": "user", "content": question}] ) return response
With the help of FAISS and LangChain, the bot searches through PDFs, DOCX files, and web pages, finds relevant sections, and feeds that into GPT for accurate, context-aware responses.
The system’s document retrieval is what makes the chatbot particularly powerful. Using LangChain for document loading and FAISS for fast similarity searches, the bot retrieves answers from pre-loaded PDFs, Word docs, or even web URLs.
class TextSplitter: def __init__(self, chunk_size=1000, chunk_overlap=200): # Initialize the text splitter with chunk size and overlap settings self.text_splitter = RecursiveCharacterTextSplitter( chunk_size=chunk_size, chunk_overlap=chunk_overlap, separators=["\n\n", "\n", ".", "!", "?", ",", " ", ""] ) def split_documents(self, documents): try: # Split documents into smaller chunks for better processing return self.text_splitter.split_documents(documents) except Exception as e: # Log any errors that occur during document splitting logging.error(f"Error splitting documents: {str(e)}") return []
This system turns what would otherwise be static documents into a live knowledge base that the bot can draw from to answer customer queries.
This code also performs a similarity search to find relevant documents based on a user's question, filters them using a threshold, and handles cases where no relevant documents are found.
docs_and_scores = vector_search.similarity_search(question, k=10)
SIMILARITY_THRESHOLD = 0.2 relevant_docs = [doc for doc, score in docs_and_scores if score >= SIMILARITY_THRESHOLD]
This block filters the results, only keeping documents that have a similarity score of 0.2 or higher. Documents with lower scores are considered irrelevant.
If no relevant documents meet the threshold, the bot provides a fallback answer like "I don't have the information”.
One of the standout features of this project is the ability to automatically generate professional customer support emails based on the chatbot’s conversation. Once the bot resolves an issue, it can draft a follow-up email using the response.
@app.route('/generate_email', methods=['POST']) def generate_email(): last_bot_message = chat_history[-1][1] # Get the bot's last message email_prompt = f"Write a professional support email based on: {last_bot_message}" email_response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": email_prompt}] ) return email_response
The emails are formatted in valid HTML, ensuring they’re ready to be sent or integrated with other systems immediately.
One of the features I’m particularly proud of is source tracking. Every response the bot gives is backed by the documents it retrieved the information from, ensuring full transparency. At the end of each response, the bot lists its sources so users can verify the information.
sources = set([doc.metadata.get('source', 'Unknown source') for doc, _ in docs_and_scores]) response += f"\nSources: {', '.join(sources)}"
This feature boosts trustworthiness, especially when the bot is answering detailed or technical questions.
The front-end was built with simplicity in mind, using JavaScript to manage real-time user interaction. Users can easily ask questions, receive streamed responses from the bot, and copy responses with a single click.
// Add a copy button to each bot message function addCopyButton(messageElement) { const copyButton = document.createElement('button'); copyButton.innerText = 'Copy'; copyButton.onclick = () => copyToClipboard(messageElement.innerText); messageElement.appendChild(copyButton); }
This ensures that the chatbot not only provides useful answers but also allows users to quickly copy and share those responses with others.
This project has a number of key benefits:
Feel free to explore the code
[Implementation](Link text)
The smart support system I built is more than just a chatbot—it’s a complete customer support solution. By integrating document retrieval, AI-powered chat, and email generation, it significantly streamlines the support process. The ability to track sources further ensures transparency, making it an invaluable tool for customer service teams.
Looking ahead, I see endless opportunities to expand this system—whether by integrating live email-sending capabilities or adding support for even more document types or expanding vector base with pinecone or even finetuning the model based on domain specifications. This project showcases how AI can help customer support teams work more efficiently, all while providing a better experience for customers
There are no datasets linked
There are no models linked
There are no datasets linked
There are no models linked