How to send a request to a VertexAI model from NodeJS

26 views Asked by At

I have a custom VertexAI model with some endpoints I can access. I'm trying to send requests to these endpoints from a NodeJS (React if it matters) project. Here's the code I have so far:

    const client = new PredictionServiceClient({
        apiEndpoint: 'us-central1-aiplatform.googleapis.com',
    });

    const endpoint = `projects/${PROJECT_ID}/locations/${COMPUTE_REGION}/endpoints/${ENDPOINT_ID_SWOT}`;
    const instances = [{ content: DEFAULT_CONTENT }];
    const parametersObj = {};
    const parameters = JSON.stringify(parametersObj);
    const request = {
        endpoint,
        instances: instances,
        parameters,
    };

    const response = client.predict(request);

However I'm getting the following problem in the last line:

Argument of type '{ endpoint: string; instances: { content: string; }[]; parameters: string; }' is not assignable to parameter of type 'IPredictRequest'.
  Types of property 'instances' are incompatible.
    Type '{ content: string; }[]' is not assignable to type 'IValue[]'.
      Type '{ content: string; }' has no properties in common with type 'IValue'.

DuetAI has been giving me the same suggestion no matter how many times I point out that it doesn't work, which is to convert instance to this:

const instances = [instance].map(instance => ({
      structValue: {
        fields: instance,
      },
    }));

Like I said, this doesn't work. Here's the error:

Argument of type '{ endpoint: string; instances: { structValue: { fields: { content: string; }; }; }[]; parameters: string; }' is not assignable to parameter of type 'IPredictRequest'.
  Types of property 'instances' are incompatible.
    Type '{ structValue: { fields: { content: string; }; }; }[]' is not assignable to type 'IValue[]'.
      Type '{ structValue: { fields: { content: string; }; }; }' is not assignable to type 'IValue'.
        The types of 'structValue.fields' are incompatible between these types.
          Type '{ content: string; }' is not assignable to type '{ [k: string]: IValue; }'.
            Property 'content' is incompatible with index signature.
              Type 'string' has no properties in common with type 'IValue'.

I have also tried to write instances as:

    const instances = [
        {
            stringValue: DEFAULT_CONTENT,
        },
    ];

I'm very confused on what to do here. How can I send a request to the VertexAI endpoint I have?

0

There are 0 answers