Contoh asinkron untuk Membuat konten dengan Model AI Multimodal

Contoh kode menunjukkan cara menggunakan Model AI Generatif menggunakan fitur asinkron

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, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

from google import genai
from google.genai.types import GenerateContentConfig, HttpOptions

client = genai.Client(http_options=HttpOptions(api_version="v1"))
model_id = "gemini-2.0-flash-001"

response = await client.aio.models.generate_content(
    model=model_id,
    contents="Compose a song about the adventures of a time-traveling squirrel.",
    config=GenerateContentConfig(
        response_modalities=["TEXT"],
    ),
)

print(response.text)
# Example response:
# (Verse 1)
# Sammy the squirrel, a furry little friend
# Had a knack for adventure, beyond all comprehend

Langkah berikutnya

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