google-cloud/aiplatform 顶点 AI 预测服务客户端截断响应 NodeJS

Loe*_*bre 5 machine-learning node.js google-cloud-ai bart google-cloud-aiplatform

我正在尝试让 aiplatform 客户端在 NodeJS 项目上工作,它似乎有效,我的意思是凭据很好,并且我得到了“有效”响应。但是预测的内容被截断了(使用curl我得到了完整的列表),只有第一行出现在那里。我想知道我是否应该以不同的方式解析 IValues 或者什么。有人在 NodeJS 项目上成功集成了 AIPlatform 库吗?

这是脚本:

/**
 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
 */
import * as sdk from "@google-cloud/aiplatform";

const project = "generativeai-390315";
const loc = 'us-central1';

// Imports the Google Cloud Prediction service client
const { PredictionServiceClient } = sdk.v1;

// Import the helper module for converting arbitrary protobuf.Value objects.
const { helpers } = sdk;

const credentials = {
    client_email: "your-client-email",
    private_key: "your-private-key",
};

// Specifies the location of the api endpoint
const clientOptions = {
    credentials,
    apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};

const publisher = 'google';
const model = 'text-bison@001';


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

async function callPredict() {
    // Configure the parent resource
    const endpoint = `projects/${project}/locations/${loc}/publishers/${publisher}/models/${model}`;

    const prompt = {
        prompt:
            'what are the 10 largest cities in Europe?',
    };
    const instanceValue = helpers.toValue(prompt);
    const instances = [instanceValue] as protobuf.common.IValue[];

    const parameter = {
        temperature: 0.2,
        maxOutputTokens: 5,
        topP: 0.95,
        topK: 40,
    };
    const parameters = helpers.toValue(parameter);

    const request = {
        endpoint,
        instances,
        parameters,
    };

    // Predict request
    const response = await predictionServiceClient.predict(request);
    console.log('Get text prompt response');
    console.log("\n\n");

    // const predictResp: sdk.protos.google.cloud.aiplatform.v1.IPredictResponse = response[0];
    // const predicObj: sdk.protos.google.cloud.aiplatform.v1.PredictResponse = new sdk.protos.google.cloud.aiplatform.v1.PredictResponse(predictResp);
    // console.log(JSON.stringify(predicObj.predictions, null, 2));


    for (let p of  response[0]!.predictions!) {
      console.log(JSON.stringify(p, null, 2))
    }
    return response;
}

(async ()=>{
    const response = await callPredict();
})()
Run Code Online (Sandbox Code Playgroud)

Loe*_*bre 3

主要是因为 maxOutputTokens,显然,我是盲目的,我没有看到我将它们设置为 5 个令牌