gpt4 book ai didi

node.js - Node Google Cloud AutoML PredictionServiceClient 问题

转载 作者:行者123 更新时间:2023-12-04 10:14:44 35 4
gpt4 key购买 nike

我正在尝试使用 google cloud automl API 来使用它的分类服务,但它返回以下错误:

{ Error: 3 INVALID_ARGUMENT: Request contains an invalid argument.
at Object.callErrorFromStatus (/Users/lucasreis/Documents/GitHub/base-cleaning/node_modules/@grpc/grpc-js/src/call.ts:81:24)
at Object.onReceiveStatus (/Users/lucasreis/Documents/GitHub/base-cleaning/node_modules/@grpc/grpc-js/src/client.ts:324:36)
at Object.onReceiveStatus (/Users/lucasreis/Documents/GitHub/base-cleaning/node_modules/@grpc/grpc-js/src/client-interceptors.ts:439:34)
at Object.onReceiveStatus (/Users/lucasreis/Documents/GitHub/base-cleaning/node_modules/@grpc/grpc-js/src/client-interceptors.ts:402:48)
at Http2CallStream.outputStatus (/Users/lucasreis/Documents/GitHub/base-cleaning/node_modules/@grpc/grpc-js/src/call-stream.ts:228:22)
at Http2CallStream.maybeOutputStatus (/Users/lucasreis/Documents/GitHub/base-cleaning/node_modules/@grpc/grpc-js/src/call-stream.ts:278:14)
at Http2CallStream.endCall (/Users/lucasreis/Documents/GitHub/base-cleaning/node_modules/@grpc/grpc-js/src/call-stream.ts:262:12)
at Http2CallStream.handleTrailers (/Users/lucasreis/Documents/GitHub/base-cleaning/node_modules/@grpc/grpc-js/src/call-stream.ts:392:10)
at ClientHttp2Stream.emit (events.js:182:13)
at ClientHttp2Stream.EventEmitter.emit (domain.js:442:20)
at emit (internal/http2/core.js:237:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 3,
details: 'Request contains an invalid argument.',
metadata:
Metadata {
internalRepr: Map { 'grpc-server-stats-bin' => [Array] },
options: {} } }

我的代码看起来与文档完全一样:

function main(
projectId = 'YOUR_PROJECT_ID',
location = 'us-central1',
modelId = 'YOUR_MODEL_ID',
content = 'text to predict'
) {


// Imports the Google Cloud AutoML library
const {PredictionServiceClient} = require('@google-cloud/automl').v1;

// Instantiates a client
const client = new PredictionServiceClient();

async function predict() {
// Construct request
const request = {
name: client.modelPath(projectId, location, modelId),
payload: {
textSnippet: {
content: content,
mimeType: 'text/plain', // Types: 'test/plain', 'text/html'
},
},
};

const [response] = await client.predict(request);

for (const annotationPayload of response.payload) {
console.log(`Predicted class name: ${annotationPayload.displayName}`);
console.log(
`Predicted class score: ${annotationPayload.classification.score}`
);
}
}

我试图查看他们的文档,但没有找到任何答案。奇怪的是,当我使用作为实体提取的项目的模型 ID 时,它可以完美地工作。

有人可以帮我吗?谢谢!

最佳答案

如果模型 ID 引用了错误的模型或不同的实体,您将收到此错误。我在错误地使用数据集 id(与模型 id 的形式相同)时得到了这个。

关于node.js - Node Google Cloud AutoML PredictionServiceClient 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61125687/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com