CLAPP is a Streamlit application that provides an AI pair programming assistant specialized in the CLASS cosmology code. It uses LangChain and OpenAI models, leveraging Retrieval-Augmented Generation (RAG) with CLASS documentation and code examples to provide informed responses and assist with coding tasks.
- Santiago Casas
- Christian Fidler
- Julien Lesgourgues
- With contributions from: Boris Bolliet & Francisco Villaescusa-Navarro
- inspired by the CAMELS-Agent-App
- Conversational AI: Interact with an AI assistant knowledgeable about CLASS and cosmology.
- CLASS Integration: Built-in tools to install, test, and use the CLASS cosmological code.
- Code Execution: Executes Python code snippets in real-time, with automatic error detection and correction.
- Plotting Support: Generates and displays cosmological plots from CLASS outputs.
- RAG Integration: Retrieves relevant information from CLASS documentation and code (
./class-data/
) to answer questions accurately. - Multiple Response Modes:
- Fast Mode: Quick responses with good quality (recommended for most uses)
- Swarm Mode: Multi-agent refined responses for more complex questions (takes longer)
- Secure User Management: Username-based API key storage allows multiple users to securely save encrypted API keys.
- Real-time Feedback: Streams installation and execution progress in real-time.
- Model Selection: Choose between different OpenAI models (GPT-4o, GPT-4o-mini).
This project uses conda/mamba for environment management, which is compatible with CLASS installation requirements.
-
Clone the repository:
git clone https://github.com/santiagocasas/clapp.git cd clapp
-
Create a conda environment from the environment.yml file:
# Using conda conda env create -f environment.yml # Or using mamba (faster) mamba env create -f environment.yml
-
Activate the environment:
conda activate clapp
-
API Key:
- You will need an OpenAI API or Gemini key.
- The application allows you to enter a username, API key, and password to encrypt and store it locally.
- Keys are saved as
{username}_encrypted_api_key
to allow multiple users. - Get your free Gemini key from https://aistudio.google.com/app/apikey
-
CLASS Installation:
- CLAPP includes a built-in CLASS installation button that will install CLASS from source.
- Alternatively, you can check if CLASS is already installed using the provided tool.
-
CLASS Data:
- Ensure the
class-data
directory contains the necessary CLASS documentation, code files (.py, .ini, .txt), and potentially PDF documents for the RAG system.
- Ensure the
-
System Prompts:
- Ensure the
prompts/
directory contains the necessary instruction files (class_instructions.txt
,review_instructions.txt
, etc.).
- Ensure the
-
Activate the conda environment:
conda activate clapp
-
Run the Streamlit application:
streamlit run CLAPP.py
-
Setup process:
- Enter your OpenAI API key and optionally a username and password for encryption.
- Initialize the application by clicking "Initialize with Selected Model".
- Check if CLASS is installed or install it using the provided buttons.
- Start chatting with the assistant about CLASS-related questions or cosmology code.
-
Code execution:
- When the assistant provides code, you can execute it by typing "execute!" in the chat.
- The system will run the code, display the output, and show any generated plots.
- If errors occur, the system will automatically attempt to fix them.
CLAPP.py
: The main Streamlit application script.install_classy.sh
: Script to install CLASS from source.test_classy.py
: Script to test CLASS installation and functionality.environment.yml
: Conda environment specification with all required dependencies.class-data/
: Directory containing data for the RAG system (CLASS code, docs, etc.).prompts/
: Directory containing system prompts for the AI agents.images/
: Contains images used in the app interface, including the CLAPP logo.{username}_encrypted_api_key
: Stores the encrypted OpenAI API keys for each user.
CLAPP allows you to:
- Learn about CLASS: Ask questions about CLASS cosmology code features, parameters, and usage.
- Develop cosmology code: Get help writing code that uses CLASS for cosmological calculations.
- Debug and fix errors: Get assistance with error messages and issues in your CLASS code.
- Visualize results: Generate and view plots of cosmological data.