How to Use Google’s PaLM 2 API with Python | by Elise Landman | Aug, 2023


Generative AI is all over the place. We see more and more companies investing in this powerful technology as it becomes increasingly clear how much potential it has. And as Gartner states: in the near future, [Generative AI] will become a competitive advantage and differentiator.

“in the near future, [Generative AI] will become a competitive advantage and differentiator.”

Unfortunately, developing Generative AI models is not only a complex work of engineering, but it is usually quite a pricey project. Luckily, we do not have to develop these ourselves — we can reuse what has been pre-developed for us: with APIs! Therefore, let’s not wait any longer — let’s jump right into how we can leverage Generative AI by integrating it into our application.

For this article, we’ll be looking at Google’s answer to LLMs: the PaLM 2 API. PaLM 2 is Google’s newest version of their Pathways Language Model, a large language model which uses around five times more training data than their initial model released in 2022.

In this article I will be going through some code examples and showing you how to authenticate to Google Cloud and use, as well as customize the PaLM 2 APIs with Python 3.11.

The PaLM 2 APIs can be accessed through Google Cloud’s Vertex AI platform. Therefore, before we can make any API calls, we will need to set up our Google Cloud account. You can sign up here and get $300 in free credits to start playing around with the services.

As soon as your account and project are set up, we can go ahead and create a service account which we will use to authenticate to the Vertex AI APIs. We use service accounts, because we can ensure access control to our Google Cloud resources by giving them only specific IAM permissions. For our use case, we will give the service account the Vertex AI User role. This might be too broad for your use case, so I recommend checking the available access roles and choose which one fits your needs.



Source link

Leave a Comment