From c561aa6bbc25021642399c0d4bc0859ac1693d18 Mon Sep 17 00:00:00 2001 From: Sasha Sobran Date: Thu, 19 Sep 2024 18:51:04 -0700 Subject: [PATCH] docs: Update Gemini docs PiperOrigin-RevId: 676646774 --- README.rst | 16 ++++------------ docs/README.rst | 38 ++++++++++++++++---------------------- gemini_docs/README.md | 27 ++++++++++++++++----------- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/README.rst b/README.rst index 5ea497c4b1..070715d556 100644 --- a/README.rst +++ b/README.rst @@ -3,6 +3,10 @@ Vertex AI SDK for Python |GA| |pypi| |versions| |unit-tests| |system-tests| |sample-tests| +.. note:: + + For Gemini API and Generative AI on Vertex AI, please reference `Vertex Generative AI SDK for Python`_ +.. _Vertex Generative AI SDK for Python: https://cloud.google.com/vertex-ai/generative-ai/docs/reference/python/latest `Vertex AI`_: Google Vertex AI is an integrated suite of machine learning tools and services for building and using ML models with AutoML or custom code. It offers both novices and experts the best workbench for the entire machine learning development lifecycle. @@ -113,18 +117,6 @@ Vertex AI SDK resource based functionality can be used by importing the followin from google.cloud import aiplatform -Vertex AI SDK preview functionality can be used by importing the following namespace: - -.. code-block:: Python - - from vertexai import preview - -Vertex AI SDK general availability (GA) functionality can be used by importing the following namespace: - -.. code-block:: Python - - import vertexai - Initialization ^^^^^^^^^^^^^^ Initialize the SDK to store common configurations that you use with the SDK. diff --git a/docs/README.rst b/docs/README.rst index c393e30903..070715d556 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -1,7 +1,12 @@ Vertex AI SDK for Python ================================================= -|GA| |pypi| |versions| +|GA| |pypi| |versions| |unit-tests| |system-tests| |sample-tests| + +.. note:: + + For Gemini API and Generative AI on Vertex AI, please reference `Vertex Generative AI SDK for Python`_ +.. _Vertex Generative AI SDK for Python: https://cloud.google.com/vertex-ai/generative-ai/docs/reference/python/latest `Vertex AI`_: Google Vertex AI is an integrated suite of machine learning tools and services for building and using ML models with AutoML or custom code. It offers both novices and experts the best workbench for the entire machine learning development lifecycle. @@ -14,11 +19,16 @@ Vertex AI SDK for Python :target: https://pypi.org/project/google-cloud-aiplatform/ .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-aiplatform.svg :target: https://pypi.org/project/google-cloud-aiplatform/ +.. |unit-tests| image:: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-unit-tests.svg + :target: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-unit-tests.html +.. |system-tests| image:: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-system-tests.svg + :target: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-system-tests.html +.. |sample-tests| image:: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-sample-tests.svg + :target: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-sample-tests.html .. _Vertex AI: https://cloud.google.com/vertex-ai/docs -.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/aiplatform/latest/summary_overview +.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/aiplatform/latest .. _Product Documentation: https://cloud.google.com/vertex-ai/docs - Quick Start ----------- @@ -59,7 +69,6 @@ Mac/Linux /bin/pip install google-cloud-aiplatform - Windows ^^^^^^^ @@ -70,6 +79,7 @@ Windows \Scripts\activate \Scripts\pip.exe install google-cloud-aiplatform + Supported Python Versions ^^^^^^^^^^^^^^^^^^^^^^^^^ Python >= 3.8 @@ -107,18 +117,6 @@ Vertex AI SDK resource based functionality can be used by importing the followin from google.cloud import aiplatform -Vertex AI SDK preview functionality can be used by importing the following namespace: - -.. code-block:: Python - - from vertexai import preview - -Vertex AI SDK general availability (GA) functionality can be used by importing the following namespace: - -.. code-block:: Python - - import vertexai - Initialization ^^^^^^^^^^^^^^ Initialize the SDK to store common configurations that you use with the SDK. @@ -175,8 +173,8 @@ You can also create and import a dataset in separate steps: my_dataset = aiplatform.TextDataset.create( display_name="my-dataset") - my_dataset.import( - gcs_source=['gs://path/to/my/dataset.csv'] + my_dataset.import_data( + gcs_source=['gs://path/to/my/dataset.csv'], import_schema_uri=aiplatform.schema.dataset.ioformat.text.multi_label_classification ) @@ -232,7 +230,6 @@ It must write the model artifact to the environment variable populated by the tr container_uri="us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-2:latest", requirements=["gcsfs==0.7.1"], model_serving_container_image_uri="us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest", - ) model = job.run(my_dataset, @@ -312,7 +309,6 @@ Please visit `Importing models to Vertex AI`_ for a detailed overview: .. _Importing models to Vertex AI: https://cloud.google.com/vertex-ai/docs/general/import-model - Model Evaluation ---------------- @@ -417,7 +413,6 @@ To get predictions from endpoints: endpoint.predict(instances=[[6.7, 3.1, 4.7, 1.5], [4.6, 3.1, 1.5, 0.2]]) - To undeploy models from an endpoint: .. code-block:: Python @@ -540,7 +535,6 @@ To use Explanation Metadata in endpoint deployment and model upload: aiplatform.Model.upload(..., explanation_metadata=explanation_metadata) - Cloud Profiler ---------------------------- diff --git a/gemini_docs/README.md b/gemini_docs/README.md index 2dc41fd80c..828bfc84f2 100644 --- a/gemini_docs/README.md +++ b/gemini_docs/README.md @@ -1,7 +1,6 @@ # Vertex Generative AI SDK for Python The Vertex Generative AI SDK helps developers use Google's generative AI [Gemini models](http://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/overview) -and [PaLM language models](http://cloud.google.com/vertex-ai/docs/generative-ai/language-model-overview) to build AI-powered features and applications. The SDKs support use cases like the following: @@ -25,7 +24,13 @@ For detailed instructions, see [quickstart](http://cloud.google.com/vertex-ai/do #### Imports: ```python -from vertexai.generative_models import GenerativeModel, Image, Content, Part, Tool, FunctionDeclaration, GenerationConfig +import vertexai +``` + +#### Initialization: + +```python +vertexai.init(project='my-project', location='us-central1') ``` #### Basic generation: @@ -54,7 +59,7 @@ print(vision_model.generate_content(["What is in the video? ", video_part])) ``` #### Chat -``` +```python from vertexai.generative_models import GenerativeModel, Image vision_model = GenerativeModel("gemini-ultra-vision") vision_chat = vision_model.start_chat() @@ -64,7 +69,7 @@ print(vision_chat.send_message("What things do I like?.")) ``` #### System instructions -``` +```python from vertexai.generative_models import GenerativeModel model = GenerativeModel( "gemini-1.0-pro", @@ -78,7 +83,7 @@ print(model.generate_content("Why is sky blue?")) #### Function calling -``` +```python # First, create tools that the model is can use to answer your questions. # Describe a function by specifying it's schema (JsonSchema format) get_current_weather_func = generative_models.FunctionDeclaration( @@ -132,7 +137,7 @@ print(chat.send_message( #### Automatic Function calling -``` +```python from vertexai.preview.generative_models import GenerativeModel, Tool, FunctionDeclaration, AutomaticFunctionCallingResponder # First, create functions that the model can use to answer your questions. @@ -179,7 +184,7 @@ print(chat.send_message("What is the weather like in Boston?")) - To perform bring-your-own-response(BYOR) evaluation, provide the model responses in the `response` column in the dataset. If a pairwise metric is used for BYOR evaluation, provide the baseline model responses in the `baseline_model_response` column. -``` +```python import pandas as pd from vertexai.evaluation import EvalTask, MetricPromptTemplateExamples @@ -203,7 +208,7 @@ eval_result = eval_task.evaluate(experiment_run_name="eval-experiment-run") ``` - To perform evaluation with Gemini model inference, specify the `model` parameter with a `GenerativeModel` instance. The input column name to the model is `prompt` and must be present in the dataset. -``` +```python from vertexai.evaluation import EvalTask from vertexai.generative_models import GenerativeModel @@ -223,7 +228,7 @@ result = EvalTask( - If a `prompt_template` is specified, the `prompt` column is not required. Prompts can be assembled from the evaluation dataset, and all prompt template variable names must be present in the dataset columns. -``` +```python import pandas as pd from vertexai.evaluation import EvalTask, MetricPromptTemplateExamples from vertexai.generative_models import GenerativeModel @@ -245,7 +250,7 @@ result = EvalTask( parameter with a custom inference function. The input column name to the custom inference function is `prompt` and must be present in the dataset. -``` +```python from openai import OpenAI from vertexai.evaluation import EvalTask, MetricPromptTemplateExamples @@ -279,7 +284,7 @@ the `baseline_model` input to a `PairwiseMetric` instance and the candidate `model` input to the `EvalTask.evaluate()` function. The input column name to both models is `prompt` and must be present in the dataset. -``` +```python import pandas as pd from vertexai.evaluation import EvalTask, MetricPromptTemplateExamples, PairwiseMetric from vertexai.generative_models import GenerativeModel