Skip to content

Commit 88a552b

Browse files
committed
ML/LlamaIndex: Add software tests and CI configuration
1 parent 27c218a commit 88a552b

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-0
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ updates:
114114
schedule:
115115
interval: "daily"
116116

117+
- directory: "/topic/machine-learning/llama-index"
118+
package-ecosystem: "pip"
119+
schedule:
120+
interval: "daily"
121+
117122
- directory: "/topic/machine-learning/mlops-mlflow"
118123
package-ecosystem: "pip"
119124
schedule:

.github/workflows/ml-llamaindex.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: LlamaIndex
2+
3+
on:
4+
pull_request:
5+
branches: ~
6+
paths:
7+
- '.github/workflows/ml-llamaindex.yml'
8+
- 'topic/machine-learning/llama-index/**'
9+
- '/requirements.txt'
10+
push:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/ml-llamaindex.yml'
14+
- 'topic/machine-learning/llama-index/**'
15+
- '/requirements.txt'
16+
17+
# Allow job to be triggered manually.
18+
workflow_dispatch:
19+
20+
# Run job each night after CrateDB nightly has been published.
21+
schedule:
22+
- cron: '0 3 * * *'
23+
24+
# Cancel in-progress jobs when pushing to the same branch.
25+
concurrency:
26+
cancel-in-progress: true
27+
group: ${{ github.workflow }}-${{ github.ref }}
28+
29+
jobs:
30+
test:
31+
name: "
32+
Python: ${{ matrix.python-version }}
33+
CrateDB: ${{ matrix.cratedb-version }}
34+
on ${{ matrix.os }}"
35+
runs-on: ${{ matrix.os }}
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
os: [
40+
'ubuntu-latest',
41+
]
42+
python-version: [
43+
'3.8',
44+
'3.13',
45+
]
46+
cratedb-version: [ 'nightly' ]
47+
48+
services:
49+
cratedb:
50+
image: crate/crate:${{ matrix.cratedb-version }}
51+
ports:
52+
- 4200:4200
53+
- 5432:5432
54+
env:
55+
CRATE_HEAP_SIZE: 4g
56+
57+
env:
58+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
59+
60+
steps:
61+
62+
- name: Acquire sources
63+
uses: actions/checkout@v4
64+
65+
- name: Set up Python
66+
uses: actions/setup-python@v5
67+
with:
68+
python-version: ${{ matrix.python-version }}
69+
architecture: x64
70+
cache: 'pip'
71+
cache-dependency-path: |
72+
requirements.txt
73+
topic/machine-learning/llama-index/requirements.txt
74+
topic/machine-learning/llama-index/requirements-dev.txt
75+
76+
- name: Install utilities
77+
run: |
78+
pip install -r requirements.txt
79+
80+
- name: Validate topic/machine-learning/llama-index
81+
run: |
82+
ngr test --accept-no-venv topic/machine-learning/llama-index
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE TABLE IF NOT EXISTS time_series_data (
2+
timestamp TIMESTAMP,
3+
value DOUBLE,
4+
location STRING,
5+
sensor_id INT
6+
);
7+
8+
INSERT INTO time_series_data (timestamp, value, location, sensor_id)
9+
VALUES
10+
('2023-09-14T00:00:00', 10.5, 'Sensor A', 1),
11+
('2023-09-14T01:00:00', 15.2, 'Sensor A', 1),
12+
('2023-09-14T02:00:00', 18.9, 'Sensor A', 1),
13+
('2023-09-14T03:00:00', 12.7, 'Sensor B', 2),
14+
('2023-09-14T04:00:00', 17.3, 'Sensor B', 2),
15+
('2023-09-14T05:00:00', 20.1, 'Sensor B', 2),
16+
('2023-09-14T06:00:00', 22.5, 'Sensor A', 1),
17+
('2023-09-14T07:00:00', 18.3, 'Sensor A', 1),
18+
('2023-09-14T08:00:00', 16.8, 'Sensor A', 1),
19+
('2023-09-14T09:00:00', 14.6, 'Sensor B', 2),
20+
('2023-09-14T10:00:00', 13.2, 'Sensor B', 2),
21+
('2023-09-14T11:00:00', 11.7, 'Sensor B', 2);
22+
23+
REFRESH TABLE time_series_data;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[tool.pytest.ini_options]
2+
minversion = "2.0"
3+
addopts = """
4+
-rfEX -p pytester --strict-markers --verbosity=3 --capture=no
5+
--cov=. --cov-report=term-missing --cov-report=xml
6+
"""
7+
8+
#log_level = "DEBUG"
9+
#log_cli_level = "DEBUG"
10+
11+
testpaths = [
12+
"*.py",
13+
]
14+
xfail_strict = true
15+
markers = [
16+
]
17+
18+
[tool.coverage.run]
19+
branch = false
20+
21+
[tool.coverage.report]
22+
fail_under = 0
23+
show_missing = true
24+
omit = [
25+
"conftest.py",
26+
"test*.py",
27+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cratedb-toolkit
2+
pueblo[testing]
3+
sqlparse
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
from cratedb_toolkit.io.sql import DatabaseAdapter
6+
from dotenv import load_dotenv
7+
8+
HERE = Path(__file__).parent
9+
10+
11+
@pytest.fixture()
12+
def cratedb() -> DatabaseAdapter:
13+
return DatabaseAdapter(dburi="crate://crate@localhost:4200")
14+
15+
16+
@pytest.fixture(scope="function", autouse=True)
17+
def init_database(cratedb):
18+
"""
19+
Initialize database.
20+
"""
21+
cratedb.run_sql("DROP TABLE IF EXISTS time_series_data;")
22+
cratedb.run_sql((HERE / "init.sql").read_text())
23+
24+
25+
def test_main(cratedb, capsys):
26+
"""
27+
Execute `main.py` and verify outcome.
28+
"""
29+
30+
# Load the standalone configuration also for software testing.
31+
# On CI, `OPENAI_API_KEY` will need to be supplied externally.
32+
load_dotenv("env.standalone")
33+
34+
# Invoke the workload, in-process.
35+
from main import main
36+
main()
37+
38+
# Verify the outcome.
39+
out = capsys.readouterr().out
40+
assert "Answer was: The average value for sensor 1 is approximately 17.03." in out

0 commit comments

Comments
 (0)