@ convokit/ 服务器
ConvoKit目前提前进入. 服务员是现场直播.. 加入 convokit.dev 时 以获得早期访问.
服务器 SDK 用于 骑兵队 —— 使用您的服务器发送 AI 聊天信息 密钥 API。密钥从不离开后端,使这比在浏览器中使用公钥更加安全.
安装
npm install @convokit/server
使用量
const { createClient } = require('@convokit/server');
const client = createClient(process.env.CONVOKIT_SECRET_KEY); // sk_live_...
// New conversation
const { reply, conversation_id } = await client.chat({
message: 'What are your support hours?',
});
console.log(reply);
// Follow-up in the same thread
const { reply: reply2 } = await client.chat({
message: 'And on weekends?',
conversationId: conversation_id,
});
console.log(reply2);
类型脚本
import { createClient, type ChatOptions, type ChatResponse } from '@convokit/server';
const client = createClient({ apiKey: process.env.CONVOKIT_SECRET_KEY! });
const res: ChatResponse = await client.chat({
message: 'Hello',
instanceId: 'my-bot',
chatHistory: [],
});
对话历史
传递之前的消息, AI有上下文 :
const { reply } = await client.chat({
message: 'What did I just ask?',
chatHistory: [
{ role: 'user', content: 'What are your support hours?' },
{ role: 'assistant', content: 'We are open 9am–5pm Monday to Friday.' },
],
});
格式 : { role: 'user' | 'assistant' | 'system', content: string }。 。 。 .
当你有一个 conversationId,可以省略 chatHistory ——后端已经有线程了.
选项
| 选项 | 需求 | 说明 |
|---|---|---|
message | 对 | 要发送的用户信息 |
conversationId | 没有 | 在同一线索中用于后续消息 |
widgetId | 没有 | 组合的标识符( 如: bot name, channel) |
chatHistory | 没有 | 上一则上下文信件 |
回应
| 外地 | 说明 |
|---|---|
reply | 大赦国际的答复案文 |
conversation_id | 在下一个消息中传递此内容以继续线索 |
usage | 托肯用法 - prompt_tokens, (中文(简体) ), completion_tokens, (中文(简体) ), total_tokens |
警卫
- 使用一个 密钥 (单位:千美元)
sk_live_...在您的服务器上 。 永远不要在浏览器或客户端代码中曝光. - 对于浏览器/部件的使用,请使用 公钥 (单位:千美元)
pk_live_...与@convokit/widget软件包.
提前获取
ConvoKit提前进入 获取您的 API 密钥并配置您的 AI convokit.dev (英语)。 。 。 .
等待名单是现场直播的——现在加入进来,以便早日进入.
许可证
麻省理工学院