Skip to content

Commit 9277aac

Browse files
Merge pull request #70 from AET-DevOps25/genai_tests
Add tests to genai
2 parents 0c71f4f + 79cde45 commit 9277aac

File tree

10 files changed

+59
-19
lines changed

10 files changed

+59
-19
lines changed

.github/workflows/genai-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
uv pip install -r ./genai/requirements.txt --system
2727
2828
- name: GenAI tests
29+
env:
30+
OPEN_WEB_UI_API_KEY: ${{ secrets.OPEN_WEB_UI_API_KEY }}
31+
API_URL: ${{ vars.API_URL }}
2932
run: |
3033
cd genai
3134
pytest

compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ services:
120120
DB_HOST: ${DB_HOST:-weaviate}
121121
DB_PORT: ${DB_PORT:-9090}
122122
DB_GRPC_PORT: ${DB_GRPC_PORT:-50051}
123+
OPEN_WEB_UI_API_KEY: ${OPEN_WEB_UI_API_KEY}
124+
SERVER_URL: ${SERVER_URL:-http://localhost:9091}
125+
CLIENT_URL: ${CLIENT_URL:-http://localhost:3000}
126+
GENAI_URL: ${GENAI_URL:-http://localhost:8000}
127+
API_URL: ${API_URL:-https://gpu.aet.cit.tum.de/api/chat/completions}
123128
depends_on:
124129
- weaviate
125130
volumes:

genai/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
CHAIR_API_KEY=your-api-key-here
1+
OPEN_WEB_UI_API_KEY=your-api-key-here
2+
API_URL="https://your-api-url-here"

genai/app/main.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
router = APIRouter()
2121

2222
# Environment configuration
23-
CHAIR_API_KEY = os.getenv("CHAIR_API_KEY")
24-
API_URL = "https://gpu.aet.cit.tum.de/api/chat/completions"
25-
23+
OPEN_WEB_UI_API_KEY = os.getenv("OPEN_WEB_UI_API_KEY")
24+
API_URL = os.getenv("API_URL")
25+
SERVER_URL = os.getenv("SERVER_URL")
26+
CLIENT_URL = os.getenv("CLIENT_URL")
27+
GENAI_URL = os.getenv("GENAI_URL")
2628

2729
class OpenWebUILLM(LLM):
2830
api_url: str = API_URL
29-
api_key: str = CHAIR_API_KEY
31+
api_key: str = OPEN_WEB_UI_API_KEY
3032
model_name: str = "llama3.3:latest"
3133

3234
@property
@@ -41,7 +43,7 @@ def _call(
4143
**kwargs: Any,
4244
) -> str:
4345
if not self.api_key:
44-
raise ValueError("CHAIR_API_KEY environment variable is required")
46+
raise ValueError("API_KEY environment variable is required")
4547

4648
headers = {
4749
"Authorization": f"Bearer {self.api_key}",
@@ -97,14 +99,14 @@ def custom_openapi():
9799
title=app.title,
98100
version=app.version,
99101
routes=app.routes,
100-
servers=[{"url": "http://localhost:8000"}],
102+
servers=[{"url": GENAI_URL}],
101103
)
102104
)
103105

104106

105107
app.add_middleware(
106108
CORSMiddleware,
107-
allow_origins=["http://localhost:3000", "http://localhost:9091"],
109+
allow_origins=[CLIENT_URL, SERVER_URL],
108110
allow_credentials=True,
109111
allow_methods=["*"],
110112
allow_headers=["*"],

genai/app/test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from fastapi.testclient import TestClient
2+
from app.main import app
3+
4+
client = TestClient(app)
5+
6+
def test_health_check():
7+
response = client.get("/health")
8+
assert response.status_code == 200
9+
assert "status" in response.json()
10+
11+
12+
def test_completion():
13+
payload = {"user_text": ["This is a test input."]}
14+
response = client.post("/completion", json=payload)
15+
assert response.status_code == 200
16+
assert "llm_response" in response.json()
17+
18+
def test_summarization():
19+
payload = {"user_text": ["This is a long sentence that needs summarizing."]}
20+
response = client.post("/summarization", json=payload)
21+
assert response.status_code == 200
22+
assert "llm_response" in response.json()
23+
24+
25+
def test_rephrase():
26+
payload = {"user_text": ["This is a sample sentence."]}
27+
response = client.post("/rephrase", json=payload)
28+
assert response.status_code == 200
29+
assert "llm_response" in response.json()

genai/pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,13 @@ line-ending = "auto"
7474
#
7575
# This only has an effect when the `docstring-code-format` setting is
7676
# enabled.
77-
#docstring-code-line-length = "dynamic"
77+
#docstring-code-line-length = "dynamic"
78+
79+
[tool.pytest.ini_options]
80+
asyncio_mode = "auto"
81+
testpaths = ["app"]
82+
python_files = ["test_*.py", "*_test.py", "test.py"]
83+
addopts = "-v"
84+
markers = [
85+
"asyncio: mark test as an async test",
86+
]

genai/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
annotated-types==0.7.0
2-
anyio==4.9.0
32
authlib==1.3.1
43
certifi==2025.4.26
54
cffi==1.17.1
65
click==8.1.8
7-
cryptography==44.0.3
6+
cryptography==43.0.3
87
deprecation==2.1.0
98
dnspython==2.7.0
109
email-validator==2.2.0

genai/tests/__init__.py

Whitespace-only changes.

genai/tests/routes/__init__.py

Whitespace-only changes.

genai/tests/routes/test_root.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)