We will cover briefly:
- What is MakerSuite
- Chatbot with PaLM API
- Summarize Text with PaLM API
Chatbot with PaLM API
In today’s fast-paced world, users expect instant and personalized interactions with businesses. Chatbots, powered by artificial intelligence, have become instrumental in providing efficient customer support, automating tasks, and delivering tailored recommendations.
Using Firebase AI Extensions — Palm API
Using Firebase AI Extensions — Palm API
We will cover briefly:
- What is MakerSuite
- Chatbot with PaLM API
- Summarize Text with PaLM API
https://flatteredwithflutter.com/media/a520439f9af76daec0ae6df3e0cb2e73Using Firebase AI Extensions
Chatbot with PaLM API
In today’s fast-paced world, users expect instant and personalized interactions with businesses. Chatbots, powered by artificial intelligence, have become instrumental in providing efficient customer support, automating tasks, and delivering tailored recommendations.

Firebase, Google’s mobile and web application development platform, has introduced the PaLM (Pattern Learning Model)
API as an extension to empower developers with even smarter chatbot capabilities.
Before proceeding with the installation of the extension, it’s essential to confirm that you’ve already registered for the Makersuite waitlist and have received approval.
What is MakerSuite?

MakerSuite is a software suite or platform designed to facilitate and enhance the process of creating, designing, and prototyping various products, projects, or solutions.
Go to the Get API Key
to generate your Makersuite Key

Subsequently, you have three choices within the MakerSuite platform:
- text-based prompt,
- a data prompt,
- or a chat prompt.

Installing Chatbot with PaLM API Extension
Upon installation, you’ll be prompted to provide a path within Firestore
where conversation history will be stored as individual documents. The extension will actively monitor the specified collection(s) for any new message documents.
One of the remarkable aspects of the Firebase AI Extensions — PaLM API integration is its seamless integration within the Firebase ecosystem. Developers can easily incorporate the PaLM API into their existing chatbot infrastructure, enhancing the bot’s capabilities without requiring a complete overhaul. This integration ensures a smooth transition and allows developers to harness the power of AI

Steps:
- Install the
Chatbot with PaLM API
extension from Firebase:
Note: Your project should be on the
Blaze (pay-as-you-go) plan
. There will be a nominal fee (usually approximately $0.01/month) for the Firebase resources necessary for this extension, even if it remains unused.
This extension utilizes various Firebase and Google Cloud Platform services, and if you surpass their free-tier limits, there could be associated charges for services such as
- Cloud Firestore and Cloud Functions.
It creates the generateMessage
cloud function within Google Cloud Platform (GCP). Whenever the extension is triggered, you can review its logs through StackDriver, as demonstrated here.

2. Create a path in Cloud Firestore
as follows:
users/{uid}/discussions/{discussionId}/messages
This collection structure will serve as a representation of a discussion involving a Language Model (LLM) through the PaLM API.
3. Generate a document field named prompt
within the messages sub-collection. Within this field, input your query.
4. After a few seconds, you will be able to observe the Palm API’s response within your sub-collection (like below)

Advanced Options
Here’s what you can configure:
1. PaLM API Provider
: Choose between two services — Vertex AI or Generative Language. If you opt for Vertex AI
, the service will be enabled automatically. For Generative Language
you can supply an API key obtained through MakerSuite or your GCP console.
2. Collection Path
: Path to a Cloud Firestore collection representing discussions with a Language Model on the PaLM API.
3. Prompt Field
: Field in the message document containing the prompt.
4. Response Field
: Field in the message document to store the response.
5. Order Field
: Field for ordering conversation history. If absent, the current timestamp is written to this field. Sorting is in descending order.
6. Cloud Functions Location
: Choose where to deploy the extension’s functions.
7. Language Model
: Select the language model you want to use.
8. Context
: Provide contextual information for the language model. During the setup process, you have the flexibility to customize the chatbot’s responses by offering context. For instance, if you intend the chatbot to function as a travel guide, you could provide the following context:
I want you to act as a travel guide.
I will ask you questions about various travel destinations, and you
will describe those destinations and give me suggestions on places to visit.
- This can be passed inside the
context
parameter of the extension
9. Temperature
: Control response randomness. Higher values (closer to 1) produce more varied responses, while lower values (closer to 0) yield less surprising responses.
10. Nucleus Sampling Probability
: If specified, use nucleus sampling as the decoding strategy. Enter a value between 0 and 1.
11. Sampling Strategy Parameter
: If specified, use top-k sampling as the decoding strategy. Set the number of top candidates.
12. Candidate Count
: Default is one. Increase for multiple candidate responses, stored under the ‘candidates’ field in Firestore.
13. Candidates Field
: Field for storing additional candidate responses if the candidate count is greater than one.
14. Enable Per Document Overrides
: If set to “Yes,” discussion parameters can be overwritten by fields in the discussion collection.

