This is a Python-based financial chatbot equipped with Retrieval-Augmented Generation (RAG). The chatbot seamlessly interacts with users, addressing financial queries by combining the top insights from online sources with the user's input.
The financial chatbot follows the following workflow to ensure efficiency, accuracy and currency of information:
- User Query: Receive and process the user's financial question.
- Summarization: Summarize lengthy user prompts for an enhanced online search experience.
- Google Search: Perform a Google search to extract the top 3 results within a specific time frame.
- Web Scraping: Utilize Selenium to extract text content from the searched websites (Chrome installation required).
- Text Refinement: Eliminate short paragraphs, duplicates, and unnecessary new lines to ensure superior information quality from web scraping.
- Semantic Search: Employ the robust 'all-mpnet-base-v2' model to encode the user query and online sources, thereby enhancing semantic search capabilities. Utilize the most relevant parts of the new sources.
- Summarization (Again): Independently summarize top-related paragraphs to prevent information loss and optimize the responsiveness of the chatbot.
- Prompt Engineering: Combine the user query and summarized paragraphs using prompt engineering.
- Qwen Model: Leverage the high-quality "Qwen/Qwen-14B-Chat-Int4" model for response generation.
- Response and References: Provide the user with the generated response and references.
To employ the financial chatbot, follow these simple steps:
- Clone the repository and go to the downloaded file.
git clone https://github.com/FzS92/FS_chatbot_rag.git
cd FS_chatbot_rag
- Create a new enviornment and install the required dependencies:
conda create -n fschat python=3.8
conda activate fschat
pip install -r requirements.txt
Optional: To enhance efficiency and reduce memory usage, you can install the following dependencies:
git clone https://github.com/Dao-AILab/flash-attention
cd flash-attention && pip install .
pip install csrc/layer_norm
pip install csrc/rotary
- Run the
main.py
script.
python main.py
You will see some links in the terminal. Click on the first link to launch the Gradio ChatInterface. Pose financial questions and witness the chatbot responding with the top online information!