( modelId, gcsDestinationOutputUriPrefix, exportFormat, project, location = 'us-central1' )
| 17 | 'use strict'; |
| 18 | |
| 19 | async function main( |
| 20 | modelId, |
| 21 | gcsDestinationOutputUriPrefix, |
| 22 | exportFormat, |
| 23 | project, |
| 24 | location = 'us-central1' |
| 25 | ) { |
| 26 | // [START aiplatform_export_model_sample] |
| 27 | /** |
| 28 | * TODO(developer): Uncomment these variables before running the sample.\ |
| 29 | (Not necessary if passing values as arguments) |
| 30 | */ |
| 31 | |
| 32 | // const modelId = 'YOUR_MODEL_ID'; |
| 33 | // const gcsDestinationOutputUriPrefix ='YOUR_GCS_DEST_OUTPUT_URI_PREFIX'; |
| 34 | // eg. "gs://<your-gcs-bucket>/destination_path" |
| 35 | // const exportFormat = 'YOUR_EXPORT_FORMAT'; |
| 36 | // const project = 'YOUR_PROJECT_ID'; |
| 37 | // const location = 'YOUR_PROJECT_LOCATION'; |
| 38 | |
| 39 | // Imports the Google Cloud Model Service Client library |
| 40 | const {ModelServiceClient} = require('@google-cloud/aiplatform'); |
| 41 | |
| 42 | // Specifies the location of the api endpoint |
| 43 | const clientOptions = { |
| 44 | apiEndpoint: 'us-central1-aiplatform.googleapis.com', |
| 45 | }; |
| 46 | |
| 47 | // Instantiates a client |
| 48 | const modelServiceClient = new ModelServiceClient(clientOptions); |
| 49 | |
| 50 | async function exportModel() { |
| 51 | // Configure the name resources |
| 52 | const name = `projects/${project}/locations/${location}/models/${modelId}`; |
| 53 | // Configure the outputConfig resources |
| 54 | const outputConfig = { |
| 55 | exportFormatId: exportFormat, |
| 56 | gcsDestination: { |
| 57 | outputUriPrefix: gcsDestinationOutputUriPrefix, |
| 58 | }, |
| 59 | }; |
| 60 | const request = { |
| 61 | name, |
| 62 | outputConfig, |
| 63 | }; |
| 64 | |
| 65 | // Export Model request |
| 66 | const [response] = await modelServiceClient.exportModel(request); |
| 67 | console.log(`Long running operation : ${response.name}`); |
| 68 | |
| 69 | // Wait for operation to complete |
| 70 | await response.promise(); |
| 71 | const result = response.result; |
| 72 | |
| 73 | console.log(`Export model response : ${JSON.stringify(result)}`); |
| 74 | } |
| 75 | exportModel(); |
| 76 | // [END aiplatform_export_model_sample] |
no test coverage detected