This directory contains Python code samples demonstrating how to use Google Cloud's Generative AI capabilities on Vertex AI. These samples accompany the Google Cloud Generative AI documentation and provide practical examples of various features and use cases.
To run these samples, we recommend using either Google Cloud Shell, Cloud Code IDE, or Google Colab. You'll need a Google Cloud Project and appropriate credentials.
Prerequisites:
- Google Cloud Project: Create or select a project in the Google Cloud Console.
- Authentication: Ensure you've authenticated with your Google Cloud account. See the authentication documentation for details.
- Enable the Vertex AI API: Enable the API in your project through the Cloud Console.
The samples are organized into the following categories:
Demonstrates how to use batch prediction with Generative AI models. This allows efficient processing of large datasets. See the Batch Prediction documentation for more details.
Illustrates how to create, update, use, and delete content caches. Caches store frequently used content to improve performance and reduce costs. See the Content Cache documentation for more information.
Provides examples of how to control various aspects of the generated content, such as length, format, safety attributes, and more. This allows for tailoring the output to specific requirements and constraints. See the Controlled Generation documentation for details.
Shows how to estimate token usage for inputs and outputs of Generative AI models. Understanding token consumption is crucial for managing costs and optimizing performance. See the Token Counting documentation for more details.
Demonstrates how to use Express Mode for simpler and faster interactions with Generative AI models using an API key. This mode is ideal for quick prototyping and experimentation. See the Express Mode documentation for details.
Provides examples of using the Generative AI Live API. This allows for real-time interactions and dynamic content generation.
Provides examples demonstrating how to configure and apply safety settings to Generative AI models. This includes techniques for content filtering and moderation to ensure responsible AI usage. See the Safety documentation for details.
Provides examples of generating text using various input modalities (text, images, audio, video) and features like asynchronous generation, chat, and text streaming. See the Text Generation documentation for details.
Showcases how to use tools like function calling, code execution, and grounding with Google Search to enhance Generative AI interactions. See the Tools documentation for more information.
Contributions are welcome! See the Contributing Guide.
For questions, feedback, or bug reports, please use the issues page.
This repository is not an officially supported Google product. The code is provided for demonstrative purposes only.