Setting up Vertex AI SDK for Python

1k views Asked by At

I have to call Vertex AI Structured Text Prompt model using python and below is the code generated for it after clicking on View Code link. However prior to it, seems like we have to set up Vertex AI SDK for Python. However documentation for setting up this SDK seems to be very complex and spanning across multiple webpages.

May I request to please guide me what high level steps(along with documentation link if possible) I have to follow for setting up Vertex AI SDK for Python?

import vertexai
from vertexai.language_models import TextGenerationModel

vertexai.init(project="project-1-369709", location="us-central1")
parameters = {
    "candidate_count": 1,
    "max_output_tokens": 1024,
    "temperature": 0.2,
    "top_p": 0.8,
    "top_k": 40
}
model = TextGenerationModel.from_pretrained("text-bison")
response = model.predict(
    """UiPath is a global software company that makes robotic process automation (RPA) software. It was founded in Bucharest, Romania, by Daniel Dines and Marius Tîrcă. Its headquarters are in New York City. The company\'s software monitors user activity to automate repetitive front and back office tasks, including those performed using other business software such as customer relationship management or enterprise resource planning (ERP) software.

In December 2020, the company filed confidentially for an initial public offering, and became public on April 21, 2021.

input: What is Uipath?
output:
""",
    **parameters
)
print(f"Response from Model: {response.text}")

Thanks!

1

There are 1 answers

0
Luciano Martins On

Vertex AI SDK is part of the python libraries available via PyPI.

To install it you basically need to run pip install google-cloud-aiplatform (assuming that your Python environment is properly setup). After that you will have it available on your pip base as below:

lucianomartins@lm-laptop:~$ pip list | grep google-cloud-aiplatform
google-cloud-aiplatform        1.32.0

And then you can start instantiating the SDK on your Python environment as the documentation you've read shows (here a small example within python console):

lucianomartins@lm-laptop:~$ python3
Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:40:32) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> from vertexai.language_models import TextGenerationModel
>>> model = TextGenerationModel.from_pretrained("text-bison@latest")
>>> model.predict("what is a large language model?")
 A large language model (LLM) is a type of artificial intelligence (AI) that is designed to understand and generate human language. LLMs are trained on massive datasets of text and code, which allows them to learn the statistical relationships between words and phrases. This allows them to generate text that is both coherent and informative.

Hope that helps.