Skip to main content

ChatGooglePaLM

note

This integration does not support gemini-* models. Check Google AI.

The Google PaLM API can be integrated by first installing the required packages:

npm install google-auth-library @google-ai/generativelanguage @langchain/community

Create an API key from Google MakerSuite. You can then set the key as GOOGLE_PALM_API_KEY environment variable or pass it as apiKey parameter while instantiating the model.

import { ChatGooglePaLM } from "@langchain/community/chat_models/googlepalm";
import {
AIMessage,
HumanMessage,
SystemMessage,
} from "@langchain/core/messages";

export const run = async () => {
const model = new ChatGooglePaLM({
apiKey: "<YOUR API KEY>", // or set it in environment variable as `GOOGLE_PALM_API_KEY`
temperature: 0.7, // OPTIONAL
modelName: "models/chat-bison-001", // OPTIONAL
topK: 40, // OPTIONAL
topP: 1, // OPTIONAL
examples: [
// OPTIONAL
{
input: new HumanMessage("What is your favorite sock color?"),
output: new AIMessage("My favorite sock color be arrrr-ange!"),
},
],
});

// ask questions
const questions = [
new SystemMessage(
"You are a funny assistant that answers in pirate language."
),
new HumanMessage("What is your favorite food?"),
];

// You can also use the model as part of a chain
const res = await model.invoke(questions);
console.log({ res });
};

API Reference:


Help us out by providing feedback on this documentation page: