Merge pull request #20 from the-lazy-me/doc/dify

Doc/dify
This commit is contained in:
Junyan Qin
2024-12-14 18:36:38 +08:00
committed by GitHub
7 changed files with 75 additions and 2 deletions
+5 -1
View File
@@ -180,7 +180,11 @@ export default defineConfig({
text: "实践",
items: [
{
text: "如何在 LangBot 上接入 Dify?",
text: "如何接入 Dify?",
link: "/workshop/dify-service-api",
},
{
text: "如何接入 Dify? - NewAPI 中转方案",
link: "/workshop/dify-integration",
},
{
Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

+48
View File
@@ -170,3 +170,51 @@
`role` 为消息的角色,可以是`user`(用户)、`assistant`(AI)、`system`(系统)
`content` 为字符串,表示消息内容。
在使用中通过`!default set <文件名>`指令将其设为默认(将<预设名>整体替换)
## 请求运行器 runner
```json
"runner": "local-agent",
```
设置聊天消息将由哪个运行器处理,默认是 `local-agent`
目前支持:
- `local-agent`:LangBot 本地实现的一个 Agent 机制,实现会话管理、插件调用。需要设置为 local-agent 才能使用`内容函数`。
- `dify-service-api`:使用 [Dify](https://dify.ai/) 的 Service API 机制,支持 聊天助手、Agent、工作流应用。
## Dify Service API 配置 dify-service-api
```json
"dify-service-api": {
"base-url": "https://api.dify.ai/v1",
"app-type": "chat",
"chat": {
"api-key": "app-1234567890"
},
"workflow": {
"api-key": "app-1234567890",
"output-key": "summary"
}
}
```
仅在 `runner` 设置为 `dify-service-api` 时,需要配置以下内容:
- `base-url`:Dify Service API 的地址,默认是 `https://api.dify.ai/v1`,这是 Dify 官方云服务的地址,如果你使用的是自部署的社区版,请设置为你的自部署地址。
- `app-type`:使用的 Dify 应用类型。支持 `chat`(聊天助手(含高级编排)和 Agent)和 `workflow`(工作流);请填写下方对应的应用类型 API 参数
- `chat`:Dify 聊天助手应用的配置
- `api-key`:Dify 聊天助手应用的 API 密钥
- `workflow`:Dify 工作流应用的配置
- `api-key`:Dify 工作流应用的 API 密钥
- `output-key`:Dify 工作流应用的输出键,用于获取工作流应用的输出结果。默认为`summary`,对应工作流编排时,end节点的输出变量。
![Dify 工作流应用的输出键](/assets/image/config_provider_01.png)
当使用工作流时,LangBot 会显式传入以下参数,您可以自行在 Dify 工作流的开始节点中添加:
- `langbot_user_message_text`:用户消息的纯文本
- `langbot_session_id`:用户会话id,私聊为 `person_<id>`,群聊为 `group_<id>`
- `langbot_conversation_id`:用户会话id,由 LangBot 生成。用户重置会话后,会重新生成
![Dify 工作流开始节点配置](/assets/image/config_provider_02.png)
+2 -1
View File
@@ -1,7 +1,8 @@
# 在 LangBot 上接入 Dify(NewAPI 中转方案)
::: info
本文由社区贡献者编写。
本文由社区贡献者编写。
现已支持直接接入 Dify Service API 使用,请参考 [如何接入 Dify?](./dify-service-api)
:::
[Dify](https://dify.ai/) 是一个开源的 AI 应用开发平台,支持多种 AI 模型和丰富的插件,用于快速搭建 AI Agent、Workflow 等应用。通过中间件,我们可以在 LangBot 上使用 Dify 功能。
+20
View File
@@ -0,0 +1,20 @@
# 在 LangBot 上使用 Dify
[Dify](https://dify.ai) 是一款开源的大语言模型(LLM) 应用开发平台。它融合了后端即服务(Backend as Service)和 LLMOps 的理念,使开发者可以快速搭建生产级的生成式 AI 应用。
Dify 可以创建聊天助手、Agent、文本生成应用、工作流等应用。
LangBot 目前支持`聊天助手`、`Agent`、`工作流`三种 Dify 应用类型。
## 在 Dify 上创建应用
请根据 [Dify文档](https://docs.dify.ai) 部署dify并创建你的应用。
发布应用后,在应用的 `访问API` 页面,生成 API 密钥。
![Dify 应用 API 密钥](/assets/image/dify_sv_api_01.png)
保存 API 服务器和 API 密钥,在 LangBot 的 `provider.json` 文件中配置。
## 配置 LangBot
参考 [Dify Service API 配置](../config/function/provider#dify-service-api-%E9%85%8D%E7%BD%AE-dify-service-api) 文档,配置 LangBot 的 `provider.json` 文件。