我正在使用Node.js调用Vertex AI端点中的自定义模型(用于检索的Two Towers),代码如下:
const axios = require('axios');
const { GoogleAuth } = require('google-auth-library');
const project = '1234567';
const endpointId = '8888888888';
const location = 'us-central1';
// Imports the Google Cloud Prediction Service Client library
const {PredictionServiceClient} = require('@google-cloud/aiplatform');
// Specifies the location of the api endpoint
const clientOptions = {
apiEndpoint: 'us-central1-aiplatform.googleapis.com',
project: project,
credentials: { key.json details here }
};
// Instantiates a client
const predictionServiceClient = new PredictionServiceClient(clientOptions);
async function predictCustomTrainedModel() {
// Configure the parent resource
const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`;
const instance = [{"input_1": ["disenador grafico experiencia montaje planchas".split()]}];
const instances = [instance]
const request = {
endpoint,
instances
};
const response = await predictionServiceClient.predict(request);
console.log('Predict custom trained model response');
console.log(`\tDeployed model id : ${response.deployedModelId}`);
const predictions = response.predictions;
console.log('\tPredictions :');
for (const prediction of predictions) {
console.log(`\t\tPrediction : ${JSON.stringify(prediction)}`);
}
}
predictCustomTrainedModel();
这将在端点监视中返回错误和400代码:
(node:84871) UnhandledPromiseRejectionWarning: Error: 3 INVALID_ARGUMENT: Failed to parse input instances.
at callErrorFromStatus (/home/theone/Downloads/other_models/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
at Object.onReceiveStatus (/home/theone/Downloads/other_models/node_modules/@grpc/grpc-js/build/src/client.js:192:76)
at Object.onReceiveStatus (/home/theone/Downloads/other_models/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
at Object.onReceiveStatus (/home/theone/Downloads/other_models/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
at /home/theone/Downloads/other_models/node_modules/@grpc/grpc-js/build/src/resolving-call.js:94:78
at processTicksAndRejections (internal/process/task_queues.js:79:11)
for call at
at ServiceClientImpl.makeUnaryRequest (/home/theone/Downloads/other_models/node_modules/@grpc/grpc-js/build/src/client.js:160:34)
at ServiceClientImpl.<anonymous> (/home/theone/Downloads/other_models/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
at /home/theone/Downloads/other_models/node_modules/@google-cloud/aiplatform/build/src/v1/prediction_service_client.js:217:29
at /home/theone/Downloads/other_models/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
at OngoingCallPromise.call (/home/theone/Downloads/other_models/node_modules/google-gax/build/src/call.js:67:27)
at NormalApiCaller.call (/home/theone/Downloads/other_models/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
at /home/theone/Downloads/other_models/node_modules/google-gax/build/src/createApiCall.js:84:30
这很有趣,因为Python中相同的有效负载工作得很好:
import os
from google.cloud import aiplatform
from google.protobuf import json_format
from google.protobuf.struct_pb2 import Value
from typing import Dict, List, Union
from google.oauth2 import service_account
credentials = service_account.Credentials. from_service_account_file('/home/user/key.json')
aip_endpoint_name = (
f"projects/1245678/locations/us-central1/endpoints/8888888888888"
)
endpoint = aiplatform.Endpoint(aip_endpoint_name,credentials=credentials)
instances_list = [{"input_1": ["disenador grafico experiencia montaje planchas".split()]}]
results = endpoint.predict(instances=instances_list)
有什么办法解决这个问题吗?
1条答案
按热度按时间c3frrgcw1#
我用
Helpers
.toValue
解决了这个问题: