From 762714c4c04527288f8fcc335f4e0334ffa12d6e Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Tue, 16 Sep 2025 14:05:44 -0400 Subject: [PATCH 1/4] feat: include the partial RAS XML with the 422 error when g2p fails in assemble --- readalongs/web_api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readalongs/web_api.py b/readalongs/web_api.py index 08e4af3f..085a0768 100644 --- a/readalongs/web_api.py +++ b/readalongs/web_api.py @@ -281,7 +281,9 @@ async def assemble( raise HTTPException( status_code=422, detail="g2p could not be performed, please check your text or your language code. " - + logs, + + logs + + "PARTIAL RAS: " + + xml_to_string(g2ped), ) # create grammar dict_data, text_input = create_grammar(g2ped) From dad9e89c14fca091f44b75465a00122b7ed1d2d3 Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Fri, 5 Dec 2025 15:07:08 -0500 Subject: [PATCH 2/4] fix: make the g2p error words easier to see with spacing --- readalongs/web_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readalongs/web_api.py b/readalongs/web_api.py index 085a0768..8d8831f6 100644 --- a/readalongs/web_api.py +++ b/readalongs/web_api.py @@ -272,9 +272,9 @@ async def assemble( if not valid: if non_convertible_words: logs = ( - "These words could not be converted from text to phonemes by g2p: '" - + "', '".join(non_convertible_words) - + "'." + "These words could not be converted from text to phonemes by g2p: ' " + + " ', ' ".join(non_convertible_words) + + " '." ) else: logs = "Logs: " + captured_logs.getvalue() From 024324d730eb8f4a3f5a5e33493b0a3c4d7d7253 Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Fri, 5 Dec 2025 15:08:59 -0500 Subject: [PATCH 3/4] feat: with g2p 422, send partially processed RAS file --- readalongs/web_api.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/readalongs/web_api.py b/readalongs/web_api.py index 8d8831f6..c4ac5280 100644 --- a/readalongs/web_api.py +++ b/readalongs/web_api.py @@ -36,7 +36,7 @@ from fastapi import Body, FastAPI, HTTPException from fastapi.middleware.cors import CORSMiddleware -from fastapi.responses import FileResponse +from fastapi.responses import FileResponse, JSONResponse from lxml import etree from pydantic import BaseModel, Field from starlette.background import BackgroundTask @@ -278,12 +278,14 @@ async def assemble( ) else: logs = "Logs: " + captured_logs.getvalue() - raise HTTPException( + return JSONResponse( status_code=422, - detail="g2p could not be performed, please check your text or your language code. " - + logs - + "PARTIAL RAS: " - + xml_to_string(g2ped), + content={ + "detail": "g2p could not be performed, please check your text or your language code. " + + logs, + "g2p_error_words": non_convertible_words, + "partial_ras": xml_to_string(g2ped), + }, ) # create grammar dict_data, text_input = create_grammar(g2ped) From 38b0ff463cf842f1d9580bf5c79f9d1af4274259 Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Fri, 5 Dec 2025 15:49:59 -0500 Subject: [PATCH 4/4] test: add assertions about g2p errors in assemble call --- tests/test_web_api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_web_api.py b/tests/test_web_api.py index 6215209e..c8ba4c20 100755 --- a/tests/test_web_api.py +++ b/tests/test_web_api.py @@ -219,10 +219,14 @@ def test_empty_g2p(self): with redirect_stderr(StringIO()): response = self.API_CLIENT.post("/api/v1/assemble", json=request) self.assertEqual(response.status_code, 422) - content_log = response.json()["detail"] + content = response.json() + content_log = content["detail"] for message_part in ["These words could not", "24", "23"]: self.assertIn(message_part, content_log) + self.assertEqual(content["g2p_error_words"], ["24", "23", "99", "1234"]) + self.assertIn("partial_ras", content) + def test_langs(self): # Test the langs endpoint with redirect_stderr(StringIO()):