Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 2 deletions .github/compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ services:
dockerfile: api/Dockerfile
restart: always
env_file: "${APP_ENV_FILE:-.env.ci}"
volumes:
- ../scripts/generate_configuration_documentation.py:/scripts/generate_configuration_documentation.py:ro
ports:
- 8000:8000
environment:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/deploy_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,26 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: ./docs/package-lock.json

- name: Install dependencies
working-directory: ./docs
run: npm ci

- name: Build Docusaurus site
working-directory: ./docs
run: npm run build

- name: Create CNAME file
working-directory: ./docs/build
run: echo "docs.opengatellm.etalab.gouv.fr" > CNAME

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
41 changes: 20 additions & 21 deletions .github/workflows/generate_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,26 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Checkout du code
uses: actions/checkout@v4

- name: Set up Docker Compose
run: |
cp .github/.env.ci.example .github/.env.ci
sed -i 's/^\([A-Z_]*\)_HOST=localhost/\1_HOST=\L\1/' .github/.env.ci
make test-integ action=up execute=docker
env:
BRAVE_API_KEY: ${{ secrets.BRAVE_API_KEY }}
ALBERT_API_KEY: ${{ secrets.ALBERT_API_KEY }}
CS_API_KEY: ${{ secrets.CS_API_KEY }}
- name: Configure Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Generate configuration documentation
run: |
docker compose -f .github/compose.ci.yml --env-file .github/.env.ci run -T --user $(id -u):$(id -g) -v $(pwd)/api:/api api \
python /scripts/generate_configuration_documentation.py --output /api/configuration.md

cat ./api/configuration.md > ./docs/docs/getting-started/configuration.md
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[api,dev]"

- name: Commit configuration documentation
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update configuration documentation
file_pattern: ./docs/getting-started/configuration.md
- name: Generate documentation
run: |
PYTHONPATH=. python ./scripts/docs/generate_configuration_documentation.py --output ./docs/docs/getting-started/configuration.md
PYTHONPATH=. python ./scripts/docs/convert_notebooks_to_docs.py --input ./docs/tutorials --output ./docs/docs/guides

