Skip to content

Commit 6bc5aba

Browse files
feat(genai): Add README.md page and an example feature folder (#12792)
* feat(gen_ai): Add README.md page and example feature folder * docs(gen_ai): Replace the region tags with placeholder * Update gen_ai/README.md Co-authored-by: Maciej Strzelczyk <[email protected]> * Update gen_ai/README.md Co-authored-by: Maciej Strzelczyk <[email protected]> * Update README.md * feat(genai): Update the foldername from gen_ai to genai Update the codeowner file for the same --------- Co-authored-by: Maciej Strzelczyk <[email protected]>
1 parent ba5038d commit 6bc5aba

File tree

10 files changed

+244
-5
lines changed

10 files changed

+244
-5
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
/compute/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2323
/dns/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2424
/gemma2/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
25-
/generative_ai/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
25+
/genai/**/* @GoogleCloudPlatform/generative-ai-devrel @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
26+
/generative_ai/**/* @GoogleCloudPlatform/generative-ai-devrel @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2627
/iam/cloud-client/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2728
/kms/**/** @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2829
/media_cdn/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers

genai/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 please check https://github.com/GoogleCloudPlatform/generative-ai.
7+
8+
## Getting Started
9+
10+
To try and run these Code samples, we recommend using Google Cloud IDE or Google Colab.
11+
12+
Note: A Google Cloud Project is a pre-requisite.
13+
14+
## Features folders
15+
16+
All GenAI code samples are organised into folders, referred as Feature folders.
17+
18+
### Features
19+
20+
<table>
21+
<tr>
22+
<td><strong>Python Samples Folder</strong>
23+
</td>
24+
<td><strong>Google Cloud Product</strong>
25+
</td>
26+
<td><strong>Short Description</strong></td>
27+
</tr>
28+
<tr>
29+
<td>[Template Folder](/template_folder) </td>
30+
<td><a href="add-link-here">Link to the feature</a> </td>
31+
<td>Short description</td>
32+
</tr>
33+
</table>
34+
35+
## Contributing
36+
37+
Contributions welcome! See the [Contributing Guide](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md).
38+
39+
## Getting help
40+
41+
Please use the [issues page](https://github.com/GoogleCloudPlatform/python-docs-samples/issues) to provide suggestions, feedback or submit a bug report.
42+
43+
## Disclaimer
44+
45+
This repository itself is not an officially supported Google product. The code in this repository is for demonstrative purposes only.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# # Copyright 2024 Google LLC
2+
# #
3+
# # Licensed under the Apache License, Version 2.0 (the "License");
4+
# # you may not use this file except in compliance with the License.
5+
# # You may obtain a copy of the License at
6+
# #
7+
# # https://www.apache.org/licenses/LICENSE-2.0
8+
# #
9+
# # Unless required by applicable law or agreed to in writing, software
10+
# # distributed under the License is distributed on an "AS IS" BASIS,
11+
# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# # See the License for the specific language governing permissions and
13+
# # limitations under the License.
14+
# import os
15+
#
16+
# from vertexai.generative_models import GenerationResponse
17+
#
18+
# PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
19+
#
20+
#
21+
# def advanced_example() -> GenerationResponse:
22+
# # TODO: <ADD-START-REGION-TAG-HERE>
23+
# import vertexai
24+
# from vertexai.generative_models import GenerativeModel, Part
25+
#
26+
# # TODO(developer): Update and un-comment below line
27+
# # PROJECT_ID = "your-project-id"
28+
# vertexai.init(project=PROJECT_ID, location="us-central1")
29+
#
30+
# model = GenerativeModel("gemini-1.5-flash-002")
31+
#
32+
# contents = [
33+
# Part.from_uri(
34+
# "gs://cloud-samples-data/generative-ai/video/pixel8.mp4",
35+
# mime_type="video/mp4",
36+
# ),
37+
# "Provide a description of the video.",
38+
# ]
39+
#
40+
# # tokens count for user prompt
41+
# response = model.count_tokens(contents)
42+
# print(f"Prompt Token Count: {response.total_tokens}")
43+
# print(f"Prompt Character Count: {response.total_billable_characters}")
44+
# # Example response:
45+
# # Prompt Token Count: 16822
46+
# # Prompt Character Count: 30
47+
#
48+
# # Send text to Gemini
49+
# response = model.generate_content(contents)
50+
# usage_metadata = response.usage_metadata
51+
#
52+
# # tokens count for model response
53+
# print(f"Prompt Token Count: {usage_metadata.prompt_token_count}")
54+
# print(f"Candidates Token Count: {usage_metadata.candidates_token_count}")
55+
# print(f"Total Token Count: {usage_metadata.total_token_count}")
56+
# # Example response:
57+
# # Prompt Token Count: 16822
58+
# # Candidates Token Count: 71
59+
# # Total Token Count: 16893
60+
#
61+
# # TODO: <ADD-END-REGION-TAG-HERE>
62+
# return response
63+
#
64+
#
65+
# if __name__ == "__main__":
66+
# advanced_example()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Default TEST_CONFIG_OVERRIDE for python repos.
16+
17+
# You can copy this file into your directory, then it will be imported from
18+
# the noxfile.py.
19+
20+
# The source of truth:
21+
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py
22+
23+
TEST_CONFIG_OVERRIDE = {
24+
# You can opt out from the test for specific Python versions.
25+
"ignored_versions": ["2.7", "3.7", "3.8", "3.10", "3.11"],
26+
# Old samples are opted out of enforcing Python type hints
27+
# All new samples should feature them
28+
"enforce_type_hints": True,
29+
# An envvar key for determining the project id to use. Change it
30+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
31+
# build specific Cloud project. You can also use your own string
32+
# to use your own Cloud project.
33+
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
34+
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
35+
# If you need to use a specific version of pip,
36+
# change pip_version_override to the string representation
37+
# of the version number, for example, "20.2.4"
38+
"pip_version_override": None,
39+
# A dictionary you want to inject into your test. Don't put any
40+
# secrets here. These values will override predefined values.
41+
"envs": {},
42+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
backoff==2.2.1
2+
google-api-core==2.19.0
3+
pytest==8.2.0
4+
pytest-asyncio==0.23.6
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pandas==1.3.5; python_version == '3.7'
2+
pandas==2.0.3; python_version == '3.8'
3+
pandas==2.1.4; python_version > '3.8'
4+
pillow==10.3.0; python_version < '3.8'
5+
pillow==10.3.0; python_version >= '3.8'
6+
google-cloud-aiplatform[all]==1.69.0
7+
sentencepiece==0.2.0
8+
google-auth==2.29.0
9+
anthropic[vertex]==0.28.0
10+
langchain-core==0.2.11
11+
langchain-google-vertexai==1.0.6
12+
numpy<2
13+
openai==1.30.5
14+
immutabledict==4.2.0
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# # Copyright 2024 Google LLC
2+
# #
3+
# # Licensed under the Apache License, Version 2.0 (the "License");
4+
# # you may not use this file except in compliance with the License.
5+
# # You may obtain a copy of the License at
6+
# #
7+
# # https://www.apache.org/licenses/LICENSE-2.0
8+
# #
9+
# # Unless required by applicable law or agreed to in writing, software
10+
# # distributed under the License is distributed on an "AS IS" BASIS,
11+
# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# # See the License for the specific language governing permissions and
13+
# # limitations under the License.
14+
#
15+
#
16+
# def simple_example() -> int:
17+
# "Simple example for <template_folder> feature."
18+
# # TODO: <ADD-START-REGION-TAG-HERE>
19+
# from vertexai.preview.tokenization import get_tokenizer_for_model
20+
#
21+
# # Using local tokenzier
22+
# tokenizer = get_tokenizer_for_model("gemini-1.5-flash-002")
23+
#
24+
# prompt = "hello world"
25+
# response = tokenizer.count_tokens(prompt)
26+
# print(f"Prompt Token Count: {response.total_tokens}")
27+
# # Example response:
28+
# # Prompt Token Count: 2
29+
#
30+
# prompt = ["hello world", "what's the weather today"]
31+
# response = tokenizer.count_tokens(prompt)
32+
# print(f"Prompt Token Count: {response.total_tokens}")
33+
# # Example response:
34+
# # Prompt Token Count: 8
35+
#
36+
# # TODO: <ADD-START-REGION-TAG-HERE>
37+
# return response.total_tokens
38+
#
39+
#
40+
# if __name__ == "__main__":
41+
# simple_example()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# # Copyright 2024 Google LLC
2+
# #
3+
# # Licensed under the Apache License, Version 2.0 (the "License");
4+
# # you may not use this file except in compliance with the License.
5+
# # You may obtain a copy of the License at
6+
# #
7+
# # https://www.apache.org/licenses/LICENSE-2.0
8+
# #
9+
# # Unless required by applicable law or agreed to in writing, software
10+
# # distributed under the License is distributed on an "AS IS" BASIS,
11+
# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# # See the License for the specific language governing permissions and
13+
# # limitations under the License.
14+
#
15+
# import advanced_example
16+
# import simple_example
17+
#
18+
#
19+
# def test_simple_example() -> None:
20+
# response = simple_example.simple_example()
21+
# assert response
22+
#
23+
#
24+
# def test_advanced_example() -> None:
25+
# response = advanced_example.advanced_example()
26+
# assert response

generative_ai/template_folder/advanced_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020
#
2121
# def advanced_example() -> GenerationResponse:
22-
# # [START generativeaionvertexai_gemini_token_count_multimodal]
22+
# # TODO: <ADD-START-REGION-TAG-HERE>
2323
# import vertexai
2424
# from vertexai.generative_models import GenerativeModel, Part
2525
#
@@ -58,7 +58,7 @@
5858
# # Candidates Token Count: 71
5959
# # Total Token Count: 16893
6060
#
61-
# # [END generativeaionvertexai_gemini_token_count_multimodal]
61+
# # TODO: <ADD-END-REGION-TAG-HERE>
6262
# return response
6363
#
6464
#

generative_ai/template_folder/simple_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#
1616
# def simple_example() -> int:
1717
# "Simple example for <template_folder> feature."
18-
# # [START generativeaionvertexai_token_count_sample_with_local_sdk]
18+
# # TODO: <ADD-START-REGION-TAG-HERE>
1919
# from vertexai.preview.tokenization import get_tokenizer_for_model
2020
#
2121
# # Using local tokenzier
@@ -33,7 +33,7 @@
3333
# # Example response:
3434
# # Prompt Token Count: 8
3535
#
36-
# # [END generativeaionvertexai_token_count_sample_with_local_sdk]
36+
# # TODO: <ADD-END-REGION-TAG-HERE>
3737
# return response.total_tokens
3838
#
3939
#

0 commit comments

Comments
 (0)