Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8d075be
web based client
LebToki Jul 1, 2024
ad214ca
Update utils.py
LebToki Jul 1, 2024
2b63fa0
Update bot.py
LebToki Jul 1, 2024
011c75c
Create .env
LebToki Jul 1, 2024
caf15e7
Update README.md
LebToki Jul 1, 2024
dd421bd
Update README.md
LebToki Jul 1, 2024
4fc0988
Update README.md
LebToki Jul 1, 2024
3d7e66b
Update README.md
LebToki Jul 1, 2024
9da9fc5
Update README.md
LebToki Jul 1, 2024
6bd0f66
Update README.md
LebToki Jul 2, 2024
4fe6564
Update README.md
LebToki Jul 2, 2024
4c1dba8
Update requirements.txt
LebToki Jul 2, 2024
5d6b567
Update app.py
LebToki Jul 2, 2024
eae28cd
Update index.html
LebToki Jul 2, 2024
dffc9d1
Add files via upload
LebToki Jul 2, 2024
8b1ab7b
Add files via upload
LebToki Jul 2, 2024
d55bbdc
Update README.md
LebToki Jul 2, 2024
85bd9d1
Update README.md
LebToki Jul 2, 2024
29e0c7e
Update README.md
LebToki Jul 2, 2024
22eadfd
Update README.md
LebToki Jul 2, 2024
408f688
Update README.md
LebToki Jul 2, 2024
5468380
Update README.md
LebToki Jul 2, 2024
41231c5
Update README.md
LebToki Jul 2, 2024
c1ddd93
Update README.md
LebToki Jul 2, 2024
063bc30
Update README.md
LebToki Jul 2, 2024
652e3a6
Update README.md
LebToki Jul 2, 2024
a19ae39
Update README.md
LebToki Jul 2, 2024
4e1a1a0
Update README.md
LebToki Jul 2, 2024
779fc48
Update README.md
LebToki Jul 2, 2024
fed2b0a
Update README.md
LebToki Jul 2, 2024
7357a99
Update README.md
LebToki Jul 2, 2024
a1296e5
Update README.md
LebToki Jul 2, 2024
1693a89
Update README.md
LebToki Jul 2, 2024
0c3263f
Update README.md
LebToki Jul 2, 2024
b3223d7
Update issue templates
LebToki Jul 2, 2024
23b3828
Update README.md
LebToki Jul 2, 2024
22c5320
Update README.md
LebToki Jul 2, 2024
6df0393
Update README.md
LebToki Jul 2, 2024
a55a63c
Update README.md
LebToki Jul 2, 2024
8084c01
Update index.html
LebToki Jul 2, 2024
fed1157
Update chat.html
LebToki Jul 2, 2024
269aa30
Update style.css
LebToki Jul 2, 2024
a8c9944
Update script.js
LebToki Jul 2, 2024
97dbdf9
Update app.py
LebToki Jul 2, 2024
60d558e
Update utils.py
LebToki Jul 2, 2024
2ba52cb
Update requirements.txt
LebToki Jul 2, 2024
931c41d
Add files via upload
LebToki Jul 2, 2024
20de26a
Update README.md
LebToki Jul 2, 2024
7d7edc2
Update README.md
LebToki Jul 2, 2024
360be21
Create CONTRIBUTING.md
LebToki Jul 2, 2024
d0ad956
Update README.md
LebToki Jul 2, 2024
1a1ea0b
Create python-package-conda.yml
LebToki Jul 2, 2024
f35b4d9
Update README.md
LebToki Jul 2, 2024
9707f79
Delete .github/workflows/python-package-conda.yml
LebToki Jul 2, 2024
ab46d16
Merge branch 'main' into main
LebToki Jul 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPENAI_API_KEY="INSERTYOURAPIKEYHERE"
GROQ_API_KEY="INSERTYOURAPIKEYHERE"
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Contributing

We welcome contributions! Please read the [CONTRIBUTING](CONTRIBUTING.md) guidelines before submitting a pull request.

### Note for Contributors

This project is based on Groq's API, not the original Together API. If you are contributing, please ensure compatibility and optimizations are aligned with Groq's specifications and guidelines.

## Contact

For any questions or feedback, please open an issue in this repository.

---
228 changes: 115 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,160 +1,162 @@
# Mixture-of-Agents (MoA)

