Skip to content

Commit aa250e3

Browse files
authored
Merge pull request #19 from ruivieira/RHOAIENG-21043-proto
feat(RHOAIENG-21043): Add protobuf support
2 parents 6be5c1b + caf7437 commit aa250e3

25 files changed

+4453
-243
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Python Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.11"]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
cache: "pip"
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install uv
30+
python -m venv .venv
31+
source .venv/bin/activate
32+
if [ -f pyproject.toml ]; then
33+
uv pip install -e ".[dev,protobuf]"
34+
else
35+
uv pip install pytest
36+
fi
37+
38+
- name: Install protobuf compiler
39+
run: |
40+
sudo apt-get update
41+
sudo apt-get install -y protobuf-compiler
42+
43+
- name: Generate protobuf stubs
44+
run: |
45+
source .venv/bin/activate
46+
bash scripts/generate_protos.sh
47+
48+
- name: Run tests with pytest
49+
run: |
50+
source .venv/bin/activate
51+
pytest tests/ -v --cov=src --cov-report=xml
52+
53+
- name: Upload coverage to Codecov
54+
uses: codecov/codecov-action@v4
55+
with:
56+
file: ./coverage.xml
57+
fail_ci_if_error: false

.sourcery.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
ignore_branches:
2-
- "dependabot/**"

README.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TrustyAI Service
22

3-
👋 The TrustyAI Service is intended to a hub for all kinds of Responsible AI workflows, such as
3+
👋 The TrustyAI Service is intended to be a hub for all kinds of Responsible AI workflows, such as
44
explainability, drift, and Large Language Model (LLM) evaluation. Designed as a REST server wrapping
55
a core Python library, the TrustyAI service is intended to be a tool that can operate in a local
66
environment, a Jupyter Notebook, or in Kubernetes.
@@ -15,7 +15,7 @@ environment, a Jupyter Notebook, or in Kubernetes.
1515
- Meanshift
1616

1717
### ⚖️ Fairness ⚖️
18-
- Statistical Parity Difference
18+
- Statistical Parity Difference
1919
- Disparate Impact Ratio
2020
- Average Odds Ratio (WIP)
2121
- Average Predictive Value Difference (WIP)
@@ -52,6 +52,11 @@ podman build -t $IMAGE_NAME .
5252
podman build -t $IMAGE_NAME --build-arg EXTRAS=eval .
5353
````
5454
55+
### Locally (With ModelMesh/Protobuf Support)
56+
```bash
57+
uv pip install .[protobuf]
58+
````
59+
5560

5661
## 🏃Running 🏃‍♀️
5762
### Locally
@@ -64,7 +69,50 @@ uv run uvicorn src.main --host 0.0.0.0 --port 8080
6469
podman run -t $IMAGE_NAME -p 8080:8080 .
6570
```
6671

72+
## 🧪 Testing 🧪
73+
### Running All Tests
74+
To run all tests in the project:
75+
```bash
76+
python -m pytest
77+
```
78+
79+
Or with more verbose output:
80+
```bash
81+
python -m pytest -v
82+
```
83+
84+
### Running with Coverage
85+
To run tests with coverage reporting:
86+
```bash
87+
python -m pytest --cov=src
88+
```
89+
90+
---
91+
## 🔄 Protobuf Support 🔄
92+
To process model inference data from ModelMesh models, you can install protobuf support. Otherwise, only KServe models will be supported.
93+
94+
### Installing Dependencies
95+
Install the required dependencies for protobuf support:
96+
```bash
97+
uv pip install -e ".[protobuf]"
98+
```
99+
100+
### Generating Protobuf Code
101+
After installing dependencies, generate Python code from the protobuf definitions:
102+
103+
```bash
104+
# From the project root
105+
bash scripts/generate_protos.sh
106+
```
107+
108+
### Testing Protobuf Functionality
109+
Run the tests for the protobuf implementation:
110+
111+
```bash
112+
# From the project root
113+
python -m pytest tests/service/data/test_modelmesh_parser.py -v
114+
```
115+
67116
---
68117
## ☎️ API ☎️
69118
When the service is running, visit `localhost:8080/docs` to see the OpenAPI documentation!
70-

pyproject.toml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
name = "trustyai-service"
33
version = "1.0.0rc0"
44
description = "TrustyAI Service"
5-
authors = [
6-
{ name = "Rui Vieira" },
7-
{ name = "TrustyAI team" },
8-
]
5+
authors = [{ name = "Rui Vieira" }, { name = "TrustyAI team" }]
96
requires-python = "~=3.11"
107
readme = "README.md"
118
dependencies = [
@@ -29,11 +26,8 @@ dev = [
2926
"pytest-cov>=4.1.0,<5",
3027
"httpx>=0.25.0,<0.26",
3128
]
32-
eval = [
33-
"lm-eval[api]==0.4.4",
34-
"fastapi-utils>=0.8.0",
35-
"typing-inspect==0.9.0",
36-
]
29+
eval = ["lm-eval[api]==0.4.4", "fastapi-utils>=0.8.0", "typing-inspect==0.9.0"]
30+
protobuf = ["numpy>=1.24.0,<2", "grpcio>=1.62.1,<2", "grpcio-tools>=1.62.1,<2"]
3731

3832
[tool.hatch.build.targets.sdist]
3933
include = ["src"]

scripts/generate_protos.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Script to generate protobuf stubs
3+
4+
set -e
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
PROTO_DIR="${SCRIPT_DIR}/../src/proto"
8+
9+
echo "Generating Python protobuf stubs..."
10+
cd "${PROTO_DIR}"
11+
12+
PROTO_FILES=$(find . -name "*.proto")
13+
if [ -z "$PROTO_FILES" ]; then
14+
echo "No .proto files found in ${PROTO_DIR}"
15+
exit 1
16+
fi
17+
18+
for PROTO_FILE in $PROTO_FILES; do
19+
echo "Compiling ${PROTO_FILE}..."
20+
protoc --python_out=. --proto_path=. "$PROTO_FILE"
21+
done
22+
23+
if [ ! -f "__init__.py" ]; then
24+
echo "# Generated protobuf package" > "__init__.py"
25+
echo "Created __init__.py file"
26+
fi
27+
28+
echo "Protobuf generation completed successfully!"

0 commit comments

Comments
 (0)