diff --git a/readalongs/web_api.py b/readalongs/web_api.py
index 2bb1033b..d70d0387 100644
--- a/readalongs/web_api.py
+++ b/readalongs/web_api.py
@@ -92,8 +92,8 @@ class InputFormat(Enum):
class AssembleRequest(BaseModel):
"""Base request for assemble"""
- input_text: str = Field(None, alias="input")
- mime_type: InputFormat = Field(None, alias="type")
+ input_text: Optional[str] = Field(None, alias="input")
+ mime_type: Optional[InputFormat] = Field(None, alias="type")
text_languages: List[str]
debug: bool = False
@@ -105,10 +105,10 @@ class AssembleResponse(BaseModel):
text_ids: str # The text ID input for the decoder in plain text
processed_ras: str # The processed RAS XML is returned as a string
input_request: Optional[AssembleRequest] = Field(None, alias="input")
- parsed: Optional[str]
- tokenized: Optional[str]
- g2ped: Optional[str]
- log: Optional[str]
+ parsed: Optional[str] = None
+ tokenized: Optional[str] = None
+ g2ped: Optional[str] = None
+ log: Optional[str] = None
class SupportedLanguage(BaseModel):
@@ -144,26 +144,28 @@ async def langs() -> List[SupportedLanguage]:
@v1.post("/assemble", response_model=AssembleResponse)
async def assemble(
request: AssembleRequest = Body(
- examples={
- "text": {
- "summary": "A basic example with plain text input",
- "value": {
- "input": "hej verden",
- "type": "text/plain",
- "text_languages": ["dan", "und"],
- "debug": False,
+ examples=[
+ {
+ "text": {
+ "summary": "A basic example with plain text input",
+ "value": {
+ "input": "hej verden",
+ "type": "text/plain",
+ "text_languages": ["dan", "und"],
+ "debug": False,
+ },
},
- },
- "xml": {
- "summary": "A basic example with xml input",
- "value": {
- "input": "hej verden
",
- "type": "application/readalong+xml",
- "text_languages": ["dan", "und"],
- "debug": False,
+ "xml": {
+ "summary": "A basic example with xml input",
+ "value": {
+ "input": "hej verden
",
+ "type": "application/readalong+xml",
+ "text_languages": ["dan", "und"],
+ "debug": False,
+ },
},
- },
- }
+ }
+ ]
)
):
"""Create an input RAS from the given text (as plain text or XML).
@@ -190,7 +192,7 @@ async def assemble(
if request.mime_type == InputFormat.RAS:
try:
parsed = etree.fromstring(
- bytes(request.input_text, encoding="utf-8"),
+ bytes(request.input_text or "", encoding="utf-8"),
parser=etree.XMLParser(resolve_entities=False),
)
except etree.ParseError as e:
@@ -271,7 +273,7 @@ def create_grammar(xml):
class WordAlignment(BaseModel):
"""Word alignment extracted from RAS"""
- word_id: str = Field(None, alias="id")
+ word_id: Optional[str] = Field(None, alias="id")
start: float
end: float
@@ -317,6 +319,7 @@ class ConvertRequest(BaseModel):
example=2.01,
gt=0.0,
title="The duration of the audio used to create the alignment, in seconds.",
+ default=None,
)
ras: str = Field(
diff --git a/requirements.dev.txt b/requirements.dev.txt
index 668a6356..aed0c7c5 100644
--- a/requirements.dev.txt
+++ b/requirements.dev.txt
@@ -3,7 +3,8 @@ black~=22.0
flake8>=4.0.1
gitlint-core==0.17.0
isort>=5.10.1
-mypy>=0.941
+mypy>=1.4.1
+mypy>=1.5.1; python_version >= "3.8"
pre-commit>=2.6.0
types-python-slugify>=5.0.3
types-pyyaml>=6.0.5
diff --git a/requirements.min.txt b/requirements.min.txt
index 9274774a..09ecdfa6 100644
--- a/requirements.min.txt
+++ b/requirements.min.txt
@@ -3,10 +3,12 @@ anyio<4.0.0
chevron==0.14.0
click>=8.0.4
coloredlogs==10.0
-fastapi==0.78.0
-g2p>=1.1.20230822, ==1.*
+fastapi>=0.78.0
+# Note: when we move g2p to >=2, we will need fastapi>=0.100.0 which requires httpx
+g2p>=1.1.20230822, <2.1
+httpx>=0.24.1
lxml==4.9.1
-networkx>=2.5,<=2.8.4
+networkx>=2.6
numpy>=1.16.4
pydub==0.23.1
pympi-ling>=1.69,<2.0
diff --git a/setup.cfg b/setup.cfg
index 8d4c021f..4c0e4885 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -9,6 +9,7 @@ ensure_newline_before_comments=True
[mypy]
ignore_missing_imports = True
+plugins = pydantic.mypy
[flake8]
ignore = E203, E266, E501, W503