尝试在 Firebase 函数中使用带有视频的 Gemini-1.5-pro-preview-0409 api 时出现 400 错误请求错误

问题描述 投票:0回答:1

我正在尝试使用 Vertex AI API 将gemini-1.5-pro-preview-0409 与视频结合使用。

我正在使用 Firebase Cloud Functions 中实现的 nodejs 函数,我通过我的 web 应用程序调用此函数并尝试传递视频的 GCP 存储 uri。我从 Vertex AI studio 获取了代码示例。

当我在 AI Studio 中使用视频和提示时,它似乎工作正常。当我从 web 应用程序调用该函数时,我可以在云函数日志中看到我收到了 400 bad request 错误。

你能告诉我发生了什么事吗?

代码如下:

import {VertexAI} from '@google-cloud/vertexai';
const vertex_ai = new VertexAI({project: projectId, location: 'us-central1'});
const model = 'gemini-1.5-pro-preview-0409';

// Instantiate the models
const generativeModel = vertex_ai.preview.getGenerativeModel({
    model: model,
    generationConfig: {
        'maxOutputTokens': 8192,
        'temperature': 1,
        'topP': 0.95,
    },
    safetySettings: [
        {
            'category': 'HARM_CATEGORY_HATE_SPEECH',
            'threshold': 'BLOCK_MEDIUM_AND_ABOVE'
        },
        {
            'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
            'threshold': 'BLOCK_MEDIUM_AND_ABOVE'
        },
        {
            'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
            'threshold': 'BLOCK_MEDIUM_AND_ABOVE'
        },
        {
            'category': 'HARM_CATEGORY_HARASSMENT',
            'threshold': 'BLOCK_MEDIUM_AND_ABOVE'
        }
    ],
});

const text1 = {text: 'The video provided is a procedure with steps. Summarize the procedure.'};

export const outputSimFromVertexAI = onCall({timeoutSeconds: 900, memory: "1GiB"}, async (request) => {
    console.log('data is ')
    console.log(request.data)

    const videoPath = request.data.videoPath;

    console.log('video path is ', videoPath);
    const video1 = {
        fileData: {
            mimeType: 'video/mp4',
            fileUri: videoPath
        }
    };

    const req = {
        contents: [
            {role: 'user', parts: [video1, text1]}
        ]
    }

    console.log('video is ', video1)
    console.log('text1 is ', text1)

    const result = await generativeModel.generateContent(req);
    const aiResponse = JSON.stringify(await result.response);

    console.log('ai response is')
    console.log(aiResponse)

    return 'response generated successfully';
})

我得到的完整错误是:

Unhandled error ClientError: [VertexAI.ClientError]: got status: 400 Bad Request. {"error":{"code":400,"message":"Request contains an invalid argument.","status":"INVALID_ARGUMENT"}}
    at throwErrorIfNotOK (/workspace/node_modules/@google-cloud/vertexai/build/src/functions/post_fetch_processing.js:32:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async generateContent (/workspace/node_modules/@google-cloud/vertexai/build/src/functions/generate_content.js:51:5)
    at async file:///workspace/index.js:2142:20
    at async /workspace/node_modules/firebase-functions/lib/common/providers/https.js:467:26 {
  stackTrace: undefined
}
node.js google-cloud-functions google-cloud-vertex-ai google-gemini
1个回答
0
投票

我无法发表评论,但如果它更适合放在评论中,请随意将其移至评论中。

当链接到存储在云存储中的 PDF 文件时,我看到了相同的响应,但只是有时。链接到我的数据集中的大文件时会发生错误,但链接到一些较小的文件时不会发生错误。

如果我使用文件选择选项包含来自 Google 云存储桶的文件,我可以使用

gemini-1.5-pro-preview-0409
在 Vertex AI Studio 中重新创建 400 错误。令人惊讶的是,如果我将文件的副本上传到提示中,则不会发生错误,并且我可以成功生成响应。

我认为谷歌云存储中包含的文件存在一些未说明的限制。可能值得尝试使用较小的视频文件执行相同的任务,看看是否存在大小限制。

© www.soinside.com 2019 - 2024. All rights reserved.