Luis Chaves commited on
Commit
174138d
·
1 Parent(s): 4c91d01

debugging cuda issues and adding basic tests for api

Browse files
Files changed (3) hide show
  1. Dockerfile +6 -5
  2. answers.md +13 -0
  3. tests/test_api.py +43 -0
Dockerfile CHANGED
@@ -1,9 +1,10 @@
1
- FROM python:3.12-slim
2
 
3
- # Install CUDA dependencies
4
- RUN apt-get update && apt-get install -y \
5
- cuda-cudart-12-1 \
6
- cuda-libraries-12-1 \
 
7
  && rm -rf /var/lib/apt/lists/*
8
 
9
  WORKDIR /code
 
1
+ FROM nvidia/cuda:12.1.1-base-ubuntu22.04
2
 
3
+ # Install Python 3.12
4
+ RUN apt-get update && apt-get install -y --no-install-recommends \
5
+ python3.12 \
6
+ python3-pip \
7
+ && ln -s /usr/bin/python3.12 /usr/bin/python \
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
  WORKDIR /code
answers.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1. **Technical Choices:** What influenced your decision on the specific tools and models used?
2
+
3
+
4
+ 2. **Entity Contextualization:** How did you approach the problem of providing context for each identified entity?
5
+
6
+
7
+ 3. **Error Handling:** Can you describe how your API handles potential errors?
8
+
9
+
10
+ 4. **Challenges and Learnings:** What were the top challenges faced, and what did you learn from them?
11
+
12
+
13
+ 5. **Improvement Propositions:** Given more time, what improvements or additional features would you consider adding?
tests/test_api.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ from fastapi.testclient import TestClient
3
+ from everycure.app import app
4
+ import os
5
+ import tempfile
6
+
7
+ client = TestClient(app)
8
+
9
+ def create_test_pdf():
10
+ # Create a temporary PDF file for testing
11
+ with tempfile.NamedTemporaryFile(suffix=".pdf", delete=False) as tmp:
12
+ tmp.write(b"%PDF-1.5\nTest PDF content")
13
+ return tmp.name
14
+
15
+ @pytest.fixture
16
+ def test_pdf():
17
+ pdf_path = create_test_pdf()
18
+ yield pdf_path
19
+ # Cleanup after test
20
+ os.unlink(pdf_path)
21
+
22
+
23
+ def test_extract_entities_invalid_file():
24
+ # Test with non-PDF file
25
+ with tempfile.NamedTemporaryFile(suffix=".txt") as tmp:
26
+ tmp.write(b"Not a PDF file")
27
+ tmp.seek(0)
28
+ response = client.post(
29
+ "/extract",
30
+ files={"file": ("test.txt", tmp, "text/plain")}
31
+ )
32
+
33
+ assert response.status_code == 400
34
+ assert "Invalid file type" in response.json()["detail"]
35
+
36
+ def test_extract_entities_empty_file(test_pdf):
37
+ with open(test_pdf, "rb") as f:
38
+ response = client.post(
39
+ "/extract",
40
+ files={} # No file provided
41
+ )
42
+
43
+ assert response.status_code == 422 # FastAPI's validation error