Google PaLM(旧版)
危险
Google PaLM API 已弃用,将在 0.3.0 版本中移除。请改用 Google GenAI 集成。
注意
此集成不支持 embeddings-*
模型。请查看 Google GenAI 嵌入。
可以通过首先安装所需的包来集成 Google PaLM API
提示
- npm
- Yarn
- pnpm
npm install google-auth-library @google-ai/generativelanguage @langchain/community
yarn add google-auth-library @google-ai/generativelanguage @langchain/community
pnpm add google-auth-library @google-ai/generativelanguage @langchain/community
从 Google MakerSuite 创建一个 API 密钥。然后可以将密钥设置为 GOOGLE_PALM_API_KEY
环境变量,或者在实例化模型时将其作为 apiKey
参数传递。
import { GooglePaLMEmbeddings } from "@langchain/community/embeddings/googlepalm";
const model = new GooglePaLMEmbeddings({
apiKey: "<YOUR API KEY>", // or set it in environment variable as `GOOGLE_PALM_API_KEY`
model: "models/embedding-gecko-001", // OPTIONAL
});
/* Embed queries */
const res = await model.embedQuery(
"What would be a good company name for a company that makes colorful socks?"
);
console.log({ res });
/* Embed documents */
const documentRes = await model.embedDocuments(["Hello world", "Bye bye"]);
console.log({ documentRes });
API 参考
- GooglePaLMEmbeddings 来自
@langchain/community/embeddings/googlepalm