Skip to content

Commit 775ec6a

Browse files
authored
feat: update llamacloud (#2178)
* feat: update llamacloud * update res status code
1 parent e919ce3 commit 775ec6a

File tree

7 files changed

+191
-12
lines changed

7 files changed

+191
-12
lines changed

extensions/llamacloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## llamacloud
22

33
**Author:** langgenius
4-
**Version:** 0.0.1
4+
**Version:** 0.0.2
55
**Type:** extension
66

77
### Description

extensions/llamacloud/endpoints/llamacloud.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,35 @@ def _invoke(self, r: Request, values: Mapping, settings: Mapping) -> Response:
1010
"""
1111
Invokes the endpoint with the given request.
1212
"""
13+
if settings.get("api_key"):
14+
if r.headers.get("Authorization") != f"Bearer {settings.get("api_key")}":
15+
return Response(
16+
status=403,
17+
content_type="application/json"
18+
)
19+
if not r.is_json:
20+
# first step of dify call is to check if the endpoint is available
21+
return Response(
22+
status=200,
23+
content_type="application/json"
24+
)
25+
1326
# Parse JSON from the incoming request
1427
body = r.json
1528

1629
pipeline_id = body.get("knowledge_id")
1730
query = body.get("query")
1831

1932
# Extract retrieval settings with sensible defaults
20-
retrieval_settings = body.get("retrieval_setting")
33+
retrieval_settings = body.get("retrieval_setting", {})
2134
top_k = retrieval_settings.get("top_k")
2235
score_threshold = retrieval_settings.get("score_threshold")
2336

2437
# Set up the LlamaCloud client using the API key from settings
25-
client = LlamaCloud(token=settings.get("llama_cloud_api_key"))
38+
client_kwargs = {"token": settings.get("llama_cloud_api_key")}
39+
if settings.get("region") == "eu":
40+
client_kwargs["base_url"] = "https://api.cloud.eu.llamaindex.ai"
41+
client = LlamaCloud(**client_kwargs)
2642

2743
# Execute the run_search pipeline
2844
# (Ensure that `pipeline_id` exists in your `settings` object)

extensions/llamacloud/group/llamacloud.yaml

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,50 @@ settings:
22
- name: llama_cloud_api_key
33
type: secret-input
44
required: true
5+
label:
6+
en_US: Llama Cloud API key
7+
zh_Hans: Llama Cloud API 密钥
8+
ja_JP: Llama Cloud APIキー
9+
pt_BR: Chave de API do Llama Cloud
10+
placeholder:
11+
en_US: Please input your Llama Cloud API key
12+
zh_Hans: 请输入你的 Llama Cloud API 密钥
13+
ja_JP: Llama Cloud APIキーを入力してください
14+
pt_BR: Por favor, insira sua chave de API do Llama Cloud
15+
- name: api_key
16+
type: text-input
17+
required: false
518
label:
619
en_US: API key
7-
zh_Hans: API key
8-
pt_BR: API key
20+
zh_Hans: API 密钥
21+
ja_JP: APIキー
22+
pt_BR: Chave de API
923
placeholder:
10-
en_US: Please input your API key
11-
zh_Hans: 请输入你的 API key
12-
pt_BR: Please input your API key
24+
en_US: This API key is used to protect your endpoint from unauthorized requests.
25+
zh_Hans: 此 API 密钥用于保护你的端点免受未授权请求
26+
ja_JP: このAPIキーは、エンドポイントを不正なリクエストから保護するために使用されます
27+
pt_BR: Esta chave de API é usada para proteger seu endpoint de solicitações não autorizadas
28+
- name: region
29+
type: select
30+
required: false
31+
label:
32+
en_US: Region
33+
zh_Hans: 区域
34+
ja_JP: リージョン
35+
pt_BR: Região
36+
default: us
37+
options:
38+
- label:
39+
en_US: "Europe (EU)"
40+
zh_Hans: "欧洲 (EU)"
41+
ja_JP: "ヨーロッパ (EU)"
42+
pt_BR: "Europa (EU)"
43+
value: "eu"
44+
- label:
45+
en_US: "United States (US)"
46+
zh_Hans: "美国 (US)"
47+
ja_JP: "アメリカ (US)"
48+
pt_BR: "Estados Unidos (US)"
49+
value: "us"
1350
endpoints:
1451
- endpoints/llamacloud.yaml

extensions/llamacloud/manifest.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 0.0.1
1+
version: 0.0.2
22
type: plugin
33
author: langgenius
44
name: llamacloud
@@ -9,9 +9,9 @@ label:
99
pt_BR: Llamacloud
1010
description:
1111
en_US: LlamaCloud client as API Endpoint to connect Dify External Knowledge Base
12-
ja_JP: LlamaCloud client as API Endpoint to connect Dify External Knowledge Base
13-
zh_Hans: LlamaCloud client as API Endpoint to connect Dify External Knowledge Base
14-
pt_BR: LlamaCloud client as API Endpoint to connect Dify External Knowledge Base
12+
ja_JP: Dify外部ナレッジベースに接続するためのLlamaCloud APIエンドポイントクライアント
13+
zh_Hans: 作为API端点连接Dify外部知识库的LlamaCloud客户端
14+
pt_BR: Cliente LlamaCloud como endpoint de API para conectar à Base de Conhecimento Externa do Dify
1515
icon: icon.svg
1616
resource:
1717
memory: 268435456
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## llamacloud
2+
3+
**作成者:** langgenius
4+
**バージョン:** 0.0.2
5+
**タイプ:** 拡張機能
6+
7+
### 説明
8+
9+
LlamaCloud は、UI を備えた LlamaIndex のオンライン版です。
10+
11+
コンテキスト検索機能を持つ AI エージェントを構築しようとしており、主に Dify のナレッジベースを使用していない場合、Dify の外部ナレッジベースを使用して、お好みの RAG ソリューションに接続できます。このプラグインは、LlamaCloud インデックスをエンドポイントとしてデプロイし、Dify 外部ナレッジベースがシームレスに接続できるようにします。
12+
13+
LlamaCloud でインデックスを設定するには、**Tools: Index** セクションで Create Index をクリックします。
14+
15+
<img src="../_assets/llamacloud_index_create.png" width="600" />
16+
17+
インデックスパネルでは、データのアップロード、ベクトルストレージと埋め込みモデルの接続、解析設定の構成ができます。
18+
<img src="../_assets/llamacloud_index_panel.png" width="600" />
19+
20+
インデックスを設定すると、Pipeline ID が取得できます。
21+
<img src="../_assets/llama_cloud_pipeline_id.png" width="600" />
22+
23+
ここで API キーを生成します:
24+
<img src="../_assets/llama_cloud_api_key.png" width="600" />
25+
26+
次に、Dify のマーケットプレイスで LlamaCloud を見つけてインストールします。
27+
ここをクリックして新しいエンドポイントを作成します:
28+
<img src="../_assets/llamacloud_add_endpoint.png" width="600" />
29+
30+
エンドポイントに名前を付け、先ほど作成した API キーを貼り付けます。
31+
<img src="../_assets/name_endpoint.png" width="600" />
32+
33+
新しく作成されたエンドポイント URL をコピーし、ナレッジベースに移動し、「外部ナレッジ API」、「外部ナレッジ API を追加」を選択し、「API エンドポイント」に URL を貼り付けます。
34+
35+
**注意:URL から "/retrieval" を削除する必要があります!!!!!** API キーについては、認証を設定していないため、任意の内容を入力できます。したがって、**エンドポイント URL を誰にも知られないようにしてください!!!**
36+
<img src="../_assets/paste_url.png" width="600" />
37+
38+
外部ナレッジベースが接続されたら、「外部ナレッジベースに接続」に移動し、「ナレッジ ID」に Pipeline ID を入力し、名前を付ければ準備完了です。
39+
<img src="../_assets/type_pipeline_id.png" width="600" />
40+
41+
これで、外部ナレッジベースの検索テストを実行できます。
42+
<img src="../_assets/retrieval_testing.png" width="600" />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## llamacloud
2+
3+
**Autor:** langgenius
4+
**Versão:** 0.0.2
5+
**Tipo:** extensão
6+
7+
### Descrição
8+
9+
LlamaCloud é uma versão online do LlamaIndex com interface de usuário.
10+
11+
Se você está tentando construir um Agente de IA com capacidade de recuperação de contexto e não está usando principalmente a Base de Conhecimento do Dify, você pode usar a Base de Conhecimento Externa do Dify para se conectar com a solução RAG de sua preferência. Este plugin ajudará você a implantar seu Índice LlamaCloud como um endpoint para que a Base de Conhecimento Externa do Dify possa se conectar perfeitamente a ele.
12+
13+
Para configurar um Índice no LlamaCloud, na seção **Tools: Index**, clique em Create Index.
14+
15+
<img src="../_assets/llamacloud_index_create.png" width="600" />
16+
17+
No painel de Índice, você pode fazer upload de seus dados, conectar armazenamento de vetores e modelo de embedding, configurar as definições de análise.
18+
<img src="../_assets/llamacloud_index_panel.png" width="600" />
19+
20+
Depois de configurar seu Índice, você receberá um Pipeline ID.
21+
<img src="../_assets/llama_cloud_pipeline_id.png" width="600" />
22+
23+
Gere uma chave de API aqui:
24+
<img src="../_assets/llama_cloud_api_key.png" width="600" />
25+
26+
Agora, no marketplace do Dify, encontre LlamaCloud e instale-o.
27+
Crie um novo endpoint clicando aqui:
28+
<img src="../_assets/llamacloud_add_endpoint.png" width="600" />
29+
30+
Dê um nome ao seu endpoint e cole a chave de API que acabamos de criar.
31+
<img src="../_assets/name_endpoint.png" width="600" />
32+
33+
Copie a URL do Endpoint recém-criado, vá para Base de Conhecimento, "API de Conhecimento Externo", "Adicionar uma API de Conhecimento Externo" e cole a URL em "Endpoint de API".
34+
35+
**AVISO: Você DEVE REMOVER o "/retrieval" da sua URL!!!!!** Para a chave de API, como não configuramos nenhuma autorização, você pode digitar qualquer coisa que quiser. Portanto, **CERTIFIQUE-SE DE QUE NINGUÉM SAIBA A URL DO ENDPOINT!!!**
36+
<img src="../_assets/paste_url.png" width="600" />
37+
38+
Depois que sua base de conhecimento externa estiver conectada, vá para "conectar a uma base de conhecimento externa", digite o Pipeline ID em "ID de Conhecimento", dê um nome e pronto.
39+
<img src="../_assets/type_pipeline_id.png" width="600" />
40+
41+
Agora você pode fazer um teste de recuperação da sua Base de Conhecimento Externa.
42+
<img src="../_assets/retrieval_testing.png" width="600" />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## llamacloud
2+
3+
**作者:** langgenius
4+
**版本:** 0.0.2
5+
**类型:** 扩展
6+
7+
### 描述
8+
9+
LlamaCloud 是 LlamaIndex 的在线版本,带有用户界面。
10+
11+
如果你正在构建具有上下文检索能力的 AI Agent,并且主要不使用 Dify 的知识库,你可以使用 Dify 的外部知识库来连接你喜欢的 RAG 解决方案。此插件将帮助你将 LlamaCloud 索引部署为端点,以便 Dify 外部知识库可以无缝连接。
12+
13+
要在 LlamaCloud 中设置索引,请在 **Tools: Index** 部分点击 Create Index。
14+
15+
<img src="../_assets/llamacloud_index_create.png" width="600" />
16+
17+
在索引面板中,你可以上传数据、连接向量存储和嵌入模型、配置解析设置。
18+
<img src="../_assets/llamacloud_index_panel.png" width="600" />
19+
20+
设置好索引后,你将获得一个 Pipeline ID。
21+
<img src="../_assets/llama_cloud_pipeline_id.png" width="600" />
22+
23+
在此处生成 API 密钥:
24+
<img src="../_assets/llama_cloud_api_key.png" width="600" />
25+
26+
现在在 Dify 的市场中找到 LlamaCloud 并安装它。
27+
点击此处创建新端点:
28+
<img src="../_assets/llamacloud_add_endpoint.png" width="600" />
29+
30+
为你的端点命名,并粘贴我们刚刚创建的 API 密钥。
31+
<img src="../_assets/name_endpoint.png" width="600" />
32+
33+
复制新创建的端点 URL,进入知识库,"外部知识 API","添加外部知识 API",并将 URL 粘贴到"API 端点"中。
34+
35+
**注意:你必须删除 URL 中的 "/retrieval"!!!!!** 对于 API 密钥,由于我们没有配置任何授权,你可以输入任何内容。所以**请确保没有人知道端点 URL!!!**
36+
<img src="../_assets/paste_url.png" width="600" />
37+
38+
连接外部知识库后,进入"连接到外部知识库",在"知识 ID"中输入 Pipeline ID,为其命名,就可以开始使用了。
39+
<img src="../_assets/type_pipeline_id.png" width="600" />
40+
41+
现在你可以对外部知识库进行检索测试。
42+
<img src="../_assets/retrieval_testing.png" width="600" />

0 commit comments

Comments
 (0)