fix: punkt -> punkt_tab + pre-download nltk packages to prevent runtime not working (#489)

This commit is contained in:
2025-07-16 18:58:57 -06:00
committed by GitHub
parent 86ce68651f
commit 0e2ae5fca8
2 changed files with 7 additions and 5 deletions

View File

@@ -16,10 +16,14 @@ WORKDIR /app
COPY pyproject.toml uv.lock /app/ COPY pyproject.toml uv.lock /app/
RUN touch README.md && env uv sync --compile-bytecode --locked RUN touch README.md && env uv sync --compile-bytecode --locked
# pre-download nltk packages
RUN uv run python -c "import nltk; nltk.download('punkt_tab'); nltk.download('averaged_perceptron_tagger')"
# bootstrap # bootstrap
COPY alembic.ini runserver.sh /app/ COPY alembic.ini runserver.sh /app/
COPY images /app/images COPY images /app/images
COPY migrations /app/migrations COPY migrations /app/migrations
COPY reflector /app/reflector COPY reflector /app/reflector
WORKDIR /app WORKDIR /app
CMD ["./runserver.sh"] CMD ["./runserver.sh"]

View File

@@ -45,7 +45,7 @@ class LLM:
downloads only if needed. downloads only if needed.
""" """
if not cls._nltk_downloaded: if not cls._nltk_downloaded:
nltk.download("punkt") nltk.download("punkt_tab")
# For POS tagging # For POS tagging
nltk.download("averaged_perceptron_tagger") nltk.download("averaged_perceptron_tagger")
cls._nltk_downloaded = True cls._nltk_downloaded = True
@@ -222,7 +222,7 @@ class LLM:
title = modified_title[0].upper() + modified_title[1:] title = modified_title[0].upper() + modified_title[1:]
except Exception as e: except Exception as e:
reflector_logger.info( reflector_logger.info(
f"Failed to ensure casing on {title=} " f"with exception : {str(e)}" f"Failed to ensure casing on {title=} with exception : {str(e)}"
) )
return title return title
@@ -245,9 +245,7 @@ class LLM:
) )
title = re.sub(pattern, "", title, flags=re.IGNORECASE) title = re.sub(pattern, "", title, flags=re.IGNORECASE)
except Exception as e: except Exception as e:
reflector_logger.info( reflector_logger.info(f"Failed to trim {title=} with exception : {str(e)}")
f"Failed to trim {title=} " f"with exception : {str(e)}"
)
return title return title
async def _generate( async def _generate(