Friendli
Friendli 通过可扩展、高效的部署选项增强 AI 应用程序性能并优化成本节约,为高需求 AI 工作负载量身定制。
本教程指导您将 Friendli
与 LangChain 集成。
设置
确保已安装 @langchain/community
。
提示
- npm
- Yarn
- pnpm
npm install @langchain/community @langchain/core
yarn add @langchain/community @langchain/core
pnpm add @langchain/community @langchain/core
登录 Friendli Suite 创建个人访问令牌,并将其设置为 FRIENDLI_TOKEN
环境。您可以将团队 ID 设置为 FRIENDLI_TEAM
环境。
您可以通过选择要使用的模型来初始化 Friendli 聊天模型。默认模型是 mixtral-8x7b-instruct-v0-1
。您可以在 docs.friendli.ai 查看可用模型。
使用
import { Friendli } from "@langchain/community/llms/friendli";
const model = new Friendli({
model: "mixtral-8x7b-instruct-v0-1", // Default value
friendliToken: process.env.FRIENDLI_TOKEN,
friendliTeam: process.env.FRIENDLI_TEAM,
maxTokens: 18,
temperature: 0.75,
topP: 0.25,
frequencyPenalty: 0,
stop: [],
});
const response = await model.invoke(
"Check the Grammar: She dont like to eat vegetables, but she loves fruits."
);
console.log(response);
/*
Correct: She doesn't like to eat vegetables, but she loves fruits
*/
const stream = await model.stream(
"Check the Grammar: She dont like to eat vegetables, but she loves fruits."
);
for await (const chunk of stream) {
console.log(chunk);
}
/*
Cor
rect
:
She
doesn
...
she
loves
fruits
*/
API 参考
- Friendli 从
@langchain/community/llms/friendli