Skip to content

Starter repository for the RPC-01: Internal Chatbot with Role Based Access Control

Notifications You must be signed in to change notification settings

siddu28/ds-rpc-01

 
 

Repository files navigation

DS RPC 01: Internal chatbot with role based access control

Problem Statement:

This project is a role-based chatbot application built using FastAPI, Streamlit, and LangChain + Groq LLM. It restricts users to ask questions only within their role-based access level. For example, an HR user can only query HR-related documents, while Engineering can only access Engineering-related data.

alt text

Roles Provided

  • engineering
  • finance
  • general
  • hr
  • marketing

Project Structure:

project/
│
├── app/
│ └── services.py ← Core LLM + VectorDB logic
│
├── main.py ← FastAPI API (login, chat endpoints)
├── streamlit_app.py ← Streamlit UI (frontend)
│
├── resources/
│ └── data/ ← Department-wise document sources
│ ├── engineering/
│ ├── hr/
│ ├── finance/
│ └── marketing/
│
└── resource/
└── vectorstore/ ← Vector database for Chroma

🚀 Project Flow Overview

📁 1. Document Preparation and Processing All documents are stored in the resources/data folder, organized by department (e.g., hr, marketing, engineering).

The process() function:

  • Loads all department-wise files (Markdown/CSV).
  • Splits them into smaller chunks using LangChain's RecursiveCharacterTextSplitter.
  • Adds metadata like department name and allowed roles.
  • Stores them in Chroma vector store after generating embeddings using HuggingFace.

🧠 2. LLM and Vector Store Initialization On the first question or document processing:

  • The Groq API (LLaMA 3 model) is initialized.
  • Vector store is created using ChromaDB.
  • Embeddings are generated using all-MiniLM-L6-v2.
  • Then we can filter the documents based on the metadata , inorder to restrict the role based questions

🔐 3. FastAPI Backend (main.py) FastAPI server handles:

  • User Login (/login) using basic HTTP authentication.
  • Protected Chat Route (/chat):
  • Checks the user's role.
  • Runs a similarity search on documents using ChromaDB.
  • Filters results based on user role.
  • Sends allowed documents to the LLM to generate an answer.

💻 4. Streamlit Frontend (app.py) Simple login page where users can enter their username and password. On successful login:

  • They are redirected to a chatbot interface and asks to enter the username and password to check the credentials , I have a dummy user database , so i restricted upto some few people
  • Users can enter questions and receive role-based answers.
  • Supports logout to switch between user roles.

📮 Postman Testing (Backend API) You can use Postman to test the HTTP endpoints like /login and /chat. 🔸 Screenshot: Testing /login endpoint using Postman: Image Image

🔸 Screenshot: checking wheather engineering team person can access finantial questions: Image

🖥️ Streamlit Frontend (Chatbot UI) Once the backend is running, you can launch the chatbot interface via Streamlit. 🔸 Screenshot: Streamlit UI after successful login Image

🔸 Screenshot: checking wheather engineering team person can access finantial questions: Image

✨ Tech Stack

  • Frontend: Streamlit
  • Backend: FastAPI
  • LLM: LLaMA-3.3 70B via Groq API
  • Vector Store: ChromaDB
  • Embeddings: HuggingFace Transformers
  • LangChain: Document loading, QA chain, chunking
  • Postman: Manual API testing
  • Dotenv: Secure API key loading

Setup Instructions

  1. Clone the repository:

    https://github.com/siddu28/ds-rpc-01
    
  2. Install dependencies::

     pip install -r requirements.txt
    
  3. Run the fastapi server::

     uvicorn app.main:app --reload
    
  4. Run the streamlit app::

     streamlit run streamlit_app.py
    

About

Starter repository for the RPC-01: Internal Chatbot with Role Based Access Control

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%