Friendli
Friendli 通过可扩展、高效的部署选项提升 AI 应用性能并优化成本节省,专为高需求的 AI 工作负载量身打造。
本教程将指导你使用 LangChain 通过 ChatFriendli 集成聊天应用。ChatFriendli 提供了生成对话式 AI 响应的灵活方法,支持同步和异步调用。
安装配置
请确保已安装 @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 的聊天模型。默认模型是 meta-llama-3-8b-instruct。你可以在 docs.friendli.ai 查看可用模型。
使用方法
import { ChatFriendli } from "@langchain/community/chat_models/friendli";
const model = new ChatFriendli({
model: "meta-llama-3-8b-instruct", // Default value
friendliToken: process.env.FRIENDLI_TOKEN,
friendliTeam: process.env.FRIENDLI_TEAM,
maxTokens: 800,
temperature: 0.9,
topP: 0.9,
frequencyPenalty: 0,
stop: [],
});
const response = await model.invoke(
"Draft a cover letter for a role in software engineering."
);
console.log(response.content);
/*
Dear [Hiring Manager],
I am excited to apply for the role of Software Engineer at [Company Name]. With my passion for innovation, creativity, and problem-solving, I am confident that I would be a valuable asset to your team.
As a highly motivated and detail-oriented individual, ...
*/
const stream = await model.stream(
"Draft a cover letter for a role in software engineering."
);
for await (const chunk of stream) {
console.log(chunk.content);
}
/*
D
ear
[
H
iring
...
[
Your
Name
]
*/
API Reference:
- ChatFriendli from
@langchain/community/chat_models/friendli
相关内容
Related
- Chat model conceptual guide
- Chat model how-to guides