VertexAI Language Model allows you to use generative AI functionality by calling PALM2 model with text-bison. You can do Q&A, summarization, classification, creating recipes etc.
Code Lab: https://codelabs.developers.google.com/codelabs/genai-text-gen-java-palm-langchain4j
GitHub Src Code: https://github.com/vaasu1234/gcp/tree/master/palm-workshop
Setup:
In this project, we will create a base java application using Gradle. Gradle Init gives you options for your java application including build script and test framework.
$ brew install gradle
$ gradle init //build script DSL: groovy; test framework: JUnit Jupiter
The java application needs to call GCP API and for that we need to provide authentication credentials. We need to set Application Default Credentials (ADC) that your JAVA IDE can look for to access GCP Resources:
ADC searches for credentials in the following locations:
GOOGLE_APPLICATION_CREDENTIALS environment variable
User credentials set up by using the Google Cloud CLI
The attached service account, returned by the metadata server
For this project, we will have gCloud create credentials for local development purposes.
$ gcloud auth application-default login
Below is the Vertex AI Builder to initialize and trigger the Gen AI Model.
//Initialize Model
VertexAiLanguageModel model = VertexAiLanguageModel.builder()
.endpoint("us-central1-aiplatform.googleapis.com:443")
.project("gcp-test-dev-408703")
.location("us-central1")
.publisher("google")
.modelName("text-bison@001")
.maxOutputTokens(10)
.build();
//question
Response<String> response = model.generate("What are large language models?")
//answer
System.out.println(response.content());
Commands to run the app:
$ ./gradlew build
//change the main Java Class
$ ./gradlew run -DjavaMainClass=palm.workshop.TextPrompts