Skip to content

Commit

Permalink
Add response type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarLiew committed Dec 19, 2024
1 parent 8892284 commit 8183734
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:

async def authorize_header(
request: Request, bearer: HTTPAuthorizationCredentials | None = Depends(bearer_auth)
):
) -> None:
# Do nothing if AUTH_KEY is not set
auth_token: str | None = request.app.state.config.auth_token
if auth_token is None:
Expand All @@ -76,7 +76,7 @@ async def authorize_header(


@app.exception_handler(Exception)
async def ingestion_error_handler(_, exc: Exception):
async def ingestion_error_handler(_, exc: Exception) -> None:
detail = {"message": str(exc)}
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=detail
Expand All @@ -103,12 +103,12 @@ def convert_func(data: ConvertData) -> ConversionResult:
return convert_func


@app.post("/parse/url")
@app.post("/parse/url", response_model=ParseResponse)
def parse_document_url(
payload: ParseUrlRequest,
convert: ConvertFunc = Depends(convert),
_=Depends(authorize_header),
):
) -> ParseResponse:
result = convert(payload.url)
output = _get_output(result.document, payload.output_format)

Expand All @@ -121,13 +121,13 @@ def parse_document_url(
)


@app.post("/parse/file")
@app.post("/parse/file", response_model=ParseResponse)
def parse_document_stream(
file: UploadFile,
convert: ConvertFunc = Depends(convert),
payload: ParseFileRequest = Depends(ParseFileRequest.from_form_data),
_=Depends(authorize_header),
):
) -> ParseResponse:
binary_data = file.file.read()
data = DocumentStream(
name=file.filename or "unset_name", stream=BytesIO(binary_data)
Expand Down

0 comments on commit 8183734

Please sign in to comment.