Kyryll Kochkin commited on
Commit
e3a85d7
·
1 Parent(s): 2d9d40b

Fail live model probe on API errors

Browse files
.github/workflows/tests.yml ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Run tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ tests:
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ include:
14
+ - name: Unit tests
15
+ run_live: "0"
16
+ command: pytest
17
+ api_base_url: "https://k050506koch-gpt3-dev-api.hf.space"
18
+ - name: Live model probe
19
+ run_live: "1"
20
+ command: pytest -k live_more_models
21
+ api_base_url: "https://k050506koch-gpt3-dev-api.hf.space"
22
+
23
+ runs-on: ubuntu-latest
24
+ name: ${{ matrix.name }}
25
+
26
+ steps:
27
+ - name: Check out repository
28
+ uses: actions/checkout@v4
29
+
30
+ - name: Set up Python
31
+ uses: actions/setup-python@v5
32
+ with:
33
+ python-version: '3.13'
34
+
35
+ - name: Install dependencies
36
+ run: |
37
+ python -m pip install --upgrade pip
38
+ pip install -r requirements-test.txt
39
+
40
+ - name: Run tests
41
+ env:
42
+ RUN_LIVE_API_TESTS: ${{ matrix.run_live }}
43
+ API_BASE_URL: ${{ matrix.api_base_url }}
44
+ run: ${{ matrix.command }}
README.md CHANGED
@@ -125,7 +125,7 @@ export RUN_LIVE_API_TESTS=0 #or 1
125
  ```
126
  ```bash
127
  pytest
128
- pytest -k pytest -k live_more_models
129
  ```
130
 
131
  ## Project Structure
 
125
  ```
126
  ```bash
127
  pytest
128
+ pytest -k live_more_models
129
  ```
130
 
131
  ## Project Structure
requirements-test.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ fastapi>=0.110.0
2
+ httpx>=0.27.0
3
+ pytest>=7.4.0
4
+ pytest-asyncio>=0.23.0
5
+ pydantic>=2.6.0
6
+ pydantic-settings>=2.1.0
7
+ sse-starlette>=1.6.5
8
+ python-multipart>=0.0.9
9
+ tiktoken>=0.5.2
tests/test_live_more_models.py CHANGED
@@ -1,9 +1,8 @@
1
  """Additional live API tests to exercise multiple models.
2
 
3
  Skipped by default; set RUN_LIVE_API_TESTS=1 to enable.
4
- This test is lenient: if a model is listed by /v1/models but is not
5
- actually usable (e.g., missing HF auth or unavailable backend), the
6
- test skips that case instead of failing the suite.
7
  """
8
  from __future__ import annotations
9
 
@@ -57,9 +56,12 @@ def test_completion_for_models(model: str) -> None:
57
  with httpx.Client(timeout=timeout) as client:
58
  resp = client.post(f"{BASE_URL}/v1/completions", json=payload)
59
 
60
- if resp.status_code != 200:
61
- pytest.skip(
62
- f"model {model} not usable on server (status={resp.status_code}): {resp.text[:500]}"
 
 
 
63
  )
64
 
65
  body = resp.json()
 
1
  """Additional live API tests to exercise multiple models.
2
 
3
  Skipped by default; set RUN_LIVE_API_TESTS=1 to enable.
4
+ The suite skips candidates that are missing from /v1/models but now
5
+ fails whenever the live API returns an error so issues surface in CI.
 
6
  """
7
  from __future__ import annotations
8
 
 
56
  with httpx.Client(timeout=timeout) as client:
57
  resp = client.post(f"{BASE_URL}/v1/completions", json=payload)
58
 
59
+ try:
60
+ resp.raise_for_status()
61
+ except httpx.HTTPStatusError as exc: # pragma: no cover - only hit when live API misbehaves
62
+ pytest.fail(
63
+ f"model {model} returned an error response: "
64
+ f"{exc.response.status_code} {exc.response.text[:500]}"
65
  )
66
 
67
  body = resp.json()