|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +// [START generativeaionvertexai_gemini_video_with_audio] |
| 16 | +const {VertexAI} = require('@google-cloud/vertexai'); |
| 17 | + |
| 18 | +/** |
| 19 | + * TODO(developer): Update these variables before running the sample. |
| 20 | + */ |
| 21 | +async function analyze_video_with_audio(projectId = 'PROJECT_ID') { |
| 22 | + const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); |
| 23 | + |
| 24 | + const generativeModel = vertexAI.getGenerativeModel({ |
| 25 | + model: 'gemini-1.5-pro-preview-0409', |
| 26 | + }); |
| 27 | + |
| 28 | + const filePart = { |
| 29 | + file_data: { |
| 30 | + file_uri: 'gs://cloud-samples-data/generative-ai/video/pixel8.mp4', |
| 31 | + mime_type: 'video/mp4', |
| 32 | + }, |
| 33 | + }; |
| 34 | + const textPart = { |
| 35 | + text: ` |
| 36 | + Provide a description of the video. |
| 37 | + The description should also contain anything important which people say in the video.`, |
| 38 | + }; |
| 39 | + |
| 40 | + const request = { |
| 41 | + contents: [{role: 'user', parts: [filePart, textPart]}], |
| 42 | + }; |
| 43 | + |
| 44 | + const resp = await generativeModel.generateContent(request); |
| 45 | + const contentResponse = await resp.response; |
| 46 | + console.log(JSON.stringify(contentResponse)); |
| 47 | +} |
| 48 | +// [END generativeaionvertexai_gemini_video_with_audio] |
| 49 | + |
| 50 | +analyze_video_with_audio(...process.argv.slice(2)).catch(err => { |
| 51 | + console.error(err.message); |
| 52 | + process.exitCode = 1; |
| 53 | +}); |
0 commit comments