Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jina reader #3468

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/core/tools/provider/_position.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- pubmed
- stablediffusion
- webscraper
- jina
- model.zhipuai
- aippt
- youtube
Expand Down
4 changes: 4 additions & 0 deletions api/core/tools/provider/builtin/jina/_assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions api/core/tools/provider/builtin/jina/jina.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Any

from core.tools.errors import ToolProviderCredentialValidationError
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController


class GoogleProvider(BuiltinToolProviderController):
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
try:
pass
except Exception as e:
raise ToolProviderCredentialValidationError(str(e))
13 changes: 13 additions & 0 deletions api/core/tools/provider/builtin/jina/jina.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
identity:
author: Dify
name: jina
label:
en_US: JinaReader
zh_Hans: JinaReader
pt_BR: JinaReader
description:
en_US: Convert any URL to an LLM-friendly input. Experience improved output for your agent and RAG systems at no cost.
zh_Hans: 将任何 URL 转换为 LLM 友好的输入。无需付费即可体验为您的 Agent 和 RAG 系统提供的改进输出。
pt_BR: Converta qualquer URL em uma entrada amigável ao LLM. Experimente uma saída aprimorada para seus sistemas de agente e RAG sem custo.
icon: icon.svg
credentials_for_provider:
35 changes: 35 additions & 0 deletions api/core/tools/provider/builtin/jina/tools/jina_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from typing import Any, Union

from yarl import URL

from core.helper import ssrf_proxy
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool


class JinaReaderTool(BuiltinTool):
_jina_reader_endpoint = 'https://r.jina.ai/'

def _invoke(self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
"""
invoke tools
"""
url = tool_parameters['url']

headers = {
'Accept': 'text/event-stream'
}

response = ssrf_proxy.get(
str(URL(self._jina_reader_endpoint + url)),
headers=headers,
timeout=(10, 60)
)

if tool_parameters.get('summary', False):
return self.create_text_message(self.summary(user_id, response.text))

return self.create_text_message(response.text)
41 changes: 41 additions & 0 deletions api/core/tools/provider/builtin/jina/tools/jina_reader.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
identity:
name: jina_reader
author: Dify
label:
en_US: JinaReader
zh_Hans: JinaReader
pt_BR: JinaReader
description:
human:
en_US: Convert any URL to an LLM-friendly input. Experience improved output for your agent and RAG systems at no cost.
zh_Hans: 将任何 URL 转换为 LLM 友好的输入。无需付费即可体验为您的 Agent 和 RAG 系统提供的改进输出。
pt_BR: Converta qualquer URL em uma entrada amigável ao LLM. Experimente uma saída aprimorada para seus sistemas de agente e RAG sem custo.
llm: A tool for scraping webpages. Input should be a URL.
parameters:
- name: url
type: string
required: true
label:
en_US: URL
zh_Hans: 网页链接
pt_BR: URL
human_description:
en_US: used for linking to webpages
zh_Hans: 用于链接到网页
pt_BR: used for linking to webpages
llm_description: url for scraping
form: llm
- name: summary
type: boolean
required: false
default: false
label:
en_US: Enable summary
zh_Hans: 是否启用摘要
pt_BR: Habilitar resumo
human_description:
en_US: Enable summary for the output
zh_Hans: 为输出启用摘要
pt_BR: Habilitar resumo para a saída
llm_description: enable summary
form: form
Loading