def METHOD_NAME(slug: str, shipment, **kwargs) -> dict:
    template = models.DocumentTemplate.objects.get(slug=slug)
    carrier = kwargs.get("carrier") or getattr(shipment, "selected_rate_carrier", None)
    params = dict(
        shipments_context=[
            dict(
                shipment=ShipmentSerializer(shipment).data,
                line_items=get_shipment_item_contexts(shipment),
                carrier=get_carrier_context(carrier.settings),
                orders=OrderSerializer(
                    get_shipment_order_contexts(shipment),
                    many=True,
                ).data,
            )
        ]
    )
    document = Documents.generate(template, params).getvalue()
    return dict(
        doc_format="PDF",
        doc_name=f"{template.name}.pdf",
        doc_type=(template.metadata or {}).get("doc_type") or "commercial_invoice",
        doc_file=base64.b64encode(document).decode("utf-8"),
    )