Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

ux: Minimify HTML on render

Clémence Lesné9eac8e0efd3a
diff --git a/main.py b/main.py
index 7b462d4..671fb8b 100644
--- a/main.py
+++ b/main.py
@@ -46,6 +46,7 @@ from helpers.call_events import (
)
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from models.readiness import ReadinessModel, ReadinessCheckModel, ReadinessStatus
+from htmlmin.minify import html_minify
# Jinja configuration
@@ -53,10 +54,11 @@ _jinja = Environment(
autoescape=True,
enable_async=True,
loader=FileSystemLoader("public_website"),
+ optimized=False, # Outsource optimization to html_minify
)
# Jinja custom functions
_jinja.filters["quote_plus"] = lambda x: quote_plus(str(x)) if x else ""
-_jinja.filters["markdown"] = lambda x: mistune.create_markdown(escape=False, plugins=["abbr", "speedup", "url"])(x) if x else "" # type: ignore
+_jinja.filters["markdown"] = lambda x: mistune.create_markdown(plugins=["abbr", "speedup", "url"])(x) if x else "" # type: ignore
# Azure Communication Services
_source_caller = PhoneNumberIdentifier(CONFIG.communication_service.phone_number)
@@ -165,6 +167,7 @@ async def report_get(
phone_number=phone_number,
version=CONFIG.version,
)
+ render = html_minify(render) # Minify HTML
return HTMLResponse(content=render)
@@ -188,6 +191,7 @@ async def report_single_get(call_id: UUID) -> HTMLResponse:
next_actions=[action for action in NextActionEnum],
version=CONFIG.version,
)
+ render = html_minify(render) # Minify HTML
return HTMLResponse(content=render)
diff --git a/requirements.txt b/requirements.txt
index dfbfb30..80256a7 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,6 +9,7 @@ azure-eventgrid==4.19.0
azure-identity==1.16.0 # Required for all Azure SDKs
azure-monitor-opentelemetry==1.4.1
azure-search-documents==11.6.0b3
+django-htmlmin==0.11.0
fastapi==0.111.0
gunicorn==22.0.0
jinja2==3.1.4