-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI for agent example within AI cookbook (#28)
* WIP Signed-off-by: Sid Murching <[email protected]> * WIP Signed-off-by: Sid Murching <[email protected]> * Remove lint workflow Signed-off-by: Sid Murching <[email protected]> * Add comments to utils Signed-off-by: Sid Murching <[email protected]> * Fix test Signed-off-by: Sid Murching <[email protected]> * Delete autogenerated comments Signed-off-by: Sid Murching <[email protected]> * Switch to .show() which is defined locally Signed-off-by: Sid Murching <[email protected]> --------- Signed-off-by: Sid Murching <[email protected]>
- Loading branch information
Showing
11 changed files
with
142 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Unit tests | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.10", "3.11"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r dev/dev_requirements.txt | ||
- name: Test with pytest | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
genai_cookbook/_build | ||
env | ||
.env | ||
.DS_STORE | ||
.DS_STORE | ||
.idea | ||
__pycache__ | ||
|
||
# Exclude `databricks sync` CLI command snapshots | ||
.databricks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import sys | ||
import os | ||
|
||
# Add the root directory to sys.path, so that we can treat directories like | ||
# agent_app_sample_code as modules | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
import pyspark | ||
import pandas as pd | ||
|
||
from agent_app_sample_code.utils.file_loading import load_files_to_df | ||
|
||
@pytest.fixture(scope="module") | ||
def spark(): | ||
return ( | ||
pyspark.sql.SparkSession.builder | ||
.master("local[1]") | ||
# Uncomment the following line for testing on Apple silicon locally | ||
.config("spark.driver.bindAddress", "127.0.0.1") | ||
.config("spark.task.maxFailures", "1") # avoid retry failed spark tasks | ||
.getOrCreate() | ||
) | ||
|
||
def test_load_files_to_df(spark, tmpdir): | ||
temp_dir = tmpdir.mkdir("files_subdir") | ||
file_1 = temp_dir.join("file1.txt") | ||
file_2 = temp_dir.join("file2.txt") | ||
file_1.write("file1 content") | ||
file_2.write("file2 content") | ||
raw_files_df = load_files_to_df(spark, str(temp_dir)).drop("modificationTime").orderBy("path") | ||
assert raw_files_df.count() == 2 | ||
raw_pandas_df = raw_files_df.toPandas() | ||
# Decode the content from bytes to string | ||
raw_pandas_df['content'] = raw_pandas_df['content'].apply( | ||
lambda x: bytes(x).decode('utf-8') | ||
) | ||
# Expected DataFrame | ||
expected_df = pd.DataFrame([{ | ||
"path": f"file:{str(file_1)}", | ||
"length": len("file1 content"), | ||
"content": "file1 content", | ||
}, { | ||
"path": f"file:{str(file_2)}", | ||
"length": len("file2 content"), | ||
"content": "file2 content", | ||
}]) | ||
pd.testing.assert_frame_equal(raw_pandas_df, expected_df) | ||
|
||
def test_load_files_to_df_throws_if_no_files(spark, tmpdir): | ||
temp_dir = tmpdir.mkdir("files_subdir") | ||
with pytest.raises(Exception, match="does not contain any files"): | ||
load_files_to_df(spark, str(temp_dir)) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
jupyter-book | ||
livereload | ||
livereload | ||
black | ||
pytest | ||
mlflow-skinny[databricks] | ||
databricks-vectorsearch | ||
pyspark | ||
pandas |