Menggunakan Gemini untuk meringkas file PDF

Contoh ini menunjukkan cara menggunakan Gemini untuk membuat ringkasan file PDF.

Contoh kode

Python

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Python di Panduan memulai Vertex AI menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Python Vertex AI.

Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import vertexai
from vertexai.generative_models import GenerativeModel, Part

# TODO (developer): update project id
vertexai.init(project=PROJECT_ID, location="us-central1")

model = GenerativeModel("gemini-1.5-flash-002")

contents = [
    # Text prompt
    "Summarise this file",
    # Example PDF document on Transformers, a neural network architecture.
    Part.from_uri(
        "https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/1706.03762v7.pdf",
        "application/pdf",
    ),
]

response = model.generate_content(contents)
print(response.text)
# Example response:
#     'This paper introduces the Transformer, a new neural network architecture for '
#     'sequence transduction, which uses an attention mechanism to learn global '
#     'dependencies between input and output sequences. The Transformer ...

Langkah selanjutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat Google Cloud browser contoh.