Hello!
In the version 2.1 the following way should work to export DEM in slope mode:
chunk = Metashape.app.document.chunk
task = Metashape.Tasks.ExportRaster()
task.path = "D:/slope.jpg"
task.source_data = Metashape.ElevationData
task.raster_transform = Metashape.RasterTransformPalette
task["elevation_mode"] = 1
task.apply(chunk)