Vertex AI Nodejs ‘filePart’ 引发类型错误

  const base64File = await getFileAsBase64("src/testt.jpg");  console.log(base64File);  const filePart = {    inline_data: {      data: base64File,      mimeType: "image/jpeg",    },  };  const textPart = {    text: `   exampleeee    `,  };  const request = {    contents: [{ role: "user", parts: [textPart, filePart] }],  };  const resp = await generativeModel.generateContent(request); <----- 类型错误

这是我的文件,示例来自网站。我不知道为什么会导致

rgument of type '{ contents: { role: string; parts: ({ inline_data: { data: string; mimeType: string; }; } | { text: string; })[]; }[]; }' is not assignable to parameter of type 'string | GenerateContentRequest'.

我哪里做错了?


回答:

在 TypeScript 中,你可以强制使用 FileDataPart 类型,如下所示:

import { VertexAI, FileDataPart } from '@google-cloud/vertexai';      const filePart: FileDataPart = {        file_data: {          file_uri: fileUri,          mime_type: 'image/jpeg',        },      };

或者使用 InlineDataPart 类型,如下所示:

import { VertexAI, InlineDataPart } from '@google-cloud/vertexai';      const filePart: InlineDataPart = {        inline_data: {          data: base64File,          mime_type: 'image/jpeg',        },      };

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注