2024-12-13 09:48:43 -08:00
<!-- DANSWER_METADATA={"link": "https://github.com/onyx - dot - app/onyx/blob/main/CONTRIBUTING.md"} -->
2023-11-20 19:56:06 -08:00
2024-12-13 09:48:43 -08:00
# Contributing to Onyx
2023-07-12 19:29:13 -07:00
2024-12-13 09:48:43 -08:00
Hey there! We are so excited that you're interested in Onyx.
2023-07-12 19:29:13 -07:00
2024-12-13 09:48:43 -08:00
As an open source project in a rapidly changing space, we welcome all contributions.
2023-07-12 19:29:13 -07:00
## 💃 Guidelines
2024-12-13 09:48:43 -08:00
2023-07-12 19:29:13 -07:00
### Contribution Opportunities
2024-12-13 09:48:43 -08:00
The [GitHub Issues ](https://github.com/onyx-dot-app/onyx/issues ) page is a great place to start for contribution ideas.
2023-07-12 19:29:13 -07:00
2025-01-07 16:16:17 -08:00
To ensure that your contribution is aligned with the project's direction, please reach out to Hagen (or any other maintainer) on the Onyx team
via [Slack ](https://join.slack.com/t/onyx-dot-app/shared_invite/zt-2twesxdr6-5iQitKZQpgq~hYIZ~dv3KA ) /
[Discord ](https://discord.gg/TDJ59cGV2X ) or [email ](mailto:founders@onyx.app ).
2023-07-12 19:29:13 -07:00
Issues that have been explicitly approved by the maintainers (aligned with the direction of the project)
will be marked with the `approved by maintainers` label.
Issues marked `good first issue` are an especially great place to start.
2023-07-15 16:20:04 -07:00
**Connectors** to other tools are another great place to contribute. For details on how, refer to this
2024-12-13 09:48:43 -08:00
[README.md ](https://github.com/onyx-dot-app/onyx/blob/main/backend/onyx/connectors/README.md ).
2023-07-12 19:29:13 -07:00
2023-07-15 16:20:04 -07:00
If you have a new/different contribution in mind, we'd love to hear about it!
2024-12-13 09:48:43 -08:00
Your input is vital to making sure that Onyx moves in the right direction.
2023-07-12 19:29:13 -07:00
Before starting on implementation, please raise a GitHub issue.
2025-01-07 16:16:17 -08:00
Also, always feel free to message the founders (Chris Weaver / Yuhong Sun) on
[Slack ](https://join.slack.com/t/onyx-dot-app/shared_invite/zt-2twesxdr6-5iQitKZQpgq~hYIZ~dv3KA ) /
2024-12-13 09:48:43 -08:00
[Discord ](https://discord.gg/TDJ59cGV2X ) directly about anything at all.
2023-07-12 19:29:13 -07:00
### Contributing Code
2024-12-13 09:48:43 -08:00
2023-07-12 19:29:13 -07:00
To contribute to this project, please follow the
["fork and pull request" ](https://docs.github.com/en/get-started/quickstart/contributing-to-projects ) workflow.
When opening a pull request, mention related issues and feel free to tag relevant maintainers.
Before creating a pull request please make sure that the new changes conform to the formatting and linting requirements.
2024-11-23 21:13:23 +01:00
See the [Formatting and Linting ](#formatting-and-linting ) section for how to run these checks locally.
2023-07-12 19:29:13 -07:00
### Getting Help 🙋
2024-12-13 09:48:43 -08:00
2023-07-12 19:29:13 -07:00
Our goal is to make contributing as easy as possible. If you run into any issues please don't hesitate to reach out.
That way we can help future contributors and users can avoid the same issue.
We also have support channels and generally interesting discussions on our
2025-01-07 16:16:17 -08:00
[Slack ](https://join.slack.com/t/onyx-dot-app/shared_invite/zt-2twesxdr6-5iQitKZQpgq~hYIZ~dv3KA )
2024-12-13 09:48:43 -08:00
and
2023-07-12 19:29:13 -07:00
[Discord ](https://discord.gg/TDJ59cGV2X ).
We would love to see you there!
## Get Started 🚀
2024-12-13 09:48:43 -08:00
Onyx being a fully functional app, relies on some external software, specifically:
2023-10-25 18:26:02 -07:00
- [Postgres ](https://www.postgresql.org/ ) (Relational DB)
2023-08-26 15:35:19 -07:00
- [Vespa ](https://vespa.ai/ ) (Vector DB/Search Engine)
2024-09-07 14:05:36 -07:00
- [Redis ](https://redis.io/ ) (Cache)
- [Nginx ](https://nginx.org/ ) (Not needed for development flows generally)
2023-07-12 19:29:13 -07:00
2024-09-07 14:05:36 -07:00
> **Note:**
2024-12-13 09:48:43 -08:00
> This guide provides instructions to build and run Onyx locally from source with Docker containers providing the above external software. We believe this combination is easier for
> development purposes. If you prefer to use pre-built container images, we provide instructions on running the full Onyx stack within Docker below.
2023-07-12 19:29:13 -07:00
### Local Set Up
2024-12-13 09:48:43 -08:00
2024-09-11 10:45:52 -07:00
Be sure to use Python version 3.11. For instructions on installing Python 3.11 on macOS, refer to the [CONTRIBUTING_MACOS.md ](./CONTRIBUTING_MACOS.md ) readme.
2023-07-12 19:29:13 -07:00
2024-01-08 22:44:11 -08:00
If using a lower version, modifications will have to be made to the code.
2024-09-07 14:05:36 -07:00
If using a higher version, sometimes some libraries will not be available (i.e. we had problems with Tensorflow in the past with higher versions of python).
2024-09-02 15:30:18 -07:00
2024-09-11 12:16:37 -07:00
#### Backend: Python requirements
2024-12-13 09:48:43 -08:00
2023-07-12 19:29:13 -07:00
Currently, we use pip and recommend creating a virtual environment.
For convenience here's a command for it:
2024-12-13 09:48:43 -08:00
2023-07-12 19:29:13 -07:00
```bash
python -m venv .venv
source .venv/bin/activate
```
2024-06-18 11:28:47 -07:00
2024-09-07 14:05:36 -07:00
> **Note:**
2024-12-13 09:48:43 -08:00
> This virtual environment MUST NOT be set up WITHIN the onyx directory if you plan on using mypy within certain IDEs.
> For simplicity, we recommend setting up the virtual environment outside of the onyx directory.
2024-06-18 11:28:47 -07:00
2024-02-21 20:15:23 -05:00
_For Windows, activate the virtual environment using Command Prompt:_
2024-12-13 09:48:43 -08:00
2023-07-28 19:03:25 -07:00
```bash
.venv\Scripts\activate
```
2024-12-13 09:48:43 -08:00
2024-02-21 20:15:23 -05:00
If using PowerShell, the command slightly differs:
2024-12-13 09:48:43 -08:00
2024-02-21 20:15:23 -05:00
```powershell
.venv\Scripts\Activate.ps1
2024-02-21 17:44:13 -08:00
```
2023-07-12 19:29:13 -07:00
Install the required python dependencies:
2024-12-13 09:48:43 -08:00
2023-07-12 19:29:13 -07:00
```bash
2024-12-13 09:48:43 -08:00
pip install -r onyx/backend/requirements/default.txt
pip install -r onyx/backend/requirements/dev.txt
pip install -r onyx/backend/requirements/ee.txt
pip install -r onyx/backend/requirements/model_server.txt
2023-07-12 19:29:13 -07:00
```
2024-09-11 12:16:37 -07:00
Install Playwright for Python (headless browser required by the Web Connector)
2024-09-02 15:30:18 -07:00
2024-09-11 12:16:37 -07:00
In the activated Python virtualenv, install Playwright for Python by running:
2024-12-13 09:48:43 -08:00
2023-07-12 19:29:13 -07:00
```bash
2024-09-11 12:16:37 -07:00
playwright install
2023-07-12 19:29:13 -07:00
```
2024-09-11 12:16:37 -07:00
You may have to deactivate and reactivate your virtualenv for `playwright` to appear on your path.
2024-01-01 18:06:56 -08:00
2024-09-11 12:16:37 -07:00
#### Frontend: Node dependencies
2024-01-01 18:06:17 -08:00
2024-09-11 12:16:37 -07:00
Install [Node.js and npm ](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm ) for the frontend.
2024-12-13 09:48:43 -08:00
Once the above is done, navigate to `onyx/web` run:
2023-07-12 19:29:13 -07:00
```bash
2024-09-11 12:16:37 -07:00
npm i
2023-07-12 19:29:13 -07:00
```
2025-01-07 16:16:17 -08:00
## Formatting and Linting
### Backend
For the backend, you'll need to setup pre-commit hooks (black / reorder-python-imports).
First, install pre-commit (if you don't have it already) following the instructions
[here ](https://pre-commit.com/#installation ).
With the virtual environment active, install the pre-commit library with:
```bash
pip install pre-commit
```
Then, from the `onyx/backend` directory, run:
```bash
pre-commit install
```
Additionally, we use `mypy` for static type checking.
Onyx is fully type-annotated, and we want to keep it that way!
To run the mypy checks manually, run `python -m mypy .` from the `onyx/backend` directory.
### Web
We use `prettier` for formatting. The desired version (2.8.8) will be installed via a `npm i` from the `onyx/web` directory.
To run the formatter, use `npx prettier --write .` from the `onyx/web` directory.
Please double check that prettier passes before creating a pull request.
# Running the application for development
## Developing using VSCode Debugger (recommended)
We highly recommend using VSCode debugger for development.
See [CONTRIBUTING_VSCODE.md ](./CONTRIBUTING_VSCODE.md ) for more details.
Otherwise, you can follow the instructions below to run the application for development.
## Manually running the application for development
### Docker containers for external software
2024-12-13 09:48:43 -08:00
2024-09-02 15:30:18 -07:00
You will need Docker installed to run these containers.
2024-12-13 09:48:43 -08:00
First navigate to `onyx/deployment/docker_compose` , then start up Postgres/Vespa/Redis with:
2023-07-12 19:29:13 -07:00
```bash
2024-12-13 09:48:43 -08:00
docker compose -f docker-compose.dev.yml -p onyx-stack up -d index relational_db cache
2023-07-12 19:29:13 -07:00
```
2024-12-13 09:48:43 -08:00
2024-09-06 12:21:29 -07:00
(index refers to Vespa, relational_db refers to Postgres, and cache refers to Redis)
2023-07-12 19:29:13 -07:00
2025-01-07 16:16:17 -08:00
### Running Onyx locally
2024-12-13 09:48:43 -08:00
To start the frontend, navigate to `onyx/web` and run:
2024-09-07 14:05:36 -07:00
2023-07-12 19:29:13 -07:00
```bash
2023-10-25 18:26:02 -07:00
npm run dev
2023-07-12 19:29:13 -07:00
```
2023-10-25 18:26:02 -07:00
2024-04-07 21:25:06 -07:00
Next, start the model server which runs the local NLP models.
2024-12-13 09:48:43 -08:00
Navigate to `onyx/backend` and run:
2024-04-07 21:25:06 -07:00
```bash
uvicorn model_server.main:app --reload --port 9000
```
2024-09-07 14:05:36 -07:00
2024-04-07 21:25:06 -07:00
_For Windows (for compatibility with both PowerShell and Command Prompt):_
2024-12-13 09:48:43 -08:00
2024-04-07 21:25:06 -07:00
```bash
2024-09-07 14:05:36 -07:00
powershell -Command "uvicorn model_server.main:app --reload --port 9000"
2024-04-07 21:25:06 -07:00
```
2024-12-13 09:48:43 -08:00
The first time running Onyx, you will need to run the DB migrations for Postgres.
2023-10-25 18:26:02 -07:00
After the first time, this is no longer required unless the DB models change.
2023-07-12 19:29:13 -07:00
2024-12-13 09:48:43 -08:00
Navigate to `onyx/backend` and with the venv active, run:
2023-07-12 19:29:13 -07:00
```bash
alembic upgrade head
```
2023-10-25 18:26:02 -07:00
Next, start the task queue which orchestrates the background jobs.
Jobs that take more time are run async from the API server.
2024-12-13 09:48:43 -08:00
Still in `onyx/backend` , run:
2023-08-26 15:35:19 -07:00
```bash
2023-10-25 18:26:02 -07:00
python ./scripts/dev_run_background_jobs.py
2023-08-26 15:35:19 -07:00
```
2024-12-13 09:48:43 -08:00
To run the backend API server, navigate back to `onyx/backend` and run:
2023-07-12 19:29:13 -07:00
```bash
2024-12-13 09:48:43 -08:00
AUTH_TYPE=disabled uvicorn onyx.main:app --reload --port 8080
2023-07-12 19:29:13 -07:00
```
2024-09-07 14:05:36 -07:00
2023-07-28 19:03:25 -07:00
_For Windows (for compatibility with both PowerShell and Command Prompt):_
2024-12-13 09:48:43 -08:00
2023-07-28 19:03:25 -07:00
```bash
2023-08-26 15:35:19 -07:00
powershell -Command "
2023-10-01 23:49:38 -07:00
$env:AUTH_TYPE='disabled'
2024-12-13 09:48:43 -08:00
uvicorn onyx.main:app --reload --port 8080
2023-08-26 15:35:19 -07:00
"
2023-07-28 19:03:25 -07:00
```
2023-07-12 19:29:13 -07:00
2024-09-07 14:05:36 -07:00
> **Note:**
> If you need finer logging, add the additional environment variable `LOG_LEVEL=DEBUG` to the relevant services.
2024-09-11 12:16:37 -07:00
#### Wrapping up
You should now have 4 servers running:
- Web server
- Backend API
- Model server
- Background jobs
2024-12-13 09:48:43 -08:00
Now, visit `http://localhost:3000` in your browser. You should see the Onyx onboarding wizard where you can connect your external LLM provider to Onyx.
2024-09-11 12:16:37 -07:00
2024-12-13 09:48:43 -08:00
You've successfully set up a local Onyx instance! 🏁
2024-09-11 12:16:37 -07:00
2024-12-13 09:48:43 -08:00
#### Running the Onyx application in a container
2024-09-11 12:16:37 -07:00
2024-12-13 09:48:43 -08:00
You can run the full Onyx application stack from pre-built images including all external software dependencies.
2024-09-11 12:16:37 -07:00
2024-12-13 09:48:43 -08:00
Navigate to `onyx/deployment/docker_compose` and run:
2024-09-11 12:16:37 -07:00
```bash
2024-12-13 09:48:43 -08:00
docker compose -f docker-compose.dev.yml -p onyx-stack up -d
2024-09-11 12:16:37 -07:00
```
2024-12-13 09:48:43 -08:00
After Docker pulls and starts these containers, navigate to `http://localhost:3000` to use Onyx.
2024-09-11 12:16:37 -07:00
2024-12-13 09:48:43 -08:00
If you want to make changes to Onyx and run those changes in Docker, you can also build a local version of the Onyx container images that incorporates your changes like so:
2024-09-11 12:16:37 -07:00
```bash
2024-12-13 09:48:43 -08:00
docker compose -f docker-compose.dev.yml -p onyx-stack up -d --build
2024-09-11 12:16:37 -07:00
```
2023-07-12 19:29:13 -07:00
### Release Process
2024-12-13 09:48:43 -08:00
Onyx loosely follows the SemVer versioning standard.
2024-09-07 14:05:36 -07:00
Major changes are released with a "minor" version bump. Currently we use patch release versions to indicate small feature changes.
2023-07-12 19:29:13 -07:00
A set of Docker containers will be pushed automatically to DockerHub with every tag.
2024-12-13 09:48:43 -08:00
You can see the containers [here ](https://hub.docker.com/search?q=onyx%2F ).