Skip to content

Commit

Permalink
Merge pull request #24 from i-dot-ai/feature/REDBOX-4-setup-mypy-for-…
Browse files Browse the repository at this point in the history
…type-hinting-testing

Feature/redbox 4 setup mypy for type hinting testing
  • Loading branch information
lmwilkigov committed Feb 19, 2024
2 parents e7aee2a + 8223341 commit d16e045
Show file tree
Hide file tree
Showing 28 changed files with 239 additions and 216 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ jobs:
- name: Format code
run: |
make format
- name: Type check
run: |
make checktypes
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ format:
poetry run ruff format .
# additionally we format, but not lint, the notebooks
poetry run ruff format **/*.ipynb

checktypes:
poetry run mypy redbox app tests --ignore-missing-imports
poetry run mypy legacy_app --follow-imports skip --ignore-missing-imports
Empty file added app/workers/embed/__init__.py
Empty file.
13 changes: 6 additions & 7 deletions app/workers/embed/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
from contextlib import asynccontextmanager
from datetime import datetime
from typing import List
from uuid import uuid4

import pydantic
Expand All @@ -22,23 +21,23 @@ class ModelInfo(pydantic.BaseModel):
class Embedding(pydantic.BaseModel):
object: str = "embedding"
index: int
embedding: List[float]
embedding: list[float]


class EmbeddingResponse(pydantic.BaseModel):
object: str = "list"
data: List[Embedding]
data: list[Embedding]
embedding_id: str
model: str
model_info: ModelInfo


class EmbeddingRequest(pydantic.BaseModel):
sentences: List[str]
sentences: list[str]


class ModelListResponse(pydantic.BaseModel):
models: List[ModelInfo]
models: list[ModelInfo]


class StatusResponse(pydantic.BaseModel):
Expand Down Expand Up @@ -174,12 +173,12 @@ def get_model(model: str):


@app.post("/models/{model}/embed", response_model=EmbeddingResponse, tags=["models"])
def embed_sentences(model: str, sentences: List[str]):
def embed_sentences(model: str, sentences: list[str]):
"""Embeds a list of sentences using a given model
Args:
model (str): The name of the model
sentences (List[str]): A list of sentences
sentences (list[str]): A list of sentences
Returns:
EmbeddingResponse: The embeddings of the sentences
Expand Down
Empty file added app/workers/ingest/__init__.py
Empty file.
26 changes: 16 additions & 10 deletions legacy_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import uuid
from datetime import datetime
from io import BytesIO
from typing import Dict, List, Optional, Union
from typing import Optional

import boto3
import cognitojwt
Expand Down Expand Up @@ -86,6 +86,9 @@ def populate_user_info(ENV: dict) -> dict:
st.sidebar.markdown("Running Locally")
return {"name": "dev", "email": "dev@example.com"}

# TODO: is this the right thing to do here?
return {}


def init_session_state() -> dict:
"""
Expand Down Expand Up @@ -257,7 +260,7 @@ def init_session_state() -> dict:


def get_link_html(
page: str, text: str, query_dict: dict = None, target: str = "_self"
page: str, text: str, query_dict: Optional[dict] = None, target: str = "_self"
) -> str:
"""Returns a link in HTML format
Expand All @@ -279,7 +282,7 @@ def get_link_html(
return f"<a href='/{page}{query}' target={target}><button style='background-color: white;border-radius: 8px;'>{text}</button></a>"


def get_file_link(file: File, page: int = None) -> str:
def get_file_link(file: File, page: Optional[int] = None) -> str:
"""Returns a link to a file
Args:
Expand All @@ -296,7 +299,7 @@ def get_file_link(file: File, page: int = None) -> str:
presentation_name = file.name
query_dict = {"file_uuid": file.uuid}
if page is not None:
query_dict["page_number"] = page[0]
query_dict["page_number"] = page

link_html = get_link_html(
page="Preview_Files",
Expand Down Expand Up @@ -360,7 +363,7 @@ def load_llm_handler(ENV, update=False) -> None:
)


def hash_list_of_files(list_of_files: List[File]) -> str:
def hash_list_of_files(list_of_files: list[File]) -> str:
"""Returns a hash of the list of files
Args:
Expand Down Expand Up @@ -425,7 +428,7 @@ def st_render(self, file: File) -> None:
file_bytes = stream["Body"].read()
render_method(file, file_bytes)

def _render_pdf(self, file: File, page_number: int = None) -> None:
def _render_pdf(self, file: File, page_number: Optional[int] = None) -> None:
stream = st.session_state.s3_client.get_object(
Bucket=st.session_state.BUCKET_NAME, Key=file.name
)
Expand Down Expand Up @@ -480,8 +483,8 @@ def _render_docx(self, file: File, file_bytes: bytes) -> None:

def replace_doc_ref(
output_for_render: str = "",
files: List[File] = [],
page_numbers: List = [],
files: Optional[list[File]] = None,
page_numbers: Optional[list] = None,
flexible=False,
) -> str:
"""Replaces references to files in the output text with links to the files
Expand All @@ -495,6 +498,9 @@ def replace_doc_ref(
Returns:
str: The modified text
"""
files = files or []
page_numbers = page_numbers or []

if len(page_numbers) != len(files):
page_numbers = [None for _ in files]

Expand Down Expand Up @@ -537,8 +543,8 @@ def eval_csv_to_squad_json(csv_path: str, json_path: str) -> None:


def submit_feedback(
feedback: Dict,
input: Union[str, List[str]],
feedback: dict,
input: str | list[str],
output: str,
creator_user_uuid: str,
chain: Optional[Chain] = None,
Expand Down
68 changes: 68 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ ruff = "^0.2.1"
pytest = "^8.0.1"
pre-commit = "^3.6.1"
pylint = "^3.0.3"

mypy = "^1.8.0"
types-python-dateutil = "^2.8.19.20240106"
types-markdown = "^3.5.0.20240129"


[build-system]
Expand Down
4 changes: 2 additions & 2 deletions redbox/export/docx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tempfile
from typing import List, Optional
from typing import Optional

import markdown
from dateutil import parser
Expand All @@ -20,7 +20,7 @@ def lookup_indentedness(raw: str, line_str_to_match: str):

def spotlight_complete_to_docx(
spotlight_complete: SpotlightComplete,
files: List[File],
files: list[File],
title: Optional[str] = None,
):
document = Document()
Expand Down
Loading

0 comments on commit d16e045

Please sign in to comment.