-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nbtest job to the GitHub Actions CI
- Loading branch information
1 parent
fb3ea3a
commit 7b442fb
Showing
13 changed files
with
151 additions
and
69 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,38 @@ | ||
name: notebook-tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- notebooks/** | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- notebooks/** | ||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
services: | ||
elasticsearch: | ||
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0 | ||
env: | ||
discovery.type: single-node | ||
xpack.security.enabled: false | ||
xpack.security.http.ssl.enabled: false | ||
xpack.license.self_generated.type: trial | ||
ports: | ||
- 9200:9200 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
- name: Setup nbtest | ||
run: make nbtest | ||
- name: Warm up | ||
run: sleep 30 && bin/nbtest notebooks/search/00-quick-start.ipynb >/dev/null 2>&1 | ||
- name: Run tests | ||
run: PATCH_ES=1 FORCE_COLOR=1 make -s test |
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,28 +1,20 @@ | ||
# this is the list of notebooks that are integrated with the testing framework | ||
NOTEBOOKS = $(shell bin/find-notebooks-to-test.sh) | ||
|
||
.PHONY: install pre-commit nbtest test notebooks | ||
|
||
test: nbtest notebooks | ||
|
||
notebooks: search document-chunking model-upgrades langchain | ||
|
||
search: | ||
$(MAKE) -C notebooks/search | ||
|
||
document-chunking: | ||
$(MAKE) -C notebooks/document-chunking | ||
|
||
model-upgrades: | ||
$(MAKE) -C notebooks/model-upgrades | ||
|
||
langchain: | ||
$(MAKE) -C notebooks/langchain | ||
notebooks: | ||
bin/nbtest $(NOTEBOOKS) | ||
|
||
install: pre-commit nbtest | ||
|
||
pre-commit: | ||
python -m venv .venv | ||
.venv/bin/pip install -r requirements-dev.txt | ||
.venv/bin/pip install -qqq -r requirements-dev.txt | ||
.venv/bin/pre-commit install | ||
|
||
nbtest: | ||
python3 -m venv .venv | ||
.venv/bin/pip install elastic-nbtest | ||
.venv/bin/pip install -qqq elastic-nbtest |
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,25 @@ | ||
#!/bin/bash | ||
# add any notebooks that are currently not testable to the exemptions list | ||
EXEMPT_NOTEBOOKS=( | ||
"notebooks/search/07-inference.ipynb" | ||
"notebooks/langchain/langchain-vector-store.ipynb" | ||
"notebooks/langchain/self-query-retriever-examples/chatbot-example.ipynb" | ||
"notebooks/langchain/self-query-retriever-examples/chatbot-with-bm25-only-example.ipynb" | ||
"notebooks/langchain/self-query-retriever-examples/langchain-self-query-retriever.ipynb" | ||
"notebooks/langchain/multi-query-retriever-examples/chatbot-with-multi-query-retriever.ipynb" | ||
"notebooks/langchain/multi-query-retriever-examples/langchain-multi-query-retriever.ipynb" | ||
"notebooks/generative-ai/question-answering.ipynb" | ||
"notebooks/generative-ai/chatbot.ipynb" | ||
"notebooks/integrations/amazon-bedrock/langchain-qa-example.ipynb" | ||
"notebooks/integrations/llama-index/intro.ipynb" | ||
"notebooks/integrations/gemini/vector-search-gemini-elastic.ipynb" | ||
"notebooks/integrations/gemini/qa-langchain-gemini-elasticsearch.ipynb" | ||
"notebooks/integrations/openai/openai-KNN-RAG.ipynb" | ||
) | ||
|
||
ALL_NOTEBOOKS=$(find notebooks -name "*.ipynb" | grep -v "_nbtest" | grep -v ".ipynb_checkpoints" | sort) | ||
for notebook in $ALL_NOTEBOOKS; do | ||
if [[ ! "${EXEMPT_NOTEBOOKS[@]}" =~ $notebook ]]; then | ||
echo $notebook | ||
fi | ||
done |
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,18 @@ | ||
# This module is provided to nbtest when running under GitHub Actions CI to | ||
# mock the Elasticsearch client to always connect on localhost, regardless of | ||
# arguments provided | ||
|
||
import elasticsearch | ||
|
||
orig_es_init = elasticsearch.Elasticsearch.__init__ | ||
|
||
|
||
def patched_es_init(self, *args, **kwargs): | ||
if 'cloud_id' in kwargs: | ||
assert kwargs['cloud_id'] == 'foo' | ||
if 'api_key' in kwargs: | ||
assert kwargs['api_key'] == 'bar' | ||
return orig_es_init(self, 'http://localhost:9200') | ||
|
||
|
||
elasticsearch.Elasticsearch.__init__ = patched_es_init |
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,41 @@ | ||
import os | ||
import sys | ||
|
||
|
||
def patch_elasticsearch(): | ||
# preserve the original import path | ||
saved_path = sys.path.copy() | ||
|
||
# remove the path entry that refers to this directory | ||
for path in sys.path: | ||
if not path.startswith('/'): | ||
path = os.path.join(os.getcwd(), path) | ||
if __file__ == os.path.join(path, 'elasticsearch.py'): | ||
sys.path.remove(path) | ||
break | ||
|
||
# remove this module, and import the real one instead | ||
del sys.modules['elasticsearch'] | ||
import elasticsearch | ||
|
||
# restore the import path | ||
sys.path = saved_path | ||
|
||
# preserve the original Elasticsearch.__init__ method | ||
orig_es_init = elasticsearch.Elasticsearch.__init__ | ||
|
||
# patched version of Elasticsearch.__init__ that connects to self-hosted | ||
# regardless of connection arguments given | ||
def patched_es_init(self, *args, **kwargs): | ||
if 'cloud_id' in kwargs: | ||
assert kwargs['cloud_id'] == 'foo' | ||
if 'api_key' in kwargs: | ||
assert kwargs['api_key'] == 'bar' | ||
return orig_es_init(self, 'http://localhost:9200') | ||
|
||
# patch Elasticsearch.__init__ | ||
elasticsearch.Elasticsearch.__init__ = patched_es_init | ||
|
||
|
||
patch_elasticsearch() | ||
del patch_elasticsearch |
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 was deleted.
Oops, something went wrong.
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,2 @@ | ||
masks: | ||
- 'Score: [0-9]+\.[0-9][0-9]*' |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.