Google Cloud Platform Vertex AI PaLM
Note: This is seperate from the Google PaLM integration, it exposes Vertex AI PaLM API on Google Cloud.
By default, Google Cloud does not use Customer Data to train its foundation models as part of Google Cloud`s AI/ML Privacy Commitment. More details about how Google processes data can also be found in Google's Customer Data Processing Addendum (CDPA).
To use Vertex AI PaLM you must have the google-cloud-aiplatform
Python package installed and either:
- Have credentials configured for your environment (gcloud, workload identity, etc...)
- Store the path to a service account JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable
This codebase uses the google.auth
library which first looks for the application credentials variable mentioned above, and then looks for system-level auth.
For more information, see:
- https://cloud.google.com/docs/authentication/application-default-credentials#GAC
- https://googleapis.dev/python/google-auth/latest/reference/google.auth.html#module-google.auth
#!pip install google-cloud-aiplatform
from langchain.llms import VertexAI
from langchain import PromptTemplate, LLMChain
API Reference:
- VertexAI from
langchain.llms
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate(template=template, input_variables=["question"])
llm = VertexAI()
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.run(question)
'Justin Bieber was born on March 1, 1994. The Super Bowl in 1994 was won by the San Francisco 49ers.\nThe final answer: San Francisco 49ers.'
You can now leverage the Codey API for code generation within Vertex AI. The model names are:
- code-bison: for code suggestion
- code-gecko: for code completion
llm = VertexAI(model_name="code-bison")
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "Write a python function that identifies if the number is a prime number?"
llm_chain.run(question)
'```python\ndef is_prime(n):\n """\n Determines if a number is prime.\n\n Args:\n n: The number to be tested.\n\n Returns:\n True if the number is prime, False otherwise.\n """\n\n # Check if the number is 1.\n if n == 1:\n return False\n\n # Check if the number is 2.\n if n == 2:\n return True\n\n'