Skip to content

The-Language-and-Learning-Analytics-Lab/TRAIL-Chat-Module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TRAIL: Team Research and AI Integration Lab

Python VENV

  1. python version 3.11
  2. Steps:
    following tutorials in https://gist.github.com/ryumada/c22133988fd1c22a66e4ed1b23eca233
    pip install -r requirement_venv.txt

Tool information

Tool : Visual Studio Code Extension: Remote Development

Commit Conventions

run pre-commit before commit files

pre-commit run --all-files

Overview

This project aims to build an AI chatbot that can interact effectively in a collaborative environment, contributing to research on human-like AI behavior. It provides both a Slack integration and a web interface for team collaboration with AI.

Features

  • Multi-room chat support with persistent history
  • Customizable AI teammate personality traits
  • Long-term memory and context awareness
  • Real-time collaboration with multiple users
  • Shareable room links
  • Secure experiment setup interface with authentication

How to Run

Environment Setup

  1. Git clone this repo
  2. Create a .env file in the Bolt directory with the following variables:
    # Required for Slack integration
    SLACK_APP_TOKEN=<your-slack-app-token>
    SLACK_BOT_TOKEN=<your-slack-bot-token>
    
    # Required for both Slack and Web interface
    OPENAI_API_KEY=<your-openai-api-key>
    
    # Required for experiment setup authentication
    SETUP_USERNAME=<your-desired-username>
    SETUP_PASSWORD=<your-desired-password>
    
    # Optional configurations
    OPEN_AI_MODEL=gpt-4
    SQLITE_DB_NAME=chat_history.db
    

Run Slack ChatBot

  1. Follow the instructions to generate Slack API keys and add corresponding Scopes: https://www.youtube.com/watch?v=oDoFvpDftBA&ab_channel=PyBites
  2. Add the Slack tokens to your .env file
  3. Run python3 app.py to start the Slack bot

Run Web Interface

  1. Ensure you have all required environment variables in your .env file
  2. Navigate to the Bolt directory
  3. Run python3 web_app.py
  4. Access the web interface at http://localhost:5000

Web Interface Features

  • Default landing page directs to participant join interface
  • Secure experiment setup page with username/password authentication
  • Create and join chat rooms
  • Real-time chat with AI teammate
  • Customize AI personality traits and communication style
  • Share room links with other users
  • Persistent chat history
  • Multiple active rooms support

Web Interface Workflow

  1. Participants: Access the join page directly at the root URL
  2. Experimenters:
    • Access /experiment/setup_login for setup authentication
    • Enter credentials from .env file
    • Once authenticated, access the experiment setup interface

How It Works

Database Structure

The application uses SQLite3 for data persistence with the following tables:

  • users: Stores user information and session data
  • personas: Stores AI personality configurations per room
  • new_msg_queue: Manages message queue for processing
  • history: Stores chat history
  • context_history: Maintains context for AI responses
  • long_term_memories: Stores summarized conversation insights

AI Interaction

  • Uses OpenAI's GPT-4 model for natural language processing
  • Maintains conversation context and long-term memory
  • Adapts responses based on configured personality traits
  • Supports real-time updates to AI behavior through personality adjustments

Deployment Instructions

Prerequisites

  • Python 3.11
  • AWS CLI configured with appropriate credentials
  • Docker
  • Node.js and npm (for AWS CDK)

AWS CLI and AWS CDK Setup

1. Install AWS CLI

The AWS Command Line Interface (CLI) allows you to interact with AWS services using commands in your terminal.

On macOS/Linux:

  • Install via pip:

    pip install awscli

    Alternatively, install the latest version of AWS CLI v2 by following instructions from the official AWS CLI installation guide.

  • Verify the installation:

    aws --version

    This should display the AWS CLI version.

On Windows:

  1. Download the AWS CLI installer for Windows:
    AWS CLI Version 2 for Windows

  2. Run the installer by following on-screen instructions.

  3. Verify the installation:

    Open CMD or PowerShell and run:

    aws --version

2. Install AWS CDK (Cloud Development Kit)

AWS CDK allows you to define AWS infrastructure using code. You can install it globally with npm.

Install Node.js (if not installed):

Visit Node.js website and install the LTS version for your OS. Verify installation:

node -v
npm -v

Install AWS CDK:

Run the following command to install AWS CDK globally:

npm install -g aws-cdk

Verify the installation:

After installing AWS CDK, verify by running:

cdk --version

This should output the installed AWS CDK version.

Bootstrap CDK (first time only):

cdk bootstrap

3. Configure AWS CLI

Before using AWS CLI or AWS CDK, configure your AWS credentials.

  1. Run the configuration command:

    aws configure
  2. Enter your credentials:

    You'll be prompted to enter your AWS Access Key, Secret Access Key, default region, and output format.

    Example:

    AWS Access Key ID [None]: 
    AWS Secret Access Key [None]:
    Default region name [None]: us-west-2
    Default output format [None]: json
    

Local Development Setup

  1. Create and activate a virtual environment within infrastructure folder:
cd infrastructure
python -m venv venv
source venv/bin/activate  # On Windows: .\venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt

Environment Variables Management

Run these command in the project root folder. The application uses AWS Systems Manager Parameter Store for environment variables. To manage them:

  1. Upload environment variables to Parameter Store:
python infrastructure/manage_env.py upload .env
  1. Download environment variables from Parameter Store:
python infrastructure/manage_env.py download .env

Docker Deployment

  1. Build the Docker image:
docker build -t trail-chat .
  1. Run locally:
docker run -p 3000:3000 trail-chat

AWS ECR Deployment

  1. Create an ECR repository (if not exists):
aws ecr create-repository --repository-name trail-chat-repository --region us-west-2
  1. Login to ECR:
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin {account_id}.dkr.ecr.us-west-2.amazonaws.com
  1. Tag and push the image:
docker tag trail-chat:latest {account_id}.dkr.ecr.us-west-2.amazonaws.com/trail-chat-repository:latest
docker push {account_id}.dkr.ecr.us-west-2.amazonaws.com/trail-chat-repository:latest

AWS Infrastructure Setup

Deploy the infrastructure:

cdk deploy --app "python app.py"

Infrastructure Components

The CDK stack creates:

  • VPC with public and private subnets
  • EC2 instance with appropriate security groups
  • IAM roles with necessary permissions
  • SSM Parameter Store parameters
  • ECR repository access

Security

  • Environment variables are stored in AWS Parameter Store
  • EC2 instance uses IAM roles for AWS service access
  • Security groups restrict access to necessary ports
  • All sensitive data is encrypted at rest

Cleanup

To destroy the infrastructure:

cd infrastructure
cdk destroy --app "python app.py"

Possible Setup Issues and Solutions

All package versions are listed in requirements.txt current chromadb version: 0.4.15

  1. When you create a new github Codespaces, you should install the packages manually. run "pip install --no-cache-dir -r .devcontainer/requirements.txt"

NOTE: It is not recommended to upload your API token to the codebase because the GIT and Slack will lock the privilege.

Preprint paper:

The AI Collaborator: Bridging Human-AI Interaction in Educational and Professional Settings
Mohammad Amin Samadi, Spencer JaQuay, Jing Gu, Nia Nixon, link

citation:

@article{samadi2024ai, title={The AI Collaborator: Bridging Human-AI Interaction in Educational and Professional Settings}, author={Samadi, Mohammad Amin and JaQuay, Spencer and Gu, Jing and Nixon, Nia}, journal={arXiv preprint arXiv:2405.10460}, year={2024} }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •