mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
parent
048bc4c06e
commit
541bf1db5a
|
@ -2,6 +2,7 @@
|
|||
- bing
|
||||
- duckduckgo
|
||||
- searchapi
|
||||
- serper
|
||||
- searxng
|
||||
- dalle
|
||||
- azuredalle
|
||||
|
|
12
api/core/tools/provider/builtin/serper/_assets/icon.svg
Normal file
12
api/core/tools/provider/builtin/serper/_assets/icon.svg
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="128px" height="128px" viewBox="0 0 128 128" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>serper</title>
|
||||
<g id="ai-doc-check-2.0" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="画板" fill="#90CDF4" fill-rule="nonzero">
|
||||
<g id="serper">
|
||||
<path d="M65.2785371,32.0482743 C68.7012571,32.0482743 71.9303314,32.6286629 74.9661257,33.7892571 C78.0315429,34.9500343 80.7100343,36.5571657 83.0017829,38.6106514 C85.2935314,40.66432 87.0345143,43.0453029 88.2249143,45.7536 C88.4928,46.3488 88.6268343,46.9589943 88.6268343,47.584 C88.6268343,48.8042057 88.1802971,49.8607543 87.2875886,50.7536457 C86.42432,51.6167314 85.3827657,52.0482743 84.16256,52.0482743 C83.3589029,52.0482743 82.5554286,51.7952 81.7517714,51.2892343 C80.9482971,50.7536457 80.38272,50.1136457 80.0554057,49.3696 C78.9244343,46.8101486 77.0346057,44.7714743 74.3857371,43.2535771 C71.7666743,41.73568 68.73088,40.9768229 65.2785371,40.9768229 C63.5821714,40.9768229 61.7815771,41.1850971 59.8767543,41.6018286 C58.0017371,42.0183771 56.2309486,42.6583771 54.5642057,43.5214629 C52.8976457,44.3547429 51.5434057,45.4112914 50.5018514,46.6911086 C49.4601143,47.9707429 48.9393371,49.4590171 48.9393371,51.1553829 C48.9393371,52.5244343 49.3856914,53.7148343 50.2785829,54.7267657 C51.1714743,55.7088914 52.1684114,56.4827429 53.2695771,57.0481371 C55.8590171,58.3279543 58.71616,59.2208457 61.8410057,59.7268114 C64.99584,60.2327771 68.1802971,60.7237486 71.39456,61.2000914 C74.6090057,61.6762514 77.6,62.5095314 80.3679086,63.6999314 C82.1238857,64.4439771 83.80544,65.4709029 85.4125714,66.7803429 C87.0197029,68.0899657 88.3291429,69.6821029 89.3410743,71.55712 C90.3530057,73.4321371 90.8589714,75.6344686 90.8589714,78.1642971 C90.8589714,81.4381714 90.0703086,84.3101257 88.4928,86.7803429 C86.9154743,89.25056 84.8469943,91.3042286 82.2875429,92.9409829 C79.7279086,94.57792 76.9451886,95.81312 73.9392,96.6464 C70.9630171,97.4500571 68.0464457,97.8517943 65.1893029,97.8517943 C61.3202286,97.8517943 57.6892343,97.2416 54.2965029,96.0213943 C50.9035886,94.7713829 47.9422171,93.0154057 45.4125714,90.7536457 C42.8827429,88.4618971 40.9482971,85.7834057 39.6088686,82.7178057 C39.3409829,82.1226057 39.2071314,81.5274057 39.2071314,80.9322057 C39.2071314,79.7118171 39.6386743,78.6702629 40.50176,77.8071771 C41.3946514,76.9142857 42.4512,76.4679314 43.6714057,76.4679314 C44.5046857,76.4679314 45.3231543,76.7356343 46.1268114,77.2714057 C46.9302857,77.7773714 47.4808686,78.4171886 47.77856,79.19104 C49.0881829,82.1970286 51.3053257,84.5780114 54.4303543,86.3339886 C57.5553829,88.06016 61.1415771,88.9232457 65.1893029,88.9232457 C67.7191314,88.9232457 70.2637714,88.5511314 72.8232229,87.8070857 C75.3826743,87.0334171 77.5255771,85.8578286 79.2517486,84.28032 C81.0077257,82.6731886 81.8856229,80.6345143 81.8856229,78.1642971 C81.8856229,76.5869714 81.3500343,75.2923429 80.2784914,74.2804114 C79.2369371,73.2386743 78.0911543,72.4500114 76.8411429,71.91424 C74.0136229,70.6940343 70.9928229,69.8607543 67.77856,69.4142171 C64.5642971,68.9380571 61.3648457,68.4470857 58.1803886,67.94112 C54.9957486,67.4053486 52.0195657,66.4380343 49.25184,65.03936 C46.9006629,63.8487771 44.75776,62.1226057 42.8231314,59.8606629 C40.9184914,57.5690971 39.9659886,54.6673371 39.9659886,51.1553829 C39.9659886,48.06016 40.7100343,45.3368686 42.1981257,42.9856914 C43.7160229,40.6047086 45.71008,38.6106514 48.1802971,37.00352 C50.68032,35.3665829 53.4184229,34.1315657 56.3946057,33.2982857 C59.3707886,32.4648229 62.33216,32.0482743 65.2785371,32.0482743 Z" id="路径"></path>
|
||||
<path d="M64,0 C99.3462239,0 128,28.6537761 128,64 C128,99.3462239 99.3462239,128 64,128 C28.6537761,128 0,99.3462239 0,64 C0,28.6537761 28.6537761,0 64,0 Z M64,10.9714286 C34.7131288,10.9714286 10.9714286,34.7131288 10.9714286,64 C10.9714286,93.2868712 34.7131288,117.028571 64,117.028571 C93.2868712,117.028571 117.028571,93.2868712 117.028571,64 C117.028571,34.7131288 93.2868712,10.9714286 64,10.9714286 Z" id="椭圆形"></path>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.1 KiB |
23
api/core/tools/provider/builtin/serper/serper.py
Normal file
23
api/core/tools/provider/builtin/serper/serper.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from typing import Any
|
||||
|
||||
from core.tools.errors import ToolProviderCredentialValidationError
|
||||
from core.tools.provider.builtin.serper.tools.serper_search import SerperSearchTool
|
||||
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
|
||||
|
||||
|
||||
class SerperProvider(BuiltinToolProviderController):
|
||||
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
|
||||
try:
|
||||
SerperSearchTool().fork_tool_runtime(
|
||||
runtime={
|
||||
"credentials": credentials,
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_parameters={
|
||||
"query": "test",
|
||||
"result_type": "link"
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
raise ToolProviderCredentialValidationError(str(e))
|
31
api/core/tools/provider/builtin/serper/serper.yaml
Normal file
31
api/core/tools/provider/builtin/serper/serper.yaml
Normal file
|
@ -0,0 +1,31 @@
|
|||
identity:
|
||||
author: zhuhao
|
||||
name: serper
|
||||
label:
|
||||
en_US: Serper
|
||||
zh_Hans: Serper
|
||||
pt_BR: Serper
|
||||
description:
|
||||
en_US: Serper is a powerful real-time search engine tool API that provides structured data from Google Search.
|
||||
zh_Hans: Serper 是一个强大的实时搜索引擎工具API,可提供来自 Google 搜索引擎搜索的结构化数据。
|
||||
pt_BR: Serper is a powerful real-time search engine tool API that provides structured data from Google Search.
|
||||
icon: icon.svg
|
||||
tags:
|
||||
- search
|
||||
credentials_for_provider:
|
||||
serperapi_api_key:
|
||||
type: secret-input
|
||||
required: true
|
||||
label:
|
||||
en_US: Serper API key
|
||||
zh_Hans: Serper API key
|
||||
pt_BR: Serper API key
|
||||
placeholder:
|
||||
en_US: Please input your Serper API key
|
||||
zh_Hans: 请输入你的 Serper API key
|
||||
pt_BR: Please input your Serper API key
|
||||
help:
|
||||
en_US: Get your Serper API key from Serper
|
||||
zh_Hans: 从 Serper 获取您的 Serper API key
|
||||
pt_BR: Get your Serper API key from Serper
|
||||
url: https://serper.dev/api-key
|
|
@ -0,0 +1,44 @@
|
|||
from typing import Any, Union
|
||||
|
||||
import requests
|
||||
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
|
||||
SERPER_API_URL = "https://google.serper.dev/search"
|
||||
|
||||
|
||||
class SerperSearchTool(BuiltinTool):
|
||||
|
||||
def _parse_response(self, response: dict) -> dict:
|
||||
result = {}
|
||||
if "knowledgeGraph" in response:
|
||||
result["title"] = response["knowledgeGraph"].get("title", "")
|
||||
result["description"] = response["knowledgeGraph"].get("description", "")
|
||||
if "organic" in response:
|
||||
result["organic"] = [
|
||||
{
|
||||
"title": item.get("title", ""),
|
||||
"link": item.get("link", ""),
|
||||
"snippet": item.get("snippet", "")
|
||||
}
|
||||
for item in response["organic"]
|
||||
]
|
||||
return result
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_parameters: dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
params = {
|
||||
"q": tool_parameters['query'],
|
||||
"gl": "us",
|
||||
"hl": "en"
|
||||
}
|
||||
headers = {
|
||||
'X-API-KEY': self.runtime.credentials['serperapi_api_key'],
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.get(url=SERPER_API_URL, params=params,headers=headers)
|
||||
response.raise_for_status()
|
||||
valuable_res = self._parse_response(response.json())
|
||||
return self.create_json_message(valuable_res)
|
|
@ -0,0 +1,27 @@
|
|||
identity:
|
||||
name: serper
|
||||
author: zhuhao
|
||||
label:
|
||||
en_US: Serper
|
||||
zh_Hans: Serper
|
||||
pt_BR: Serper
|
||||
description:
|
||||
human:
|
||||
en_US: A tool for performing a Google search and extracting snippets and webpages.Input should be a search query.
|
||||
zh_Hans: 一个用于执行 Google 搜索并提取片段和网页的工具。输入应该是一个搜索查询。
|
||||
pt_BR: A tool for performing a Google search and extracting snippets and webpages.Input should be a search query.
|
||||
llm: A tool for performing a Google search and extracting snippets and webpages.Input should be a search query.
|
||||
parameters:
|
||||
- name: query
|
||||
type: string
|
||||
required: true
|
||||
label:
|
||||
en_US: Query string
|
||||
zh_Hans: 查询语句
|
||||
pt_BR: Query string
|
||||
human_description:
|
||||
en_US: used for searching
|
||||
zh_Hans: 用于搜索网页内容
|
||||
pt_BR: used for searching
|
||||
llm_description: key words for searching
|
||||
form: llm
|
Loading…
Reference in New Issue
Block a user