Friendli
Friendli 通过可扩展、高效的部署选项增强 AI 应用性能并优化成本节省,专为高需求 AI 工作负载量身定制。
本教程指导您完成将 Friendli
与 LangChain 集成。
设置
确保安装了 @langchain/community
。
提示
- npm
- Yarn
- pnpm
npm install @langchain/community
yarn add @langchain/community
pnpm add @langchain/community
登录 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