Skip to content

Latest commit

 

History

History
150 lines (106 loc) · 4.55 KB

CONTRIBUTING.md

File metadata and controls

150 lines (106 loc) · 4.55 KB

Contribute to Chainlit

To contribute to Chainlit, you first need to setup the project on your local machine.

Table of Contents

Local setup

Requirements

  1. Python >= 3.8
  2. Poetry (See how to install)
  3. NodeJS >= 16 (See how to install)

Setup the repo

With this setup you can easily code in your fork and fetch updates from the main repository.

  1. Go to https://github.com/Chainlit/chainlit/fork to fork the chainlit code into your own repository.
  2. Clone your fork locally
$ git clone https://github.com/YOUR_USERNAME/YOUR_FORK.git
  1. Go into your fork and list the current configured remote repository.
$ git remote -v
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push) 
  1. Specify the new remote upstream repository that will be synced with the fork.
$ git remote add upstream https://github.com/Chainlit/chainlit.git
  1. Verify the new upstream repository you've specified for your fork.
$ git remote -v
> origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
> upstream  https://github.com/Chainlit/chainlit.git (fetch)
> upstream  https://github.com/Chainlit/chainlit.git (push)

Install JS dependencies

npm install
npm run installUiDeps

Install python dependencies

cd src
poetry install

Make sure you have the Python code formatter black installed as it is used in a pre-commit hook. Run pip install black if needed.

Start the UI

npm run buildUi
cd src/chainlit/frontend
npm run dev -- --port 5174

The buildUi step is currently needed by the server.

If you visit http://127.0.0.1:5174/, it should say that it can't connect to the server.

Setup the server

Start the server

Start by running src/chainlit/hello.py as an example.

cd src
poetry run chainlit run chainlit/hello.py -h

The -h parameter (headless) means the UI will not automatically open.

You should now be able to use the UI you launched previously on http://127.0.0.1:5174/.

If you've made it this far, you can now replace chainlit/hello.py by your own target. 😎

Run the tests

Run npm test

Once you create a pull request, the tests will automatically run. It is a good practice to run the tests locally before pushing.

Run one test

  1. Find the folder containing the e2e test that you're looking for in cypress/e2e.
  2. Run SINGLE_TEST=FOLDER npm test and change FOLDER with the folder from the previous step (example: SINGLE_TEST=scoped_elements run test).

Only contribute to one side of the project

This is the easiest solution if you want to only make a change in the UI or the server.

Start with following the steps from the Local setup.

Only contribute to the frontend

  1. Change the server url in src/chainlit/frontend/src/api/index.ts to match your target chainlit server. Below is an example using a public chainlit server. Don't forget to change the configuration back before commiting.
const devServer = 'https://img-gen.chainlit.app/';
  1. Follow the steps from Start the UI.

Only contribute to the server

  1. Build the UI.
npm run buildUi
  1. Follow the instruction from Install from local sources.

  2. Run the server without the -h flag. Replace target.py with the file you want to run. You can use src/chainlit/hello.py as an example.

poetry run chainlit run target.py
  1. Any time you've made a change, restart the server from the previous step.