Awesome
Reverse Chain
Implementation of paper: Reverse Chain: A Generic-Rule for LLMs to Master Multi-API Planning. This implementation uses FAISS vector database to retrieve API documentation on the basis of the query.
THIS IS NOT AN OFFICIAL IMPLEMENTATION OF REVERSE CHAIN
Dependencies
- Python3: Ensure that you have Python 3 installed on your system. You can download and install Python 3 from the official Python website: https://www.python.org.
- pip: pip is the package installer for Python. It is usually installed by default when you install Python. However, make sure you have pip installed and it is up to date. You can check the version of pip by running the following command:
pip --version
Installation
To install and use Reverse-Chain, follow the steps given below:
- Fork the Reverse-Chain repository by clicking the "Fork" button at the top right corner of the repository page. This will create a copy of the repository under your GitHub account.
- Clone the forked repository to your local machine:
git clone https://github.com/{YOUR-USERNAME}/Reverse-Chain
- Navigate to the project directory:
cd Reverse-Chain
- Install the necessary Python packages by running the following command:
pip install -r requirements.txt
(NOTE: It is recommended to install these requirements in a new python environment)
How to use?
Follow the steps given below:
- Add the documentation of the APIs in the
data/api_documentation
folder in.txt
format. The format in which the documentation is required is given in the folder. - Make changes in the
example.config.ini
file- Add your OpenAI Secret Key in the
secret_key
variable in theopenai
section. - Add your query in the
query
variable in thequery
section. - Other parameters can also be changed in the config file like, model, temperature, huggingface embedding model that FAISS database will use.
config.ini
- Add your OpenAI Secret Key in the
- Initialize the FAISS database by executing the command below:
This will create the FAISS database using the documentation added in thepython3 create_vector_db.py
data/api_documentation
- Now, the setup is complete :)
- Run the model by executing the command below:
python3 main.py
Output
The output of the run is saved in output/run.json
file and the logs are saved in logs/run.log
file.
Future Developement
It is not completely correct and maynot produce similar results as claimed in the paper. The following are few points of developement that can be done in the implementation:
Code & Prompts
- Prompts can be made better.
- Code in
main.py
can be refactored to look prettier. ArgumentExtractor
class returns the arguments found in the query, its prompt can be updated in a way that it selects arguments only that are needed for the current API.
Contributions
Contributions to Reverse-Chain are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the GitHub repository.