@@ -1752,6 +1752,84 @@ def get_diagnostics(self):
17521752 diagnostics = self .details .get ("trainDiagnostics" , {})
17531753 return [DSSMLDiagnostic (d ) for d in diagnostics .get ("diagnostics" , [])]
17541754
1755+ def export_documentation (self , folder_id = None , path = None ):
1756+ """
1757+ Start the export of the model documentation from a template docx file in a managed folder,
1758+ or from the default template if no folder id and path are specified.
1759+
1760+ :param folder_id: (optional) the id of the managed folder
1761+ :param path: (optional) the path to the file from the root of the folder
1762+ :return: A :class:`~dataikuapi.dss.future.DSSFuture` representing the model document generation process
1763+ """
1764+ if bool (folder_id ) != bool (path ):
1765+ raise ValueError ("Both folder id and path arguments are required to use a template from folder. Use without argument to export using the default template" )
1766+
1767+ export_mode_url = "default-template" if folder_id is None and path is None else "template-in-folder"
1768+
1769+ if self .mltask is not None :
1770+ f = self .mltask .client ._perform_json (
1771+ "POST" , "/projects/%s/models/lab/%s/%s/models/%s/export-documentation-from-%s" %
1772+ (self .mltask .project_key , self .mltask .analysis_id , self .mltask .mltask_id , self .mltask_model_id , export_mode_url ),
1773+ params = {"folderId" : folder_id , "path" : path })
1774+ return DSSFuture (self .mltask .client , f ["jobId" ])
1775+ else :
1776+ f = self .saved_model .client ._perform_json (
1777+ "POST" , "/projects/%s/savedmodels/%s/versions/%s/export-documentation-from-%s" %
1778+ (self .saved_model .project_key , self .saved_model .sm_id , self .saved_model_version , export_mode_url ),
1779+ params = {"folderId" : folder_id , "path" : path })
1780+ return DSSFuture (self .saved_model .client , job_id = f ["jobId" ])
1781+
1782+ def export_documentation_from_custom_template (self , fp ):
1783+ """
1784+ Start the export of the model documentation from a docx template (as a file object).
1785+
1786+ :param object fp: A file-like object pointing to a template docx file
1787+ :return: A :class:`~dataikuapi.dss.future.DSSFuture` representing the model document generation process
1788+ """
1789+ files = {'file' : fp }
1790+ if self .mltask is not None :
1791+ f = self .mltask .client ._perform_json (
1792+ "POST" , "/projects/%s/models/lab/%s/%s/models/%s/model-document/export-documentation-from-custom-template" %
1793+ (self .mltask .project_key , self .mltask .analysis_id , self .mltask .mltask_id , self .mltask_model_id ),
1794+ files = files )
1795+ return DSSFuture (self .mltask .client , f ["jobId" ])
1796+ else :
1797+ f = self .saved_model .client ._perform_json (
1798+ "POST" , "/projects/%s/savedmodels/%s/versions/%s/export-documentation-from-custom-template" %
1799+ (self .saved_model .project_key , self .saved_model .sm_id , self .saved_model_version ),
1800+ files = files )
1801+ return DSSFuture (self .saved_model .client , job_id = f ["jobId" ])
1802+
1803+ def download_documentation_stream (self , export_id ):
1804+ """
1805+ Download a exported model documentation, as a binary stream.
1806+
1807+ Warning: this stream will monopolize the DSSClient until closed.
1808+
1809+ :param exportId: the template id of the generated model documentation returned as the result of the future
1810+ :return: A :class:`~dataikuapi.dss.future.DSSFuture` representing the model document generation process
1811+ """
1812+ if self .mltask is not None :
1813+ return self .mltask .client ._perform_raw (
1814+ "GET" , "/projects/%s/models/lab/download-documentation/%s" % (self .mltask .project_key , export_id ))
1815+ else :
1816+ return self .saved_model .client ._perform_raw (
1817+ "GET" , "/projects/%s/savedmodels/download-documentation/%s" % (self .saved_model .project_key , export_id ))
1818+
1819+ def download_documentation_to_file (self , export_id , path ):
1820+ """
1821+ Download an exported model documentation into the given output file.
1822+
1823+ :param export_id: the template id of the generated model documentation returned as the result of the future
1824+ :param path: the path where to download the model documentation
1825+ :return: None
1826+ """
1827+ stream = self .download_documentation_stream (export_id )
1828+ with open (path , 'wb' ) as f :
1829+ for chunk in stream .iter_content (chunk_size = 10000 ):
1830+ if chunk :
1831+ f .write (chunk )
1832+ f .flush ()
17551833
17561834class DSSMLDiagnostic (object ):
17571835 """
@@ -2462,6 +2540,7 @@ def get_scoring_pmml_stream(self):
24622540 "GET" , "/projects/%s/savedmodels/%s/versions/%s/scoring-pmml" %
24632541 (self .saved_model .project_key , self .saved_model .sm_id , self .saved_model_version ))
24642542
2543+
24652544 ## Post-train computations
24662545
24672546 def compute_subpopulation_analyses (self , split_by , wait = True , sample_size = 1000 , random_state = 1337 , n_jobs = 1 , debug_mode = False ):
0 commit comments