Contributing
This page provides the general guidelines for contributing to the Gen AI SDK.
Requirements
Below are the requirements needed to contribute to the Gen AI SDK.
Python 3.11+
Although not required, it is recommended to use Miniconda to manage python environments.
Poetry 2.1.3+
Please refer to the installation guide. After installing, close and re-open the terminal window for the changes to take effect.
gcloud CLI
Please refer to the installation guide. After installing, please run
gcloud auth login
to authorize gcloud to access the Cloud Platform with Google user credentials.
Getting Started
Below are the step-by-step guideline to setup a development environment for a Gen AI SDK module:
Go to the module directory by running cd libs/gllm-<module_name>
. Optionally, the gllm-<module_name>
module folder can also be opened using an IDE (e.g. Cursor).
Configure poetry permission to access Google Cloud repositories. These permissions can expire. If you get authorization errors after a while, please simply rerun these commands.
poetry config http-basic.gen-ai oauth2accesstoken "$(gcloud auth print-access-token)"
poetry config http-basic.gen-ai-internal oauth2accesstoken "$(gcloud auth print-access-token)"
poetry config http-basic.gen-ai-publication oauth2accesstoken "$(gcloud auth print-access-token)"
poetry config http-basic.gen-ai-internal-publication oauth2accesstoken "$(gcloud auth print-access-token)"
Install the module dependencies.
poetry install --all-extras
Install pre-commit hooks. This will make sure our code is compliant with the style guide before committing.
pre-commit install --config ../../.pre-commit-config.yaml
Test Files
The test files for each module are located in the gllm-<module_name>/tests
directory, which further contains 2 subdirectories:
unit_tests
: Contains the unit tests for the module.integration_tests
: Contains the integration tests for the module.
Any prerequisites and setup required to run the integration tests must be put in the respective module's README.md
file.
To run the tests, please use:
poetry run coverage run -m pytest
To see the coverage report, please use:
poetry run coverage report -i -m --skip-empty
Dependencies Management
Below are the conventions for the Gen AI SDK modules dependencies management:
Arrangements:
Dependencies must be sorted alphabetically by default.
Dependencies may be grouped if necessary.
Dependencies should be arranged as follows:
python = ">=3.11,<3.xx" poetry = "^2.1.3" gllm-<package_name> = { version = "^0.x.0", source = "gen-ai-internal" } <other_package_name> = "^x.y.z"
To modify the dependencies for the module, either:
Manually update the
pyproject.toml
file, then runpoetry lock --no-cache --regenerate
Use poetry commands:
To add package:
poetry add <package_name>
.To remove package:
poetry remove <package_name>
.To update package:
poetry update <package_name>
.
After using poetry commands, please adjust the package ordering accordingly.
After modifying dependencies, please make sure to commit the updated
poetry.lock
.Versioning:
For stable packages (major version >= 1), please use
^x.y.z
, e.g.pandas = "^2.2.3"
.For unstable packages (major version = 0), please use
>=0.y.z,<0.y+1.z
, e.g.fastapi = ">=0.115.0,<0.116.0"
.If necessary, package can be locked strictly to a specific version, e.g.
transformers = "4.46.1"
. However, please be careful as this may cause version conflict between modules.
Code Convention
Below are the code convention for the Gen AI SDK:
For general code convention, please refer to the Python Style Guide.
Modules are located in the
libs
directory. Each module has its own directory with the following structure:<snake_case_module_name>
: contains the source code for the module.tests
: contains the tests for the module.pyproject.toml
: contains the configuration for the module.poetry.lock
: contains the dependencies for the module.README.md
: contains the documentation for the module.
For logging, please use our logger manager:
For function logging, define the logger outside of the function:
logger = LoggerManager().get_logger() def my_function(): logger.info("This is an info") logger.warning("This is a warning") logger.error("This is an error")
For class logging, please set the logger as a protected attribute:
class MyClass: def __init__(): self._logger = LoggerManager().get_logger() def method(): self._logger.info("This is an info") self._logger.warning("This is a warning") self._logger.error("This is an error")
For deprecation, please use our deprecated decorator.
To deprecate a function, simply add the decorator:
@deprecated(deprecated_in="0.1.20", removed_in="0.2.0") def deprecated_function(): pass
To deprecate a class, add the decorator to the constructor:
class DeprecatedClass: @deprecated(deprecated_in="0.1.20", removed_in="0.2.0") def __init__(): pass
For optional packages, please use our check optional packages util as follows:
To use an optional package in a function, put the checker and import in the function:
def my_function(): check_optional_packages("package", extras="extra") from package import Module return Module(...)
To use an optional package in a class, put the checker and import in the class constructor:
class MyClass: def __init__(): check_optional_packages("package", extras="extra") from package import Module self.module = Module(...)
Contributing General Flow
The general steps for contributing to the Gen AI SDK are as follows:
Create a new branch from main
.
Work on the branch to apply the changes.
Commit the changes. If any dependency are modified, please dont forget to also commit the poetry.lock
file.
Push the changes.
Create a PR. The PR description should contain the following:
Description: Brief description on what the PR is about.
Changes: Bulleted list of specific modifications and their purpose.
How to Test: Provide a brief guidelines for the reviewers to verify the changes.
Request for reviews:
At least 2 approval are required in order to merge the PR, 1 on which should be from the Gen AI SDK team. Please communicate with the Gen AI SDK team whenever help is needed for PR reviews.
Merge the PR. Please always use Squash and Merge
.
Create a release for the merged changes:
Go to the Draft a new release page.
Click on
Choose a Tag
.The tag name should follow the following convention:
Format:
gllm_<package_name>-v<major>.<minor>.<patch>
.The version should be updated as follows:
If your changes contain breaking changes, please bump the minor version.
Otherwise, please bump the patch version.
For example, say you've just made changes to the GLLM Core module, and its current latest tag is
gllm_core-v0.2.5
(The latest tag should be visible when you start typing the tag name):If your changes contain breaking changes, please create
gllm_core-v0.3.0
.Otherwise, please create
gllm_core-v0.2.6
.
Click on
Generate release note
and adjust the message accordingly.Click on
Publish release
to create the release.
Verifying build:
After creating the release, go to the Build binary page.
Find the recent release's build.
Please make sure that all jobs are executed successfully, which means the changes are ready to be used.
If there are any failing builds, please consult to the Gen AI SDK team or the DSO team, as unattended failing builds may result in versioning problem in the future due to missing build.
Creating New Package
Coming soon!
Github Issues
For feature request or bug report, feel free to open a Github issue.
Static Code Analysis
When creating a Pull Request and a commit is pushed to GitHub, it will trigger an SCA job.
To request access to the SCA report, please fill out this ticket form by including the project keys of each modules.
You can check the project key in
./sonar-project.properties
of each module (example: gllm-core).
Last updated