Code Snippet
You can also use the Firebase Admin SDK to add a document:
const ref = await admin
.firestore()
.collection("users/{uid}/discussions/{discussionId}/messages")
.add({
prompt: "How are you today?",
})
ref.onSnapshot(snap => {
if (snap.get('response')) console.log(
'RESPONSE:' +
snap.get('response')
)
})
Summarize Text with PaLM API
This Firebase AI extension empowers developers to integrate powerful text summarization capabilities into their applications effortlessly.
With just a few configurations during installation, developers can tailor the summarization model to meet their specific requirements. Whether you need to extract key insights from articles, blog posts, or any text-based content, this extension streamlines the process, saving time and effort.

Installing Summarize Text with PaLM API Extension
We will need to provide the following details:
PaLM API Provider
: Choose from available providers for the PaLM large language model.Firestore Collection Path
: Specify the path to the Firestore collection containing the documents you want to summarize.
Create a path in Cloud Firestore
as follows:
text_documnets/{uid}
Document Field to Summarize
: Indicate the name of the document field that you wish to summarize.
Generate a document field named text
. Within this field, input the text that you wish to summarize.
Target Summary Length (in sentences)
: Define how long you want the summary to be in terms of the number of sentences.Response Field
: Name the field within the document where you want to store the generated summary.
The response from the extension gets stored in the field summary

Once set up, this extension monitors the designated collection for new document additions and performs the following actions:
1. Utilizes the PaLM API to create a summary of the specified document field.
2. Stores the generated summary within the response field of the corresponding document.
This extension utilizes various Firebase and Google Cloud Platform services, and if you surpass their free-tier limits, there could be associated charges for services such as
- Cloud Firestore and Cloud Functions.
It creates the generateSummary
cloud function within Google Cloud Platform (GCP). Whenever the extension is triggered, you can review its logs through StackDriver, as demonstrated here.

Advanced Options
Here’s what you can configure:
PaLM API Provider:
Choose between two services — Vertex AI or Generative Language. If you opt forVertex AI
, the service will be enabled automatically. ForGenerative Language
you can supply an API key obtained through MakerSuite or your GCP console.
2. Collection Name:
Specify the path to the Firestore collection where messages will be generated.
3. Text Field
: Indicate the field within the document that contains the text to summarize.
4. Response Field:
Name the field in the message document where the response will be stored.
5. Target Summary Length:
Determine the desired length of the summary in sentences.
6. Maximum Number of Tokens:
It should be an integer between 1 and 1024, with the extension’s default value being 1024.
7. Cloud Functions Location
: Decide where you want to deploy the functions created for this extension.

Code Snippet
You can also use the Firebase Admin SDK to add a document:
const ref = await admin
.firestore()
.collection("text_documents")
.add({
text: "some text you want summarized"
})
ref.onSnapshot(snap => {
if (snap.get('summary')) console.log(
'RESPONSE:',
snap.get('summary')
)
})
Bonus:
We have integrated the Summarize Text with PaLM API Extension
into our web platform called SummExt
You can input the text you want to summarize into a designated box and simply click the “Summarize” button. This action generates a summary of the provided text for you.
