mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-29 20:05:25 +08:00
Merge branch 'main' of github.com:langbot-app/Langbot-Wiki
This commit is contained in:
@@ -14,6 +14,15 @@
|
||||
"href": "https://langbot.app"
|
||||
},
|
||||
"favicon": "/favicon.ico",
|
||||
"description": "Official documentation for LangBot — the open-source multi-platform AI bot framework. Deploy Dify, Coze, n8n, GPT-4, Claude, and DeepSeek to Discord, Slack, Telegram, WeChat, DingTalk, Lark, LINE, and QQ in minutes.",
|
||||
"seo": {
|
||||
"indexing": "all",
|
||||
"metatags": {
|
||||
"og:site_name": "LangBot Docs",
|
||||
"twitter:card": "summary_large_image",
|
||||
"og:image": "https://langbot.app/og-image.png"
|
||||
}
|
||||
},
|
||||
"navbar": {
|
||||
"links": [
|
||||
{
|
||||
@@ -701,5 +710,8 @@
|
||||
"description": "Production-grade No-code AI Bot Platform. Connect DeepSeek, Dify, GPT-4 & Claude to WeChat, Discord, Telegram, Slack, Lark & DingTalk in 5 minutes.",
|
||||
"fonts": {
|
||||
"family": "Source Sans Pro"
|
||||
},
|
||||
"metadata": {
|
||||
"google-site-verification": "LBNmWbXCAXdoqrbwg5Gep-xzQ7u7lJHSdpR49N3Ttgg"
|
||||
}
|
||||
}
|
||||
@@ -82,9 +82,9 @@ async def get_query_vars(self) -> dict[str, Any]:
|
||||
query_vars = await event_context.get_query_vars()
|
||||
```
|
||||
|
||||
### List Knowledge Bases Configured for the Current Pipeline
|
||||
### List Pipeline Knowledge Bases
|
||||
|
||||
Get the knowledge bases configured in the pipeline used by the current request.
|
||||
Get the list of knowledge bases configured for the pipeline used by the current request.
|
||||
|
||||
```python
|
||||
async def list_pipeline_knowledge_bases(self) -> list[dict[str, Any]]:
|
||||
@@ -103,44 +103,7 @@ knowledge_bases = await event_context.list_pipeline_knowledge_bases()
|
||||
]
|
||||
```
|
||||
|
||||
This only returns knowledge bases bound in the current pipeline's `Local Agent` configuration. If the pipeline has no knowledge base configured, or is not using `Local Agent`, an empty list is returned.
|
||||
|
||||
### Retrieve Knowledge from the Current Pipeline Scope
|
||||
|
||||
Run retrieval against the knowledge bases that are allowed for the current request's pipeline.
|
||||
|
||||
```python
|
||||
async def retrieve_knowledge(
|
||||
self,
|
||||
kb_id: str,
|
||||
query_text: str,
|
||||
top_k: int = 5,
|
||||
filters: dict[str, Any] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Retrieve relevant documents from a knowledge base"""
|
||||
|
||||
# Usage example
|
||||
knowledge_bases = await event_context.list_pipeline_knowledge_bases()
|
||||
results = await event_context.retrieve_knowledge(
|
||||
kb_id=knowledge_bases[0]["uuid"],
|
||||
query_text="How do I configure the enterprise knowledge base?",
|
||||
top_k=3,
|
||||
filters={"document_type": {"$eq": "manual"}},
|
||||
)
|
||||
|
||||
# Return example
|
||||
[
|
||||
{
|
||||
"id": "chunk_0",
|
||||
"content": [{"type": "text", "text": "Knowledge base configuration guide"}],
|
||||
"metadata": {"document_id": "doc_001"},
|
||||
"distance": 0.12,
|
||||
"score": 0.88,
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
`kb_id` must come from `list_pipeline_knowledge_bases` and must belong to a knowledge base configured for the current pipeline. Otherwise, LangBot returns an error.
|
||||
Only returns knowledge bases bound in the `Local Agent` configuration of the pipeline corresponding to the current request. If the current pipeline has no knowledge bases configured, or does not use `Local Agent`, an empty list is returned.
|
||||
|
||||
## LangBot API
|
||||
|
||||
@@ -382,6 +345,69 @@ file_bytes = await self.plugin.get_config_file("key")
|
||||
|
||||
Use this in conjunction with configuration fields of type [``file or array[file``](/en/plugin/dev/basic-info.html#type-file).
|
||||
|
||||
## Knowledge Base API
|
||||
|
||||
These APIs are accessible via `self.plugin` in any component, allowing you to list and retrieve from all knowledge bases in the LangBot instance without pipeline restrictions.
|
||||
|
||||
### List All Knowledge Bases
|
||||
|
||||
List all available knowledge bases in the LangBot instance.
|
||||
|
||||
```python
|
||||
async def list_knowledge_bases(self) -> list[dict[str, Any]]:
|
||||
"""List all knowledge bases
|
||||
|
||||
Returns:
|
||||
List of knowledge base dicts, each containing:
|
||||
- uuid: Knowledge base UUID
|
||||
- name: Knowledge base name
|
||||
- description: Knowledge base description
|
||||
"""
|
||||
|
||||
# Usage example
|
||||
knowledge_bases = await self.plugin.list_knowledge_bases()
|
||||
for kb in knowledge_bases:
|
||||
print(f"KB: {kb['name']} ({kb['uuid']})")
|
||||
```
|
||||
|
||||
### Retrieve from Knowledge Base
|
||||
|
||||
Retrieve relevant documents from any knowledge base.
|
||||
|
||||
```python
|
||||
async def retrieve_knowledge(
|
||||
self,
|
||||
kb_id: str,
|
||||
query_text: str,
|
||||
top_k: int = 5,
|
||||
filters: dict[str, Any] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Retrieve from a knowledge base
|
||||
|
||||
Args:
|
||||
kb_id: Knowledge base UUID (from list_knowledge_bases)
|
||||
query_text: Search query text
|
||||
top_k: Number of results to return (default: 5)
|
||||
filters: Optional metadata filters for retrieval
|
||||
|
||||
Returns:
|
||||
List of retrieval result entries
|
||||
"""
|
||||
|
||||
# Usage example
|
||||
results = await self.plugin.retrieve_knowledge(
|
||||
kb_id="kb-uuid-here",
|
||||
query_text="How to configure the system?",
|
||||
top_k=3,
|
||||
)
|
||||
for entry in results:
|
||||
print(entry)
|
||||
```
|
||||
|
||||
<Tip>
|
||||
These APIs do not require a `query_id` and can be used in any component (including Tool components). They can access all knowledge bases without being restricted to the current pipeline's configuration.
|
||||
</Tip>
|
||||
|
||||
## RAG API
|
||||
|
||||
These APIs are available for `KnowledgeEngine` components to access the LangBot host's embedding models, vector database, and file storage. Access method:
|
||||
|
||||
@@ -14,6 +14,22 @@ This will redirect to GitHub authorization page, please complete authorization a
|
||||
|
||||
## Log in to LangBot Space Using CLI
|
||||
|
||||
### Option 1: Personal Access Token (Recommended)
|
||||
|
||||
1. Log in to [LangBot Space](https://space.langbot.app), click your avatar to open **Account Settings**, find **Personal Access Tokens** under the **Account** tab, and create a new token.
|
||||
2. Copy the generated token (shown only once), then run:
|
||||
|
||||
```bash
|
||||
➜ HelloPlugin > lbp login --token lbpat_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
|
||||
==================================================
|
||||
✅ Logged in with personal access token!
|
||||
Token saved to: ~/.langbot/cli/config.json
|
||||
==================================================
|
||||
```
|
||||
|
||||
### Option 2: Device Code Verification
|
||||
|
||||
Execute command `lbp login` in any directory:
|
||||
|
||||
```bash
|
||||
@@ -44,7 +60,7 @@ Expires in: 21600 seconds
|
||||
==================================================
|
||||
```
|
||||
|
||||
After successful login, you can continue using CLI to upload plugins.
|
||||
After successful login with either method, you can continue using CLI to upload plugins.
|
||||
|
||||
## Upload Plugin
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
google-site-verification: googleebab2ef285c63b19.html
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 4.6 KiB |
@@ -84,7 +84,7 @@ query_vars = await event_context.get_query_vars()
|
||||
|
||||
### 現在のパイプラインに設定されたナレッジベース一覧の取得
|
||||
|
||||
現在のリクエストで使用されているパイプラインに設定されたナレッジベース一覧を取得します。
|
||||
現在のリクエストが使用するパイプラインに設定されたナレッジベースの一覧を取得します。
|
||||
|
||||
```python
|
||||
async def list_pipeline_knowledge_bases(self) -> list[dict[str, Any]]:
|
||||
@@ -93,7 +93,7 @@ async def list_pipeline_knowledge_bases(self) -> list[dict[str, Any]]:
|
||||
# 使用例
|
||||
knowledge_bases = await event_context.list_pipeline_knowledge_bases()
|
||||
|
||||
# 返却例
|
||||
# 返り値の例
|
||||
[
|
||||
{
|
||||
"uuid": "kb_uuid",
|
||||
@@ -103,44 +103,7 @@ knowledge_bases = await event_context.list_pipeline_knowledge_bases()
|
||||
]
|
||||
```
|
||||
|
||||
返されるのは、現在のパイプラインの `Local Agent` 設定に紐づいたナレッジベースだけです。ナレッジベースが未設定、または `Local Agent` を使っていない場合は空配列になります。
|
||||
|
||||
### 現在のパイプライン範囲でナレッジを検索
|
||||
|
||||
現在のリクエストのパイプラインで許可されているナレッジベースの範囲内で検索を実行します。
|
||||
|
||||
```python
|
||||
async def retrieve_knowledge(
|
||||
self,
|
||||
kb_id: str,
|
||||
query_text: str,
|
||||
top_k: int = 5,
|
||||
filters: dict[str, Any] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Retrieve relevant documents from a knowledge base"""
|
||||
|
||||
# 使用例
|
||||
knowledge_bases = await event_context.list_pipeline_knowledge_bases()
|
||||
results = await event_context.retrieve_knowledge(
|
||||
kb_id=knowledge_bases[0]["uuid"],
|
||||
query_text="エンタープライズ向けナレッジベースの設定方法は?",
|
||||
top_k=3,
|
||||
filters={"document_type": {"$eq": "manual"}},
|
||||
)
|
||||
|
||||
# 返却例
|
||||
[
|
||||
{
|
||||
"id": "chunk_0",
|
||||
"content": [{"type": "text", "text": "ナレッジベース設定ガイド"}],
|
||||
"metadata": {"document_id": "doc_001"},
|
||||
"distance": 0.12,
|
||||
"score": 0.88,
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
`kb_id` は `list_pipeline_knowledge_bases` の返却値から取得し、現在のパイプラインに設定されたナレッジベースである必要があります。そうでない場合、LangBot はエラーを返します。
|
||||
現在のリクエストに対応するパイプラインの `Local Agent` 設定にバインドされたナレッジベースのみを返します。現在のパイプラインにナレッジベースが設定されていない場合、または `Local Agent` を使用していない場合は、空のリストが返されます。
|
||||
|
||||
## LangBot API
|
||||
|
||||
@@ -382,6 +345,69 @@ file_bytes = await self.plugin.get_config_file("key")
|
||||
|
||||
これは[``fileまたはarray[file``](/en/plugin/dev/basic-info.html#type-file)型の設定フィールドと組み合わせて使用します。
|
||||
|
||||
## ナレッジベース API
|
||||
|
||||
これらのAPIは任意のコンポーネントから`self.plugin`経由でアクセスでき、パイプライン制限なしにLangBotインスタンス内のすべてのナレッジベースの一覧取得と検索が可能です。
|
||||
|
||||
### すべてのナレッジベースの一覧取得
|
||||
|
||||
LangBotインスタンスで利用可能なすべてのナレッジベースを一覧取得します。
|
||||
|
||||
```python
|
||||
async def list_knowledge_bases(self) -> list[dict[str, Any]]:
|
||||
"""すべてのナレッジベースを一覧取得
|
||||
|
||||
Returns:
|
||||
ナレッジベースのリスト、各要素は以下を含む:
|
||||
- uuid: ナレッジベースUUID
|
||||
- name: ナレッジベース名
|
||||
- description: ナレッジベースの説明
|
||||
"""
|
||||
|
||||
# 使用例
|
||||
knowledge_bases = await self.plugin.list_knowledge_bases()
|
||||
for kb in knowledge_bases:
|
||||
print(f"KB: {kb['name']} ({kb['uuid']})")
|
||||
```
|
||||
|
||||
### ナレッジベースからの検索
|
||||
|
||||
任意のナレッジベースから関連ドキュメントを検索します。
|
||||
|
||||
```python
|
||||
async def retrieve_knowledge(
|
||||
self,
|
||||
kb_id: str,
|
||||
query_text: str,
|
||||
top_k: int = 5,
|
||||
filters: dict[str, Any] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""ナレッジベースから検索
|
||||
|
||||
Args:
|
||||
kb_id: ナレッジベースUUID(list_knowledge_basesから取得)
|
||||
query_text: 検索クエリテキスト
|
||||
top_k: 返す結果の数(デフォルト:5)
|
||||
filters: オプションのメタデータフィルター
|
||||
|
||||
Returns:
|
||||
検索結果エントリのリスト
|
||||
"""
|
||||
|
||||
# 使用例
|
||||
results = await self.plugin.retrieve_knowledge(
|
||||
kb_id="kb-uuid-here",
|
||||
query_text="システムの設定方法は?",
|
||||
top_k=3,
|
||||
)
|
||||
for entry in results:
|
||||
print(entry)
|
||||
```
|
||||
|
||||
<Tip>
|
||||
これらのAPIは`query_id`を必要とせず、任意のコンポーネント(Toolコンポーネントを含む)で使用できます。現在のパイプライン設定に制限されることなく、すべてのナレッジベースにアクセスできます。
|
||||
</Tip>
|
||||
|
||||
## RAG API
|
||||
|
||||
これらのAPIは`KnowledgeEngine`コンポーネントがLangBotホストの埋め込みモデル、ベクトルデータベース、ファイルストレージにアクセスするために使用できます。アクセス方法:
|
||||
|
||||
@@ -14,7 +14,23 @@ GitHubの認証ページにリダイレクトされますので、プロンプ
|
||||
|
||||
## CLIを使用してLangBot Spaceにログイン
|
||||
|
||||
任意のディレクトリでコマンド`lbp login`を実行します:
|
||||
### 方法1:個人アクセストークンを使用(推奨)
|
||||
|
||||
1. [LangBot Space](https://space.langbot.app)にログインし、アバターをクリックして**アカウント設定**を開き、**アカウント**タブの**個人アクセストークン**で新しいトークンを作成します。
|
||||
2. 生成されたトークンをコピーし(一度しか表示されません)、ターミナルで以下を実行します:
|
||||
|
||||
```bash
|
||||
➜ HelloPlugin > lbp login --token lbpat_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
|
||||
==================================================
|
||||
✅ 個人アクセストークンでログインしました!
|
||||
トークンの保存先:~/.langbot/cli/config.json
|
||||
==================================================
|
||||
```
|
||||
|
||||
### 方法2:デバイスコード認証を使用
|
||||
|
||||
任意のディレクトリでコマンド`lbp login`を実行します:
|
||||
|
||||
```bash
|
||||
➜ HelloPlugin > lbp login
|
||||
@@ -44,11 +60,11 @@ Expires in: 21600 seconds
|
||||
==================================================
|
||||
```
|
||||
|
||||
ログインが成功したら、CLIを使用してプラグインをアップロードできます。
|
||||
どちらの方法でもログインが成功したら、CLIを使用してプラグインをアップロードできます。
|
||||
|
||||
## プラグインのアップロード
|
||||
|
||||
プラグインディレクトリで`lbp publish`を実行してください:
|
||||
プラグインディレクトリで`lbp publish`を実行してください:
|
||||
|
||||
```bash
|
||||
➜ HelloPlugin > lbp publish
|
||||
@@ -64,4 +80,4 @@ Plugin built successfully: dist/tmp/RockChinQ-HelloPlugin-0.1.0.lbpkg
|
||||
|
||||
<img width="600" src="/images/zh/plugin/dev/plugin_submission.png" />
|
||||
|
||||
ご質問がある場合は、`[email protected]`にメールを送信するか、[コミュニティ](/en/insight/community)を通じてお問い合わせください。
|
||||
ご質問がある場合は、`[email protected]`にメールを送信するか、[コミュニティ](/ja/insight/community)を通じてお問い合わせください。
|
||||
|
||||
@@ -105,43 +105,6 @@ knowledge_bases = await event_context.list_pipeline_knowledge_bases()
|
||||
|
||||
仅返回当前请求对应流水线在 `Local Agent` 配置中绑定的知识库。若当前流水线未配置知识库,或未使用 `Local Agent`,则返回空列表。
|
||||
|
||||
### 检索当前流水线内的知识库
|
||||
|
||||
在当前请求所属流水线允许访问的知识库范围内执行检索。
|
||||
|
||||
```python
|
||||
async def retrieve_knowledge(
|
||||
self,
|
||||
kb_id: str,
|
||||
query_text: str,
|
||||
top_k: int = 5,
|
||||
filters: dict[str, Any] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Retrieve relevant documents from a knowledge base"""
|
||||
|
||||
# 调用示例
|
||||
knowledge_bases = await event_context.list_pipeline_knowledge_bases()
|
||||
results = await event_context.retrieve_knowledge(
|
||||
kb_id=knowledge_bases[0]["uuid"],
|
||||
query_text="如何配置企业知识库?",
|
||||
top_k=3,
|
||||
filters={"document_type": {"$eq": "manual"}},
|
||||
)
|
||||
|
||||
# 返回示例
|
||||
[
|
||||
{
|
||||
"id": "chunk_0",
|
||||
"content": [{"type": "text", "text": "知识库配置说明"}],
|
||||
"metadata": {"document_id": "doc_001"},
|
||||
"distance": 0.12,
|
||||
"score": 0.88,
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
`kb_id` 必须来自 `list_pipeline_knowledge_bases` 的返回结果,且必须属于当前流水线已配置的知识库,否则 LangBot 会返回错误。
|
||||
|
||||
## LangBot API
|
||||
|
||||
这些 API 可在插件任何组件中调用。访问方式如下:
|
||||
@@ -382,6 +345,69 @@ file_bytes = await self.plugin.get_config_file("key")
|
||||
|
||||
请结合 [``file 或 array[file] 类型配置项``](/zh/plugin/dev/basic-info.html#type-file)使用。
|
||||
|
||||
## 知识库 API
|
||||
|
||||
这些 API 可在任意组件中通过 `self.plugin` 访问,用于列出和检索 LangBot 实例中的所有知识库,不受流水线配置限制。
|
||||
|
||||
### 列出所有知识库
|
||||
|
||||
列出 LangBot 实例中所有可用的知识库。
|
||||
|
||||
```python
|
||||
async def list_knowledge_bases(self) -> list[dict[str, Any]]:
|
||||
"""列出所有知识库
|
||||
|
||||
Returns:
|
||||
知识库列表,每个元素包含:
|
||||
- uuid: 知识库 UUID
|
||||
- name: 知识库名称
|
||||
- description: 知识库描述
|
||||
"""
|
||||
|
||||
# 调用示例
|
||||
knowledge_bases = await self.plugin.list_knowledge_bases()
|
||||
for kb in knowledge_bases:
|
||||
print(f"KB: {kb['name']} ({kb['uuid']})")
|
||||
```
|
||||
|
||||
### 检索知识库
|
||||
|
||||
从任意知识库中检索相关文档。
|
||||
|
||||
```python
|
||||
async def retrieve_knowledge(
|
||||
self,
|
||||
kb_id: str,
|
||||
query_text: str,
|
||||
top_k: int = 5,
|
||||
filters: dict[str, Any] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""从知识库中检索
|
||||
|
||||
Args:
|
||||
kb_id: 知识库 UUID(从 list_knowledge_bases 获取)
|
||||
query_text: 检索查询文本
|
||||
top_k: 返回结果数量(默认:5)
|
||||
filters: 可选的元数据过滤条件
|
||||
|
||||
Returns:
|
||||
检索结果条目列表
|
||||
"""
|
||||
|
||||
# 调用示例
|
||||
results = await self.plugin.retrieve_knowledge(
|
||||
kb_id="kb-uuid-here",
|
||||
query_text="如何配置系统?",
|
||||
top_k=3,
|
||||
)
|
||||
for entry in results:
|
||||
print(entry)
|
||||
```
|
||||
|
||||
<Tip>
|
||||
这些 API 不需要 `query_id`,可以在任何组件中使用(包括 Tool 组件),且可以访问所有知识库,不受当前流水线配置限制。
|
||||
</Tip>
|
||||
|
||||
## RAG API
|
||||
|
||||
这些 API 供 `KnowledgeEngine` 组件调用,用于访问 LangBot 宿主的嵌入模型、向量数据库和文件存储。访问方式:
|
||||
|
||||
@@ -14,6 +14,22 @@ LangBot Space 是 LangBot 提供中心化服务平台。请访问[LangBot Space]
|
||||
|
||||
## 使用 CLI 登录 LangBot Space
|
||||
|
||||
### 方式一:使用个人访问令牌(推荐)
|
||||
|
||||
1. 登录 [LangBot Space](https://space.langbot.app),点击头像进入 **账户设置**,在 **账户** 标签页中找到 **个人访问令牌**,创建一个新的令牌。
|
||||
2. 复制生成的令牌(仅显示一次),在终端执行:
|
||||
|
||||
```bash
|
||||
➜ HelloPlugin > lbp login --token lbpat_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
|
||||
==================================================
|
||||
✅ 使用个人访问令牌登录成功!
|
||||
令牌已保存至:~/.langbot/cli/config.json
|
||||
==================================================
|
||||
```
|
||||
|
||||
### 方式二:使用设备码验证
|
||||
|
||||
在任意目录执行命令`lbp login`:
|
||||
|
||||
```bash
|
||||
@@ -44,7 +60,7 @@ Expires in: 21600 seconds
|
||||
==================================================
|
||||
```
|
||||
|
||||
登录成功后,您可以继续使用 CLI 上传插件。
|
||||
两种方式登录成功后,均可继续使用 CLI 上传插件。
|
||||
|
||||
## 上传插件
|
||||
|
||||
|
||||
Reference in New Issue
Block a user