- name: Commit documentation
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update docs
file_pattern: ./docs/getting-started/configuration.md ./docs/docs/guides/*.md
194 changes: 5 additions & 189 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,191 +1,7 @@
# Contributing

## Contributing environment

To contribute to the project, please follow the instructions below to setup your development environment and launch the services locally.

### Prerequisites

- Python 3.12+
- Docker and Docker Compose

### Step 1: development environment

#### Configuration

It is recommended to use a Python [virtualenv](https://docs.python.org/3/library/venv.html).

1. Create a *config.yml* file based on the example configuration file *[config.example.yml](./config.example.yml)*.

```bash
cp config.example.yml config.yml
```

2. Create a *env* file based on the example environment file *[env.example](./env.example)*

```bash
cp .env.example .env
```

3. Comment host names variables like this (by default, they are set to `localhost` in compose.example.yml):

```bash
# POSTGRES_HOST=postgres
```

4. Check the [configuration documentation](./docs/configuration.md) to configure your configuration file.

#### Packages installation

1. Create a Python virtual environment (recommended)

1. Install the dependencies with the following command:

```bash
pip install ".[api,playground,dev,test]"
```

#### Linter installation

The project linter is [Ruff](https://beta.ruff.rs/docs/configuration/). The specific project formatting rules are in the *[pyproject.toml](./pyproject.toml)* file.

Please install the pre-commit hooks:

```bash
pre-commit install
```

Ruff will run automatically at each commit.

To setup ruff in VSCode or Cursor, you can add the following configuration to your editor:
```json
{
"ruff.lint.enabled": true,
"ruff.lint.fix": true
}
```

### Step 2: launch services

Start services locally with the following command:

```bash
make dev
```

> [!NOTE]
> This command will start the API and the playground services and support the following options:
> ```bash
> make dev [service=api|playground|both] [env=.env] [compose=compose.yml] # service=both by default
> ```
> For more information, run `make help`.

To run the services without make command, you can use the following commands:

1. Export the environment variables:
```bash
export $(grep -v '^#' .env | xargs)
```

2. Launch the API:
```bash
uvicorn api.main:app --log-level debug --reload
```

3. Launch the Playground:
```bash
streamlit run playground/main.py
```

## Linter

The project linter is [Ruff](https://beta.ruff.rs/docs/configuration/). The specific project formatting rules are in the *[pyproject.toml](./pyproject.toml)* file. See [Linter installation section](#linter-installation) to install the linter and run it at each commit.

To run the linter manually:

```bash
make lint
```

To setup ruff in VSCode or Cursor, you can add the following configuration to your editor (edit project root path):

```json
{
"[python]": {
"editor.formatOnType": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "always"
},
"ruff.configuration": "<absolute project root path >/pyproject.toml",
"ruff.format.preview": true,
"ruff.codeAction.fixViolation": {"enable": false},
"ruff.organizeImports": true,
"ruff.fixAll": true,
"ruff.trace.server": "verbose",
"ruff.logLevel": "debug",
"ruff.nativeServer": "on",
}
}
```

## Commit

Please respect the following convention for your commits:

```
[doc|feat|fix](theme) commit object (in english)

# example
feat(collections): collection name retriever
```

## Tests

To run the tests:

```bash
make test
```

## Modifications to SQL database structure

### Modifications to the [`api/sql/models.py`](./api/sql/models.py) file

If you have modified the API database tables in the [models.py](./api/sql/models.py) file, you need to create an Alembic migration with the following command:

```bash
alembic -c api/alembic.ini revision --autogenerate -m "message"
```

Then apply the migration with the following command:

```bash
alembic -c api/alembic.ini upgrade head
```

### Modifications to the [`playground/sql/models.py`](./playground/sql/models.py) file

If you have modified the playground database tables in the [models.py](./playground/sql/models.py) file, you need to create an Alembic migration with the following command:

```bash
alembic -c playground/alembic.ini revision --autogenerate -m "message"
```

Then apply the migration with the following command:

```bash
alembic -c playground/alembic.ini upgrade head
```

## Generate configuration documentation

To generate the configuration documentation, you can use the following command:

```bash
python scripts/generate_configuration_documentation.py
```

> [!NOTE]
> This will generate the configuration documentation in the *[docs/docs/getting-started/configuration.md](./docs/docs/getting-started/configuration.md)* file from the [configuration schema](./api/schemas/core/configuration.py) with the [configuration header](./scripts/configuration_header.md).
The contributings guides is available in *Contributing* section in [documentation](https://docs.opengatellm.com/docs/):
- [Development environment](https://docs.opengatellm.com/docs/contributing/development-environment)
- [Commit and hooks](https://docs.opengatellm.com/docs/contributing/commit)
- [SQL](https://docs.opengatellm.com/docs/contributing/sql)
- [Documentation](https://docs.opengatellm.com/docs/contributing/documentation)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img src="./docs/static/img/ogl_logo.svg" alt="Logo" width="128" height="128">

# OpenGateLLM
[Documentation](https://docs.opengatellm.etalab.gouv.fr) | [API Reference](https://albert.api.etalab.gouv.fr/documentation)
### **[Documentation](https://docs.opengatellm.etalab.gouv.fr) | [API Reference](https://albert.api.etalab.gouv.fr/documentation)**

> [!WARNING]
> **The API is still under beta version, major breaking changes may occur.**
Expand Down Expand Up @@ -116,9 +116,9 @@ Explore practical use cases:
### 🤝 Contribute
***

This project exists thanks to all the people who contribute. OpenGateLLM thrives on open-source contributions. Join our community!
This project exists thanks to all the people who contribute. OpenGateLLM thrives on open-source contributions. Join our community!

Check out our [Contribution Guide](./CONTRIBUTING.md) to get started.
Check out our [Contribution Guide](https://docs.opengatellm.etalab.gouv.fr/docs/contributing) to get started.

### 🎖️ Sponsors
***
Expand Down
11 changes: 3 additions & 8 deletions api/schemas/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from api.utils.variables import (
DEFAULT_APP_NAME,
DEFAULT_TIMEOUT,
ROUTER__AUTH,
ROUTER__ADMIN,
ROUTER__AUTH,
ROUTERS,
)

Expand Down Expand Up @@ -118,7 +118,7 @@ class ModelProvider(ConfigBaseModel):
model_name: constr(strip_whitespace=True, min_length=1) = Field(..., description="Model name from the model provider.", examples=["gpt-4o"]) # fmt: off
model_cost_prompt_tokens: float = Field(default=0.0, ge=0.0, description="Model costs prompt tokens for user budget computation. The cost is by 1M tokens.", examples=[0.1]) # fmt: off
model_cost_completion_tokens: float = Field(default=0.0, ge=0.0, description="Model costs completion tokens for user budget computation. The cost is by 1M tokens.", examples=[0.1]) # fmt: off
model_carbon_footprint_zone: CountryCodes = Field(default=CountryCodes.WOR, description="Model hosting zone for carbon footprint computation (with ISO 3166-1 alpha-3 code format). For more information, see https://ecologits.ai", examples=["WOR"]) # fmt: off
model_carbon_footprint_zone: CountryCodes = Field(default=CountryCodes.WOR, description="Model hosting zone using ISO 3166-1 alpha-3 code format (e.g., `WOR` for World, `FRA` for France, `USA` for United States). This determines the electricity mix used for carbon intensity calculations. For more information, see https://ecologits.ai", examples=["WOR"]) # fmt: off
model_carbon_footprint_total_params: Optional[float] = Field(default=None, ge=0.0, description="Total params of the model in billions of parameters for carbon footprint computation. If not provided, the active params will be used if provided, else carbon footprint will not be computed. For more information, see https://ecologits.ai", examples=[8]) # fmt: off
model_carbon_footprint_active_params: Optional[float] = Field(default=None, ge=0.0, description="Active params of the model in billions of parameters for carbon footprint computation. If not provided, the total params will be used if provided, else carbon footprint will not be computed. For more information, see https://ecologits.ai", examples=[8]) # fmt: off

Expand Down Expand Up @@ -251,10 +251,6 @@ class BraveDependency(ConfigBaseModel):
timeout: int = Field(default=DEFAULT_TIMEOUT, ge=1, description="Timeout for the Brave API requests.", examples=[10]) # fmt: off


class CentraleSupelecDependency(ConfigBaseModel):
token: str = Field(description="Centrale Supélec token for testing dynamic models")


@custom_validation_error(url="https://github.com/etalab-ia/opengatellm/blob/main/docs/configuration.md#duckduckgodependency")
class DuckDuckGoDependency(ConfigBaseModel):
url: constr(strip_whitespace=True, min_length=1) = Field(default="https://api.duckduckgo.com/", description="DuckDuckGo API url.") # fmt: off
Expand Down Expand Up @@ -341,7 +337,6 @@ class EmptyDepencency(ConfigBaseModel):
class Dependencies(ConfigBaseModel):
albert: Optional[AlbertDependency] = Field(default=None, description="If provided, Albert API is used to parse pdf documents. Cannot be used with Marker dependency concurrently. Pass arguments to call Albert API in this section.") # fmt: off
brave: Optional[BraveDependency] = Field(default=None, description="If provided, Brave API is used to web search. Cannot be used with DuckDuckGo dependency concurrently. Pass arguments to call API in this section. All query parameters are supported, see https://api-dashboard.search.brave.com/app/documentation/web-search/query for more information.") # fmt: off
centralesupelec: Optional[CentraleSupelecDependency] = Field(default=None, description="Needed to pass tests where models are added")
duckduckgo: Optional[DuckDuckGoDependency] = Field(default=None, description="If provided, DuckDuckGo API is used to web search. Cannot be used with Brave dependency concurrently. Pass arguments to call API in this section. All query parameters are supported, see https://www.searchapi.io/docs/duckduckgo-api for more information.") # fmt: off
elasticsearch: Optional[ElasticsearchDependency] = Field(default=None, description="Pass all elastic python SDK arguments, see https://elasticsearch-py.readthedocs.io/en/v9.0.2/api/elasticsearch.html#elasticsearch.Elasticsearch for more information.") # fmt: off
qdrant: Optional[QdrantDependency] = Field(default=None, description="Pass all qdrant python SDK arguments, see https://python-client.qdrant.tech/qdrant_client.qdrant_client for more information.") # fmt: off
Expand Down Expand Up @@ -494,7 +489,7 @@ def validate_model(cls, values) -> Any:
@custom_validation_error(url="https://github.com/etalab-ia/opengatellm/blob/main/docs/configuration.md#all-configuration")
class ConfigFile(ConfigBaseModel):
"""
Refer to the [configuration example file](../../../config.example.yml) for an example of configuration.
Refer to the [configuration example file](https://github.com/etalab-ia/OpenGateLLM/blob/main/config.example.yml) for an example of configuration.
"""

models: List[Model] = Field(min_length=1, description="Models used by the API. At least one model must be defined.") # fmt: off
Expand Down
Loading
Loading