( modelId, deployedModelDisplayName, endpointId, project, location = 'us-central1' )
| 17 | 'use strict'; |
| 18 | |
| 19 | async function main( |
| 20 | modelId, |
| 21 | deployedModelDisplayName, |
| 22 | endpointId, |
| 23 | project, |
| 24 | location = 'us-central1' |
| 25 | ) { |
| 26 | // [START aiplatform_deploy_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 endpointId = 'YOUR_ENDPOINT_ID'; |
| 34 | // const deployedModelDisplayName = 'YOUR_DEPLOYED_MODEL_DISPLAY_NAME'; |
| 35 | // const project = 'YOUR_PROJECT_ID'; |
| 36 | // const location = 'YOUR_PROJECT_LOCATION'; |
| 37 | |
| 38 | const modelName = `projects/${project}/locations/${location}/models/${modelId}`; |
| 39 | const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`; |
| 40 | // Imports the Google Cloud Endpoint Service Client library |
| 41 | const {EndpointServiceClient} = require('@google-cloud/aiplatform'); |
| 42 | |
| 43 | // Specifies the location of the api endpoint: |
| 44 | const clientOptions = { |
| 45 | apiEndpoint: 'us-central1-aiplatform.googleapis.com', |
| 46 | }; |
| 47 | |
| 48 | // Instantiates a client |
| 49 | const endpointServiceClient = new EndpointServiceClient(clientOptions); |
| 50 | |
| 51 | async function deployModel() { |
| 52 | // Configure the parent resource |
| 53 | // key '0' assigns traffic for the newly deployed model |
| 54 | // Traffic percentage values must add up to 100 |
| 55 | // Leave dictionary empty if endpoint should not accept any traffic |
| 56 | const trafficSplit = {0: 100}; |
| 57 | const deployedModel = { |
| 58 | // format: 'projects/{project}/locations/{location}/models/{model}' |
| 59 | model: modelName, |
| 60 | displayName: deployedModelDisplayName, |
| 61 | automaticResources: {minReplicaCount: 1, maxReplicaCount: 1}, |
| 62 | }; |
| 63 | const request = { |
| 64 | endpoint, |
| 65 | deployedModel, |
| 66 | trafficSplit, |
| 67 | }; |
| 68 | |
| 69 | // Get and print out a list of all the endpoints for this resource |
| 70 | const [response] = await endpointServiceClient.deployModel(request); |
| 71 | console.log(`Long running operation : ${response.name}`); |
| 72 | |
| 73 | // Wait for operation to complete |
| 74 | await response.promise(); |
| 75 | const result = response.result; |
| 76 |
no test coverage detected