Skip to content

Files

Latest commit

 

History

History

genai

Generative AI Samples on Google Cloud

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.

Getting Started

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:

Sample Categories

The samples are organized into the following categories:

Batch Prediction (batch_prediction)

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.

Content Cache (content_cache)

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.

Controlled Generation (controlled_generation)

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.

Count Tokens (count_tokens)

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.

Express Mode (express_mode)

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.

Live API (live_api)

Provides examples of using the Generative AI Live API. This allows for real-time interactions and dynamic content generation.

Safety (safety)

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.

Text Generation (text_generation)

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.

Tools (tools)

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.

Contributing

Contributions are welcome! See the Contributing Guide.

Getting Help

For questions, feedback, or bug reports, please use the issues page.

Disclaimer

This repository is not an officially supported Google product. The code is provided for demonstrative purposes only.