|
1 |
| -# Generative AI on Google Cloud |
2 |
| - |
3 |
| -* Product Page: https://cloud.google.com/ai/generative-ai?hl=en |
4 |
| -* Code samples: https://cloud.google.com/docs/samples?text=Generative%20AI |
5 |
| - |
6 |
| -## Samples Style Guide |
7 |
| - |
8 |
| -If you are interested in code sample contributions, see [Contributing Guide](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md). |
9 |
| - |
10 |
| -Only for Generative AI Python samples, below style guide instructions take precedence over [Samples Style Guide](https://googlecloudplatform.github.io/samples-style-guide/). |
11 |
| - |
12 |
| -### 1. Use Scripting format |
13 |
| - |
14 |
| -Wrap the imports, sample code and the region tags to be with in one function definition. |
15 |
| -This is to keep the region tag section code to be in script format and also allowing you to write regular testcases. |
16 |
| - |
17 |
| -> This change is motivated by the desire to provide code samples in a copy-paste-run |
18 |
| -format that is helpful for popular data science community tools like |
19 |
| -Google Colab, Jupyter Notebooks, and IPython shell. |
20 |
| - |
21 |
| -Here is an example code. |
22 |
| - |
23 |
| -```python |
24 |
| -def create_hello_world_file(filename): |
25 |
| - # <region tag: starts here> |
26 |
| - import os |
27 |
| - |
28 |
| - # TODO(developer): Update and uncomment below code |
29 |
| - # filename = `/tmp/test.txt` |
30 |
| - |
31 |
| - if os.path.isfile(filename): |
32 |
| - print(f'Overriding content in file(name: {filename})!') |
33 |
| - |
34 |
| - with open(filename) as fp: |
35 |
| - fp.write('Hello world!') |
36 |
| - # <region tag: ends here> |
37 |
| -``` |
38 |
| - |
39 |
| -In Google Cloud documentation, this code sample will be shown as below |
40 |
| - |
41 |
| -```python |
42 |
| -import os |
43 |
| - |
44 |
| -# TODO(developer): Update and uncomment below code |
45 |
| -# filename = `/tmp/test.txt` |
46 |
| - |
47 |
| -if os.path.isfile(filename): |
48 |
| - print(f'Overriding content in file(name: {filename})!') |
49 |
| - |
50 |
| -with open(filename) as fp: |
51 |
| - fp.write('Hello world!') |
52 |
| -``` |
53 |
| - |
54 |
| -**Note:** In the above sample, `imports` are include and `TODO's` are provided to variable |
55 |
| -that need to update by users. |
56 |
| - |
57 |
| -### 2. Avoid Hidden Variables |
58 |
| - |
59 |
| -Suggestion to avoid hidden variables in code samples |
60 |
| - |
61 |
| -* Use global variables, to defined common variables like PROJECT_ID, LOCATION. |
62 |
| - |
63 |
| -* Keep the function definitions simple, with less or no arguments. |
64 |
| - * Ex: Use `def generate_text() -> str:` instead of `def generate_text(temperature=..image_path=..video_path=..) -> str:` |
65 |
| - |
66 |
| -* Use descriptive variables names and if need, use long variable name. |
67 |
| - * Ex: Use `text_input` instead of `user_input` or `input_var` or `myvar` ... |
68 |
| - |
69 |
| -* Resist the temptation to tell more |
70 |
| - * Ex: Don't define unused optional arguments |
71 |
| - * Ex: Use `Read more @ http://..` than explaining `video_config looks like {"foo": "bar",...}` |
72 |
| - |
73 |
| -**Note**: Not all the samples are the same! "Avoid Hidden variables" is not same as "Dont/No Hidden Variables". |
74 |
| - |
75 |
| - |
76 |
| -## Conclusion |
77 |
| - |
78 |
| -To summarize, it's crucial to maintain the simplicity and brevity of your code |
79 |
| -examples. |
80 |
| -> The ideal sample is one that appears self-evident and immediately |
81 |
| -comprehensible. |
82 |
| - |
83 |
| - |
84 |
| - |
| 1 | +# Generative AI Samples on Google Cloud |
| 2 | + |
| 3 | +Welcome to the Python samples folder for Generative AI on Vertex AI! In this folder, you can find the Python samples |
| 4 | +used in [Google Cloud Generative AI documentation](https://cloud.google.com/ai/generative-ai?hl=en). |
| 5 | + |
| 6 | +If you are looking for colab notebook, then this [link](https://github.com/GoogleCloudPlatform/generative-ai/tree/main). |
| 7 | + |
| 8 | +## Getting Started |
| 9 | + |
| 10 | +To try and run these Code samples, we have following recommend using Google Cloud IDE or Google Colab. |
| 11 | + |
| 12 | +Note: A Google Cloud Project is a pre-requisite. |
| 13 | + |
| 14 | +### Feature folders |
| 15 | + |
| 16 | +Browse the folders below to find the Generative AI capabilities you're interested in. |
| 17 | + |
| 18 | +<table> |
| 19 | + <tr> |
| 20 | + <td><strong>Python Samples Folder</strong> |
| 21 | + </td> |
| 22 | + <td><strong>Google Cloud Product</strong> |
| 23 | + </td> |
| 24 | + <td><strong>Short Description (With the help of Gemini 1.5)</strong> |
| 25 | + </td> |
| 26 | + </tr> |
| 27 | + <tr> |
| 28 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/context_caching">Context Caching</a> |
| 29 | + </td> |
| 30 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/context-cache/context-cache-overview">https://cloud.google.com/vertex-ai/generative-ai/docs/context-cache/context-cache-overview</a> |
| 31 | + </td> |
| 32 | + <td>Code samples demonstrating how to use context caching with Vertex AI's generative models. This allows for more consistent and relevant responses across multiple interactions by storing previous conversation history. |
| 33 | + </td> |
| 34 | + </tr> |
| 35 | + <tr> |
| 36 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/controlled_generation">Controlled Generation</a> |
| 37 | + </td> |
| 38 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/control-generated-output">https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/control-generated-output</a> |
| 39 | + </td> |
| 40 | + <td>Examples of how to control the output of generative models, such as specifying length, format, or sentiment. |
| 41 | + </td> |
| 42 | + </tr> |
| 43 | + <tr> |
| 44 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/count_token">Count Token</a> |
| 45 | + </td> |
| 46 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/list-token">https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/list-token</a> |
| 47 | + </td> |
| 48 | + <td>Code demonstrating how to count tokens in text, which is crucial for managing costs and understanding model limitations. |
| 49 | + </td> |
| 50 | + </tr> |
| 51 | + <tr> |
| 52 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/embeddings">Embeddings</a> |
| 53 | + </td> |
| 54 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings">https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings</a> |
| 55 | + </td> |
| 56 | + <td>Code showing how to generate and use embeddings from text or images. Embeddings can be used for tasks like semantic search, clustering, and classification. |
| 57 | + </td> |
| 58 | + </tr> |
| 59 | + <tr> |
| 60 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/extensions">Extensions</a> |
| 61 | + </td> |
| 62 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/extensions/overview">https://cloud.google.com/vertex-ai/generative-ai/docs/extensions/overview</a> |
| 63 | + </td> |
| 64 | + <td>Demonstrations of how to use extensions with generative models, enabling them to access and process real-time information, use tools, and interact with external systems. |
| 65 | + </td> |
| 66 | + </tr> |
| 67 | + <tr> |
| 68 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/function_calling">Function Calling</a> |
| 69 | + </td> |
| 70 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling">https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling</a> |
| 71 | + </td> |
| 72 | + <td>Examples of how to use function calling to enable generative models to execute specific actions or retrieve information from external APIs. |
| 73 | + </td> |
| 74 | + </tr> |
| 75 | + <tr> |
| 76 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/grounding">Grounding</a> |
| 77 | + </td> |
| 78 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview">https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview</a> |
| 79 | + </td> |
| 80 | + <td>Code illustrating how to ground generative models with specific knowledge bases or data sources to improve the accuracy and relevance of their responses. |
| 81 | + </td> |
| 82 | + </tr> |
| 83 | + <tr> |
| 84 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/image_generation">Image Generation</a> |
| 85 | + </td> |
| 86 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/image/overview">https://cloud.google.com/vertex-ai/generative-ai/docs/image/overview</a> |
| 87 | + </td> |
| 88 | + <td>Samples showcasing how to generate images from text prompts using models like Imagen. |
| 89 | + </td> |
| 90 | + </tr> |
| 91 | + <tr> |
| 92 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/model_garden">Model Garden</a> |
| 93 | + </td> |
| 94 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/model-garden/explore-models">https://cloud.google.com/vertex-ai/generative-ai/docs/model-garden/explore-models</a> |
| 95 | + </td> |
| 96 | + <td>Resources related to exploring and utilizing pre-trained models available in Vertex AI's Model Garden. |
| 97 | + </td> |
| 98 | + </tr> |
| 99 | + <tr> |
| 100 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/model_tuning">Model Tuning</a> |
| 101 | + </td> |
| 102 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/models/tune-models">https://cloud.google.com/vertex-ai/generative-ai/docs/models/tune-models</a> |
| 103 | + </td> |
| 104 | + <td>Code and guides for fine-tuning pre-trained generative models on specific datasets or for specific tasks. |
| 105 | + </td> |
| 106 | + </tr> |
| 107 | + <tr> |
| 108 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/rag">RAG</a> |
| 109 | + </td> |
| 110 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/rag-api">https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/rag-api</a> |
| 111 | + </td> |
| 112 | + <td>Information and resources about Retrieval Augmented Generation (RAG), which combines information retrieval with generative models. |
| 113 | + </td> |
| 114 | + </tr> |
| 115 | + <tr> |
| 116 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/reasoning_engine">Reasoning Engine</a> |
| 117 | + </td> |
| 118 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/reasoning-engine">https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/reasoning-engine</a> |
| 119 | + </td> |
| 120 | + <td>Details about the Reasoning Engine, which enables more complex reasoning and logical deduction in generative models. |
| 121 | + </td> |
| 122 | + </tr> |
| 123 | + <tr> |
| 124 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/safety">Safety</a> |
| 125 | + </td> |
| 126 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-attributes">https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-attributes</a> |
| 127 | + </td> |
| 128 | + <td>Examples of how to configure safety attributes and filters to mitigate risks and ensure responsible use of generative models. |
| 129 | + </td> |
| 130 | + </tr> |
| 131 | + <tr> |
| 132 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/system_instructions">System Instructions</a> |
| 133 | + </td> |
| 134 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/system-instructions?hl=en">https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/system-instructions?hl=en</a> |
| 135 | + </td> |
| 136 | + <td>Code demonstrating how to provide system instructions to guide the behavior and responses of generative models. |
| 137 | + </td> |
| 138 | + </tr> |
| 139 | + <tr> |
| 140 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/text_generation">Text Generation</a> |
| 141 | + </td> |
| 142 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/send-chat-prompts-gemini">https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/send-chat-prompts-gemini</a> |
| 143 | + </td> |
| 144 | + <td>Samples of how to generate text using Gemini models, including chat-based interactions and creative writing. |
| 145 | + </td> |
| 146 | + </tr> |
| 147 | + <tr> |
| 148 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/audio">Understand Audio</a> |
| 149 | + </td> |
| 150 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding">https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding</a> |
| 151 | + </td> |
| 152 | + <td>Examples of how to use generative models for audio understanding tasks, such as transcription and audio classification. |
| 153 | + </td> |
| 154 | + </tr> |
| 155 | + <tr> |
| 156 | + <td><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai/video">Understand Video</a> |
| 157 | + </td> |
| 158 | + <td><a href="https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/video-understanding">https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/video-understanding</a> |
| 159 | + </td> |
| 160 | + <td>Samples showcasing how to use generative models for video understanding tasks, such as video summarization and content analysis. |
| 161 | + </td> |
| 162 | + </tr> |
| 163 | +</table> |
| 164 | + |
| 165 | +## Contributing |
| 166 | + |
| 167 | +Contributions welcome! See the [Contributing Guide](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md). |
| 168 | + |
| 169 | +## Getting help |
| 170 | + |
| 171 | +Please use the [issues page](https://github.com/GoogleCloudPlatform/python-docs-samples/issues) to provide suggestions, feedback or submit a bug report. |
| 172 | + |
| 173 | +## Disclaimer |
| 174 | + |
| 175 | +This repository itself is not an officially supported Google product. The code in this repository is for demonstrative purposes only. |
0 commit comments