Hello thans,
I think should be like you've described:
chunk.buildDenseCloud()
chunk.dense_cloud.classifyGroundPoints()
chunk.buildDem(source=PhotoScan.DenseCloudData, classes=[2])
chunk.exportDem()
But please note that only one digital elevation model can be stored in the chunk at the same time, so if you wish to keep both DSM and DTM you need to duplicate the chunk after generating the dense cloud.
Also you might need to use non-default parameters for dense cloud generation and classification and fro building DEM and export.