Building an Intelligent Co-worker Chatbot for Microsoft Teams with Hugging Face LLM and Python Django

Large enterprises often face complex cloud migrations of their business applications. Software engineering teams in such enterprises need quick, smart tools to address their queries related to ongoing cloud migration, offering the best documentation, syntax help, and next best actions.

Software developers can significantly boost productivity through a smart assistant, a.k.a. Co-Worker Chatbot. This tool can help them navigate complex migration processes, configurations, and documentation specific to the enterprise.

This blog post explores a reference architecture for a smart assistant application, integrated into Microsoft Teams, using Hugging Face’s Large Language Models (LLM), Django, and MongoDB, all deployed on cloud platforms such as AWS, Azure, or GCP.

Overview

The primary goal of this application is to assist software developers with questions related to cloud migration by leveraging a custom LLM fine-tuned on public documentation from AWS, Azure, and GCP. The application consists of several components, including a Microsoft Teams app, a Django-based backend, and a FastAPI service for LLM inference.

Key Features

  • Microsoft Teams Integration: The chatbot is accessible directly within Microsoft Teams.
  • Custom LLM: Fine-tuned on cloud service documentation to provide accurate and relevant responses.
  • Django Backend: Manages API requests and business logic.
  • MongoDB: Stores user queries, responses, and logs.
  • Cloud Deployment: Hosted on AWS, Azure, or GCP for scalability and reliability.

High-Level Architecture

1. Microsoft Teams Integration

The application starts with a custom Microsoft Teams app that allows users to interact with the chatbot. The Teams app uses the Microsoft Bot Framework to handle communication between the user and the backend services.

2. Django Backend

The core backend service is developed using Django, providing API endpoints to handle user queries. It processes the requests, interacts with the LLM service, and returns responses to the user. MongoDB is used for storing data such as query logs and user interactions.

3. Custom LLM Integration

A custom LLM is fine-tuned using Hugging Face models on public documentation from AWS, Azure, and GCP. This model is deployed as a separate microservice using FastAPI, which handles inference requests from the Django backend.

4. Cloud Services

The entire application is containerized using Docker and deployed on cloud platforms like AWS, Azure, or GCP, ensuring scalability and high availability. Kubernetes or cloud-native orchestration services like AWS ECS, Azure AKS, or GCP GKE manage the deployment.

Detailed Architecture Components

Microsoft Teams Integration

  • Teams App Manifest: Defines the app configuration, bot registration, and API endpoints.
  • Bot Framework: Manages communication between Teams and the backend.

Django Backend

  • API Endpoints: Defined for various functionalities such as querying the LLM, logging interactions, and managing configurations.
  • Business Logic: Processes incoming requests, interacts with the LLM service, and handles the business logic.
  • Database Integration: Uses MongoDB for data persistence.

Custom LLM Service

  • Data Collection: Aggregates public documentation from cloud providers.
  • Model Fine-Tuning: Fine-tunes a pre-trained LLM from Hugging Face.
  • Inference Service: Deployed using FastAPI, handling inference requests from the backend.

Cloud Deployment

  • Containerization: Uses Docker to containerize the Django app, LLM service, and MongoDB.
  • Orchestration: Managed by Kubernetes or cloud-native orchestration services.
  • Monitoring and Logging: Implements monitoring and logging using cloud-native tools.

Project Structure

intelligent-teams-coworker/
├── backend/
│ ├── manage.py
│ ├── backend/
│ ├── api/
│ └── requirements.txt
├── llm_service/
│ ├── main.py
│ └── requirements.txt
├── teams_app/
├── README.md
└── .gitignore

Step-by-Step Implementation

1. Microsoft Teams App

Create and register a Microsoft Teams app with bot capabilities. Define the app manifest and configure bot endpoints.

2. Django Backend

Set up a Django project and create API endpoints to handle user queries, interact with the LLM service, and log interactions.

3. Custom LLM Model

Collect data from AWS, Azure, and GCP documentation. Fine-tune a Hugging Face model and deploy it using FastAPI.

4. Cloud Deployment

Containerize the Django app, LLM service, and MongoDB using Docker. Deploy the containers using Kubernetes or cloud-native orchestration services. Implement monitoring and logging for the microservices.

Conclusion

By integrating a custom LLM with Microsoft Teams and deploying the application on cloud platforms, we can create an intelligent co-worker that enhances productivity and aids in cloud migration processes. This architecture ensures scalability, high availability, and seamless user interaction, making it a powerful tool for enterprise environments.

Hugging Face LLM Libraries and Models (2024)

Libraries

  • Transformers: The latest version includes support for models like Llama 3.
  • PEFT (Parameter-Efficient Fine-Tuning): Efficiently fine-tunes large models with fewer parameters.
  • Datasets: Framework for loading and processing datasets.

Models

  • Meta Llama 3: Available in 8B and 70B parameter models, optimized for dialogue and assistant-like interactions.
  • Swallow-70B: Instruction-tuned models from Tokyo Institute of Technology, suitable for question answering.
  • StarCoder2: Developed by ServiceNow, Hugging Face, and NVIDIA, ideal for code-related assistance.

Fine-Tuning with Public Documentation

  1. Data Collection: Aggregate documentation from AWS, Azure, and GCP.
  2. Data Processing: Use the datasets library to preprocess and structure the data.
  3. Fine-Tuning: Use the transformers library to load a base model and apply PEFT techniques.
  4. Validation: Use relevant benchmarks to ensure performance.

By leveraging these libraries and models, you can create a highly effective and responsive chatbot to assist with cloud migration tasks in your Microsoft Teams environment.