2

I'm trying to use the google cloud automl API to use it's classification service but it's returning the following error:

{ 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: {} } }

My code looks exactly like the documentation:


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}`
      );
    }
  }

I tried to look at their documentation but I didn't find any answer. The weird part is that when I use a model ID of a projet that is an entity extraction it work perfectly.

Could anybody help me? Thank you!

Ismail
  • 1,068
  • 1
  • 6
  • 11
Lucas Reis
  • 21
  • 1

1 Answers1

2

You will get this error if the model id is referencing the wrong model or a different entity. I got this when using the dataset id (which is of the same form as the model id) by mistake.

kynan
  • 13,235
  • 6
  • 79
  • 81