Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ jobs:
source .venv/bin/activate
sudo apt-get install --yes poppler-utils
make test
make check-coverage
# NOTE(robinson) - Add check-coverage back in once we add real tests
# make check-coverage
make check-notebooks

changelog:
Expand Down
74 changes: 0 additions & 74 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

14 changes: 1 addition & 13 deletions pipeline-notebooks/pipeline-email.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions prepline_emails/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
from slowapi.errors import RateLimitExceeded
from slowapi.util import get_remote_address

from .hello_world import router as hello_world_router
from .email import router as email_router


limiter = Limiter(key_func=get_remote_address)
app = FastAPI()
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

app.include_router(hello_world_router)
app.include_router(email_router)


@app.get("/healthcheck", status_code=status.HTTP_200_OK)
Expand Down
38 changes: 13 additions & 25 deletions prepline_emails/api/hello_world.py → prepline_emails/api/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@


# pipeline-api
message = "hello world"


def pipeline_api(
file,
file_content_type=None,
m_some_parameters=[],
):
return f"{message}: {' '.join(m_some_parameters)}"
def pipeline_api(text):
pass


import json
Expand Down Expand Up @@ -99,17 +92,16 @@ async def stream_response(self, send: Send) -> None:
await send({"type": "http.response.body", "body": b"", "more_body": False})


@router.post("/emails/v0.0.1/hello-world")
@router.post("/emails/v0.0.1/email")
@limiter.limit(RATE_LIMIT)
async def pipeline_1(
request: Request,
files: Union[List[UploadFile], None] = File(default=None),
some_parameters: List[str] = Form(default=[]),
text_files: Union[List[UploadFile], None] = File(default=None),
):
content_type = request.headers.get("Accept")

if isinstance(files, list) and len(files):
if len(files) > 1:
if isinstance(text_files, list) and len(text_files):
if len(text_files) > 1:
if content_type and content_type not in ["*/*", "multipart/mixed"]:
return PlainTextResponse(
content=(
Expand All @@ -120,14 +112,12 @@ async def pipeline_1(
)

def response_generator():
for file in files:
for file in text_files:

_file = file.file
text = file.file.read().decode("utf-8")

response = pipeline_api(
_file,
m_some_parameters=some_parameters,
file_content_type=file.content_type,
text,
)
if type(response) not in [str, bytes]:
response = json.dumps(response)
Expand All @@ -138,20 +128,18 @@ def response_generator():
)
else:

file = files[0]
_file = file.file
text_file = text_files[0]
text = text_file.file.read().decode("utf-8")

response = pipeline_api(
_file,
m_some_parameters=some_parameters,
file_content_type=file.content_type,
text,
)

return response

else:
return PlainTextResponse(
content='Request parameter "files" is required.\n',
content='Request parameter "text_files" is required.\n',
status_code=status.HTTP_400_BAD_REQUEST,
)

Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ unstructured>=0.2.4
unstructured-api-tools>=0.4.4

ratelimit
requests
37 changes: 30 additions & 7 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile requirements/base.in
#
Expand All @@ -19,7 +19,12 @@ beautifulsoup4==4.11.1
bleach==5.0.1
# via nbconvert
certifi==2022.12.7
# via httpx
# via
# httpx
# requests
# unstructured
charset-normalizer==2.1.1
# via requests
click==8.1.3
# via
# nltk
Expand Down Expand Up @@ -48,7 +53,12 @@ httpx==0.15.5
idna==3.4
# via
# anyio
# requests
# rfc3986
importlib-metadata==5.2.0
# via nbconvert
importlib-resources==5.10.1
# via jsonschema
jinja2==3.1.2
# via
# nbconvert
Expand Down Expand Up @@ -110,6 +120,8 @@ pandas==1.5.2
# via argilla
pandocfilters==1.5.0
# via nbconvert
pkgutil-resolve-name==1.3.10
# via jsonschema
pydantic==1.10.2
# via
# argilla
Expand All @@ -135,9 +147,11 @@ pyyaml==6.0
pyzmq==24.0.1
# via jupyter-client
ratelimit==2.2.1
# via -r base.in
# via -r requirements/base.in
regex==2022.10.31
# via nltk
requests==2.28.1
# via -r requirements/base.in
rfc3986[idna2008]==1.5.0
# via httpx
six==1.16.0
Expand All @@ -159,6 +173,8 @@ starlette==0.20.4
# via fastapi
tinycss2==1.1.1
# via nbconvert
tomli==2.0.1
# via mypy
tornado==6.2
# via jupyter-client
tqdm==4.64.1
Expand All @@ -182,10 +198,13 @@ typing-extensions==4.3.0
# via
# mypy
# pydantic
unstructured==0.3.2
# via -r base.in
# starlette
unstructured==0.3.4
# via -r requirements/base.in
unstructured-api-tools==0.4.6
# via -r base.in
# via -r requirements/base.in
urllib3==1.26.13
# via requests
uvicorn[standard]==0.18.3
# via unstructured-api-tools
uvloop==0.17.0
Expand All @@ -202,3 +221,7 @@ wrapt==1.13.3
# via
# argilla
# deprecated
zipp==3.11.0
# via
# importlib-metadata
# importlib-resources
Loading