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', }, };