From 593079fb6887ddaabe9bb931d1df05580b9c7c89 Mon Sep 17 00:00:00 2001 From: "bahawal.baloch" Date: Thu, 14 May 2026 17:43:44 +0500 Subject: [PATCH] Update Dockerfile for caching and modify req.txt for platform-specific dependencies; add smoke test for Google Custom Search API --- Dockerfile | 12 ++++++---- req.txt | 41 ++++++++++++++++--------------- test_search_api.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 test_search_api.py diff --git a/Dockerfile b/Dockerfile index fac9ba9..8cf1868 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,22 @@ +# syntax=docker/dockerfile:1.6 FROM python:3.13-slim ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ - PIP_NO_CACHE_DIR=1 \ PYTHONPATH=/app WORKDIR /app -RUN apt-get update && apt-get install -y --no-install-recommends \ +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get update && apt-get install -y --no-install-recommends \ build-essential \ curl \ - git \ - && rm -rf /var/lib/apt/lists/* + git COPY req.txt ./ -RUN pip install --upgrade pip && pip install -r req.txt +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install --upgrade pip && pip install -r req.txt COPY dev_backend ./dev_backend COPY custom_search_api ./custom_search_api diff --git a/req.txt b/req.txt index bd27ef8..ac7e2c3 100644 --- a/req.txt +++ b/req.txt @@ -5,9 +5,9 @@ asyncmy==0.2.11 certifi==2026.4.22 click==8.3.3 contourpy==1.3.3 -cuda-bindings==13.2.0 -cuda-pathfinder==1.5.4 -cuda-toolkit==13.0.2 +cuda-bindings==13.2.0 ; sys_platform == "linux" +cuda-pathfinder==1.5.4 ; sys_platform == "linux" +cuda-toolkit==13.0.2 ; sys_platform == "linux" cycler==0.12.1 et_xmlfile==2.0.0 fastapi==0.136.1 @@ -23,6 +23,7 @@ httpcore==1.0.9 httpx==0.28.1 hyperframe==6.1.0 idna==3.13 +imagehash==4.3.2 Jinja2==3.1.6 joblib==1.5.3 kiwisolver==1.5.0 @@ -31,21 +32,21 @@ matplotlib==3.10.9 mpmath==1.3.0 networkx==3.6.1 numpy==2.4.4 -nvidia-cublas==13.1.0.3 -nvidia-cuda-cupti==13.0.85 -nvidia-cuda-nvrtc==13.0.88 -nvidia-cuda-runtime==13.0.96 -nvidia-cudnn-cu13==9.19.0.56 -nvidia-cufft==12.0.0.61 -nvidia-cufile==1.15.1.6 -nvidia-curand==10.4.0.35 -nvidia-cusolver==12.0.4.66 -nvidia-cusparse==12.6.3.3 -nvidia-cusparselt-cu13==0.8.0 -nvidia-nccl-cu13==2.28.9 -nvidia-nvjitlink==13.0.88 -nvidia-nvshmem-cu13==3.4.5 -nvidia-nvtx==13.0.85 +nvidia-cublas==13.1.0.3 ; sys_platform == "linux" +nvidia-cuda-cupti==13.0.85 ; sys_platform == "linux" +nvidia-cuda-nvrtc==13.0.88 ; sys_platform == "linux" +nvidia-cuda-runtime==13.0.96 ; sys_platform == "linux" +nvidia-cudnn-cu13==9.19.0.56 ; sys_platform == "linux" +nvidia-cufft==12.0.0.61 ; sys_platform == "linux" +nvidia-cufile==1.15.1.6 ; sys_platform == "linux" +nvidia-curand==10.4.0.35 ; sys_platform == "linux" +nvidia-cusolver==12.0.4.66 ; sys_platform == "linux" +nvidia-cusparse==12.6.3.3 ; sys_platform == "linux" +nvidia-cusparselt-cu13==0.8.0 ; sys_platform == "linux" +nvidia-nccl-cu13==2.28.9 ; sys_platform == "linux" +nvidia-nvjitlink==13.0.88 ; sys_platform == "linux" +nvidia-nvshmem-cu13==3.4.5 ; sys_platform == "linux" +nvidia-nvtx==13.0.85 ; sys_platform == "linux" openpyxl==3.1.5 packaging==26.2 pandas==3.0.2 @@ -58,10 +59,12 @@ pyparsing==3.3.2 python-dateutil==2.9.0.post0 python-dotenv==1.2.2 qdrant-client==1.17.1 +requests==2.34.1 scikit-learn==1.8.0 scipy==1.17.1 setuptools==81.0.0 six==1.17.0 +sqlmodel==0.0.22 SQLAlchemy==2.0.49 starlette==1.0.0 sympy==1.14.0 @@ -69,7 +72,7 @@ threadpoolctl==3.6.0 torch==2.11.0 torchvision==0.26.0 tqdm==4.67.3 -triton==3.6.0 +triton==3.6.0 ; sys_platform == "linux" typing-inspection==0.4.2 typing_extensions==4.15.0 urllib3==2.6.3 diff --git a/test_search_api.py b/test_search_api.py new file mode 100644 index 0000000..5f1f677 --- /dev/null +++ b/test_search_api.py @@ -0,0 +1,60 @@ +"""Quick smoke test that hits Google Custom Search API directly. + +Reads GEMINI_API_KEY and SEARCH_ENGINE_ID from .env and confirms credentials +work without going through the FastAPI service. +""" +import os +import sys +import requests +from dotenv import load_dotenv + +load_dotenv() + +GOOGLE_CSE_ENDPOINT = "https://www.googleapis.com/customsearch/v1" +API_KEY = os.getenv("GEMINI_API_KEY") +CX = os.getenv("SEARCH_ENGINE_ID") + +QUERY = sys.argv[1] if len(sys.argv) > 1 else "lectures" +NUM = int(sys.argv[2]) if len(sys.argv) > 2 else 5 + + +def main(): + if not API_KEY: + print("[FAIL] GEMINI_API_KEY not set in .env") + sys.exit(1) + if not CX: + print("[FAIL] SEARCH_ENGINE_ID not set in .env") + sys.exit(1) + + params = {"key": API_KEY, "cx": CX, "q": QUERY, "num": NUM} + print(f"GET {GOOGLE_CSE_ENDPOINT}?q={QUERY}&num={NUM} (key/cx hidden)\n") + + try: + r = requests.get(GOOGLE_CSE_ENDPOINT, params=params, timeout=30) + except requests.RequestException as e: + print(f"[FAIL] Could not reach Google CSE: {e}") + sys.exit(1) + + print(f"Status: {r.status_code}") + if r.status_code != 200: + print(f"Body: {r.text}") + sys.exit(1) + + data = r.json() + info = data.get("searchInformation", {}) or {} + items = data.get("items", []) or [] + + print(f"Query: {QUERY}") + print(f"Total results: {info.get('totalResults')}") + print(f"Search time: {info.get('searchTime')}s") + print(f"Items returned: {len(items)}\n") + + for i, item in enumerate(items, 1): + print(f"{i}. {item.get('title')}") + print(f" {item.get('link')}") + snippet = (item.get("snippet") or "").replace("\n", " ") + print(f" {snippet[:120]}{'...' if len(snippet) > 120 else ''}\n") + + +if __name__ == "__main__": + main()