Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/ultralytics-8.3.48
Browse files Browse the repository at this point in the history
  • Loading branch information
dreadatour authored Dec 10, 2024
2 parents 2df6908 + 415454a commit afe5470
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, windows-latest]
pyv: ['3.9', '3.12']
group: ['get_started', 'llm_and_nlp or computer_vision', 'multimodal']
exclude:
Expand Down Expand Up @@ -166,9 +166,12 @@ jobs:
- name: Install nox
run: uv pip install nox --system

# HF runs against actual API - thus run it only once
- name: Set hf token
if: matrix.os == 'ubuntu-latest' && matrix.pyv == '3.12'
run: echo 'HF_TOKEN=${{ secrets.HF_TOKEN }}' >> "$GITHUB_ENV"

- name: Run examples
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: nox -s examples -p ${{ matrix.pyv }} -- -m "${{ matrix.group }}"

check:
Expand Down
43 changes: 23 additions & 20 deletions tests/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,9 @@
]
)

llm_and_nlp_examples = sorted(
[
filename
for filename in glob.glob("examples/llm_and_nlp/**/*.py", recursive=True)
# no anthropic token, HF runs against actual API - thus run it only once
if "claude" not in filename
and (
"hf-" not in filename
or (sys.platform == "darwin" and sys.version_info >= (3, 12))
)
]
)
llm_and_nlp_examples = sorted(glob.glob("examples/llm_and_nlp/**/*.py", recursive=True))

multimodal_examples = sorted(
[
filename
for filename in glob.glob("examples/multimodal/**/*.py", recursive=True)
# no OpenAI token
if "openai" not in filename
]
)
multimodal_examples = sorted(glob.glob("examples/multimodal/**/*.py", recursive=True))

computer_vision_examples = sorted(
[
Expand Down Expand Up @@ -84,13 +66,34 @@ def test_get_started_examples(example):
@pytest.mark.llm_and_nlp
@pytest.mark.parametrize("example", llm_and_nlp_examples)
def test_llm_and_nlp_examples(example):
name = os.path.basename(example)
if "hf-" in name:
import huggingface_hub

if not huggingface_hub.get_token():
pytest.skip("Hugging Face token not set")
if "claude" in name and "ANTHROPIC_API_KEY" not in os.environ:
pytest.skip("ANTHROPIC_API_KEY not set")
if "unstructured-summary-map" in name:
import nltk

# pre-download nltk data manually
# Older version of unstructured uses their own hosted dataset, which is down.
# See: https://github.com/Unstructured-IO/unstructured/issues/3795.
# We cannot update to the latest version of unstructured because of https://github.com/Unstructured-IO/unstructured/issues/3731.

nltk.download("averaged_perceptron_tagger_eng", quiet=True)
nltk.download("punkt_tab", quiet=True)

smoke_test(example)


@pytest.mark.examples
@pytest.mark.multimodal
@pytest.mark.parametrize("example", multimodal_examples)
def test_multimodal(example):
if "openai" in os.path.basename(example) and "OPENAI_API_KEY" not in os.environ:
pytest.skip("OPENAI_API_KEY not set")
smoke_test(
example,
{
Expand Down

0 comments on commit afe5470

Please sign in to comment.