To contribute to Chainlit, you first need to setup the project on your local machine.
- Python >=
3.8
- Poetry (See how to install)
- NodeJS >=
16
(See how to install)
With this setup you can easily code in your fork and fetch updates from the main repository.
- Go to https://github.com/Chainlit/chainlit/fork to fork the chainlit code into your own repository.
- Clone your fork locally
$ git clone https://github.com/YOUR_USERNAME/YOUR_FORK.git
- 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)
- Specify the new remote upstream repository that will be synced with the fork.
$ git remote add upstream https://github.com/Chainlit/chainlit.git
- 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)
npm install
npm run installUiDeps
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.
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.
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 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.
- Find the folder containing the e2e test that you're looking for in
cypress/e2e
. - Run
SINGLE_TEST=FOLDER npm test
and change FOLDER with the folder from the previous step (example:SINGLE_TEST=scoped_elements run test
).
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.
- 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/';
- Follow the steps from Start the UI.
- Build the UI.
npm run buildUi
-
Follow the instruction from Install from local sources.
-
Run the server without the
-h
flag. Replacetarget.py
with the file you want to run. You can usesrc/chainlit/hello.py
as an example.
poetry run chainlit run target.py
- Any time you've made a change, restart the server from the previous step.