マルチモーダル AI モデルでコンテンツを生成する非同期の例

このコードサンプルは、非同期機能を使用して生成 AI モデルを使用する方法を示しています。

コードサンプル

Python

このサンプルを試す前に、Vertex AI クイックスタート: クライアント ライブラリの使用にある Python の設定手順を完了してください。 詳細については、Vertex AI Python API のリファレンス ドキュメントをご覧ください。

Vertex AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

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

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

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

次のステップ

他の Google Cloud プロダクトのコードサンプルを検索およびフィルタするには、Google Cloud サンプル ブラウザをご覧ください。