[![License](https://img.shields.io/badge/License-Apache_2.0-green.svg)](LICENSE)
[![arXiv](https://img.shields.io/badge/ArXiv-2406.04692-b31b1b.svg)](https://arxiv.org/abs/2406.04692)
[![Discord](https://img.shields.io/badge/Discord-Together%20AI-blue?logo=discord&logoColor=white)](https://discord.com/invite/9Rk6sSeWEG)
[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/togethercompute.svg?style=social&label=Follow%20%40togethercompute)](https://twitter.com/togethercompute)

<img alt="MoA architecture" src="./assets/moa.jpg">
```sh
git clone https://github.com/LebToki/MoA.git
cd MoA
```

<p align="center">
<a href="#overview"><strong>Overview</strong></a> ·
<a href="#quickstart-moa-in-50-loc"><strong>Quickstart</strong></a> ·
<a href="#multi-layer-moa-example"><strong>Advanced example</strong></a> ·
<a href="#interactive-cli-demo"><strong>Interactive CLI Demo</strong></a>
·
<a href="#evaluation"><strong>Evaluation</strong></a>
·
<a href="#results"><strong>Results</strong></a>
.
<a href="#credits"><strong>Credits</strong></a>
</p>
2. **Install Dependencies**:

## Overview
```sh
pip install -r requirements.txt
```

2.1. **List of Dependencies**

Mixture of Agents (MoA) is a novel approach that leverages the collective strengths of multiple LLMs to enhance performance, achieving state-of-the-art results. By employing a layered architecture where each layer comprises several LLM agents, **MoA significantly outperforms GPT-4 Omni’s 57.5% on AlpacaEval 2.0 with a score of 65.1%**, using only open-source models!
- **openai**: OpenAI API client library.
- **fire**: A Python library for creating command line interfaces.
- **loguru**: A library to make logging in Python simpler and more readable.
- **datasets**: Hugging Face's library for accessing and managing datasets.
- **typer**: A library for building command line interface applications.
- **rich**: A Python library for rich text and beautiful formatting in the terminal.
- **Flask**: A micro web framework for Python.
- **Flask-SQLAlchemy**: Adds SQLAlchemy support to Flask applications.
- **Flask-Uploads**: A flexible library to handle file uploading in Flask.
- **Werkzeug**: A comprehensive WSGI web application library.
- **Flask-Migrate**: Handles SQLAlchemy database migrations for Flask applications using Alembic.
- **PyMuPDF (fitz)**: A Python binding for MuPDF – a lightweight PDF and XPS viewer.
- **python-docx**: A Python library for creating and updating Microsoft Word (.docx) files.

## Quickstart: MoA in 50 LOC

To get to get started with using MoA in your own apps, see `moa.py`. In this simple example, we'll use 2 layers and 4 LLMs. You'll need to:
3. **Set Up Environment Variables**:

1. Install the Together Python library: `pip install together`
2. Get your [Together API Key](https://api.together.xyz/settings/api-keys) & export it: `export TOGETHER_API_KEY=`
3. Run the python file: `python moa.py`
Create a `.env` file in the root directory and add your API keys:

<img alt="MoA explained" src="./assets/moa-explained.png">
```
GROQ_API_KEY=your_groq_api_key
OPENAI_API_KEY=your_openai_api_key
DEBUG=0
```

## Multi-layer MoA Example
### Running the Application

In the previous example, we went over how to implement MoA with 2 layers (4 LLMs answering and one LLM aggregating). However, one strength of MoA is being able to go through several layers to get an even better response. In this example, we'll go through how to run MoA with 3+ layers in `advanced-moa.py`.

```python
python advanced-moa.py
Open your web browser and navigate to the following URL to access the web-based interface:
```sh
http://127.0.0.1:5000/
```

<img alt="MoA – 3 layer example" src="./assets/moa-3layer.png">

## Interactive CLI Demo
## Usage

This interactive CLI demo showcases a simple multi-turn chatbot where the final response is aggregated from various reference models.
### Interacting with the MoA Grog Chatbot

To run the interactive demo, follow these 3 steps:
- **Model Selection**: Choose the model you want to use from the dropdown menu. The default model is `llama3-70b-8192`, which balances performance and speed.

- **Temperature Control**: Adjust the temperature setting to control the randomness and creativity of the chatbot's responses. The default value is `0.7`, providing a good balance between deterministic and varied outputs.

- **Max Tokens**: Define the maximum number of tokens (words or characters) for the response. The default is `2048`, which ensures comprehensive answers without overwhelming verbosity.

- **Create Your Topics**: Easily create new conversation topics by entering your desired topic names in the text field provided. This helps organize your interactions and revisit previous conversations.

- **Choose Your Topic**: Select a topic by clicking on it in the sidebar. The chat interface will load on the right, allowing you to continue your discussion seamlessly.

- **Instruction Input**: Enter your prompt or instruction in the text area. This is where you ask questions or provide commands to the chatbot.

- **Theme Toggle**: Enhance your user experience by switching between light and dark modes. Use the "Switch to Dark Mode" button to toggle themes based on your preference.

- **Submit and View Responses**: After filling in the necessary fields, submit the form to receive a response from the MoA Grog Chatbot. The response will be displayed on the same page, within the chat interface.

1. Export Your API Key: `export TOGETHER_API_KEY={your_key}`
2. Install Requirements: `pip install -r requirements.txt`
3. Run the script: `python bot.py`
### Additional Features

The CLI will prompt you to input instructions interactively:
- **Create New Conversations**: Use the sidebar to create new conversation topics, helping you manage different discussions effectively.

- **Reset All Conversations**: If needed, reset all conversations from the sidebar to start fresh.

1. Start by entering your instruction at the ">>>" prompt.
2. The system will process your input using the predefined reference models.
3. It will generate a response based on the aggregated outputs from these models.
4. You can continue the conversation by inputting more instructions, with the system maintaining the context of the multi-turn interaction.
This intuitive interface makes it easy to engage with the MoA Grog Chatbot, providing a seamless and interactive user experience.

### [Optional] Additional Configuration

The demo will ask you to specify certain options but if you want to do additional configuration, you can specify these parameters:
### Planned Features

- `--aggregator`: The primary model used for final response generation.
- `--reference_models`: List of models used as references.
- `--temperature`: Controls the randomness of the response generation.
- `--max_tokens`: Maximum number of tokens in the response.
- `--rounds`: Number of rounds to process the input for refinement. (num rounds == num of MoA layers - 1)
- `--num_proc`: Number of processes to run in parallel for faster execution.
- `--multi_turn`: Boolean to toggle multi-turn interaction capability.
- **Uploading Documents**: The MoA Groq Chatbot will support file uploads and interact with the content of the uploaded documents, adding functionality to handle file uploads, process the contents of these files, and integrate the results into the chatbot's conversation flow.
- **Refine the styling**: With the latest Bootstrap and jQuery, we have room to enhance the UI/UX further.
- **Chronological ordering**: Move recent chats to the top (DESC order) to cut down on scrolling.
- **Further enhancement of the output**: Currently, not much has been implemented to control the output except basic styling. This is an area to be worked on based on various use cases.

## Evaluation

We provide scripts to quickly reproduce some of the results presented in our paper
For convenience, we have included the code from [AlpacaEval](https://github.com/tatsu-lab/alpaca_eval),
[MT-Bench](https://github.com/lm-sys/FastChat), and [FLASK](https://github.com/kaistAI/FLASK), with necessary modifications.
We extend our gratitude to these projects for creating the benchmarks.
## File Structure

### Preparation
- **MoA/**
- `app.py` - Flask application
- `bot.py` - Main chatbot logic
- `utils.py` - Utility functions
- `requirements.txt` - Python dependencies
- **templates/**
- `index.html` - HTML template for the web interface
- `chat.html` - HTML template for the chat interface
- **static/**
- `style.css` - CSS styles for the web interface
- `script.css` - JavaScript for theme switching and UI enhancements
- `bot.png` - favicon

```bash
# install requirements
pip install -r requirements.txt
cd alpaca_eval
pip install -e .
cd FastChat
pip install -e ".[model_worker,llm_judge]"
cd ..

# setup api keys
export TOGETHER_API_KEY=<TOGETHER_API_KEY>
export OPENAI_API_KEY=<OPENAI_API_KEY>
```
## Changelog
What's New in 1.1.0 · [02/07/2024]
- Implemented Dark Mode Support: Switch between light and dark themes for better usability.
- Enhanced UI/UX: Updated the styling of the chat interface, including better message formatting and improved layout.
- Improved Form Layout: Grouped form inputs on a single row for better space utilization.
- Sidebar Adjustment: Reduced the sidebar width to 180px to provide more space for the main chat interface.
- Document Upload Support: Added the ability to upload documents and interact with the content within the chatbot.
- Improved Sorting: Ensured conversation messages are displayed in descending order to prioritize the most recent interactions.

### Run AlpacaEval 2
<details>
<summary>Previous Releases</summary>
Initial Release · [01/07/2024]

To run AlpacaEval 2, execute the following scripts:
- Code Organization: Initial setup of the project with organized structure for controllers, models, and views.
- Error Handling: Basic error handling for API requests and user inputs.
- Front-end Enhancements: Initial design of the UI with Bootstrap and FontAwesome integration. Responsive design for better accessibility on all devices.
- Performance Considerations: Basic optimizations for faster loading times.
- Accessibility and Usability: Added alt attributes to all images for better accessibility.
</details>

```
bash run_eval_alpaca_eval.sh
```
## Acknowledgements

### Run MT-Bench
- **Original Creator**: Special thanks to the original creator of this amazing project. [togethercomputer](https://github.com/togethercomputer/MoA)
- **Matthew Berman**: A special thanks to [Matthew Berman](https://www.youtube.com/@matthew_berman) for showcasing this project and providing valuable insights.

For a minimal example of MT-Bench evaluation, run:

```
bash run_eval_mt_bench.sh
```

### Run FLASK
## License

For a minimal example of FLASK evaluation, run:
<p xmlns:cc="http://creativecommons.org/ns#" >This work by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://2tinteractive">Tarek Tarabichi</a> is licensed under <a href="http://creativecommons.org/licenses/by/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"></a></p>

```
bash run_eval_flask.sh
```
## Contributing

### Results
We welcome contributions! Please read the [CONTRIBUTING](CONTRIBUTING.md) guidelines before submitting a pull request.

<div align="center">
<img src="assets/alpaca_and_mtbench.png" alt="alpaca_mtbench" style="width: 100%; display: block; margin-left: auto; margin-right: auto;" />
<br>
</div>
# Note for Contributors
This project is based on Groq's API, not the original Together API.
If you are contributing, please ensure compatibility and optimizations are aligned with Groq's specifications and guidelines.

We achieved top positions on both the AlpacaEval 2.0 leaderboard and MT-Bench. Notably, on AlpacaEval 2.0, using solely open-source models, we achieved a margin of 7.6% absolute improvement from 57.5% (GPT-4 Omni) to 65.1% (MoA).
## Contact

<div align="center">
<img src="assets/flask.png" alt="flask" style="width: 50%; display: block; margin-left: auto; margin-right: auto;" />
<br>
</div>
For any questions or feedback, please open an issue in this repository.

FLASK offers fine-grained evaluation of models across multiple dimensions. Our MoA method significantly outperforms the original Qwen1.5-110B-Chat on harmlessness, robustness, correctness, efficiency, factuality, commonsense, insightfulness, completeness. Additionally, MoA also outperforms GPT-4 Omni in terms of correctness, factuality, insightfulness, completeness, and metacognition.
---
# Get Involved
Whether you're a developer, system integrator, or enterprise user, you can trust that we did everything possible to make it as smooth and easy as 1,2,3 to set up MoA Groq Chatbot.

Please feel free to contact us if you have difficulties in reproducing the results.
⭐ Give us a star on GitHub 👆

## Credits
⭐ Fork the project on GitHub and contribute👆

Notably, this work was made possible by the collaborative spirit and contributions of active organizations in the AI field. We appreciate the efforts of Meta AI, Mistral AI, Microsoft, Alibaba Cloud, and DataBricks for developing the Llama 3, Mixtral, WizardLM 2, Qwen 1.5, and DBRX models. Additionally, we extend our gratitude to Tatsu Labs, LMSYS, and KAIST AI for developing the AlpacaEval, MT-Bench, and FLASK evaluation benchmarks.
🚀 Do you like to code? You're more than welcome to contribute Join the Discussions!

## License
💡 Got a feature suggestion? Add your roadmap ideas

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
<br/>

## Citation
This project is licensed under the Attribution License.
2024 · Tarek Tarabichi from 2TInteractive.com · Made with 💙

If you find this work helpful, please consider citing:
Thank you for using MoA Groq Chatbot!
We hope you find it useful and look forward to your contributions.

```bibtex
@article{wang2024mixture,
title={Mixture-of-Agents Enhances Large Language Model Capabilities},
author={Wang, Junlin and Wang, Jue and Athiwaratkun, Ben and Zhang, Ce and Zou, James},
journal={arXiv preprint arXiv:2406.04692},
year={2024}
}
```
Loading