From 0143ea7998dc9111d33596e9e0240d587b2533b6 Mon Sep 17 00:00:00 2001 From: Sebastjan Prachovskij Date: Mon, 10 Jun 2024 19:43:58 +0300 Subject: [PATCH] Add SearchApi tutorial --- en/tutorials/tool-configuration/README.md | 1 + en/tutorials/tool-configuration/searchapi.md | 33 +++++++++++++++++++ .../guides/tools/tool-configuration/README.md | 3 +- .../tools/tool-configuration/searchapi.md | 33 +++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 en/tutorials/tool-configuration/searchapi.md create mode 100644 zh_CN/guides/tools/tool-configuration/searchapi.md diff --git a/en/tutorials/tool-configuration/README.md b/en/tutorials/tool-configuration/README.md index e2e897e3..415da674 100644 --- a/en/tutorials/tool-configuration/README.md +++ b/en/tutorials/tool-configuration/README.md @@ -11,3 +11,4 @@ Dify supports various tools to enhance your application's capabilities. Each too - [StableDiffusion](./stable-diffusion.md): A tool for generating images based on text prompts. - [SearXNG](./searxng.md): A free internet metasearch engine which aggregates results from various search services and databases. +- [SearchApi](./searchapi.md): A tool which extracts organic results from Google, Google News, Google Jobs, or YouTube video Transcripts. diff --git a/en/tutorials/tool-configuration/searchapi.md b/en/tutorials/tool-configuration/searchapi.md new file mode 100644 index 00000000..4eb2bbab --- /dev/null +++ b/en/tutorials/tool-configuration/searchapi.md @@ -0,0 +1,33 @@ +# SearchApi +SearchApi is a real-time SERP API that provides structured data from a variety of search engines, including Google Search, Google Shopping, Google Jobs, YouTube, Amazon, and more. + +## 1. Retrieve SearchApi API Key +Sign up for a free account at [searchapi.io](https://www.searchapi.io/) to get your API key. + +## 2. Use Google Search, Google News, Google Jobs, or YouTube Transcripts Tool +- Google Search, Google News, Google Jobs: These engines require a search query. +- YouTube Transcripts Tool: This tool requires a `video_id`. + +The SearchAPI class allows you to query these tools and process the results. + +### For Google searches, the results can include: + +For `result_type=text`: +- `answer_box` (fields: `answer`, `snippet`) +- `knowledge_graph` (field: `description`) +- `organic_results` (fields: `snippet`, `link`) + +For `result_type=link`: +- `answer_box` (field: `organic_result` with subfields `title`, `link`) +- `organic_results` (fields: `title`, `link`) +- `related_questions` (fields: `title`, `link`) +- `related_searches` (fields: `title`, `link`) + +## Integrating a New SearchApi Engine +To integrate a new engine into SearchApi, follow these steps: + +1. Copy the existing tool code. +2. Modify the `get_params` request parameters to suit the new engine. +3. Adjust `_process_response` to handle and return the response according to your needs. + +By following these instructions, you can easily expand the functionality of the SearchApi to include new search engines and customize how the data is processed and returned. diff --git a/zh_CN/guides/tools/tool-configuration/README.md b/zh_CN/guides/tools/tool-configuration/README.md index 1c8c5bac..6e67ce6d 100644 --- a/zh_CN/guides/tools/tool-configuration/README.md +++ b/zh_CN/guides/tools/tool-configuration/README.md @@ -9,4 +9,5 @@ Dify 支持各种工具来增强应用的功能。每个工具都有独特的功 ## 工具集成指南 - [StableDiffusion](./stable-diffusion.md):一种基于文本提示生成图像的工具。 -- [SearXNG](./searxng.md):一个免费的互联网元搜索引擎,整合了各种搜索服务的结果。用户不会被跟踪,也不会被分析。 \ No newline at end of file +- [SearXNG](./searxng.md):一个免费的互联网元搜索引擎,整合了各种搜索服务的结果。用户不会被跟踪,也不会被分析。 +- [SearchApi](./searchapi.md):一个从 Google、Google 新闻、Google 工作或 YouTube 视频字幕中提取有机结果的工具。 \ No newline at end of file diff --git a/zh_CN/guides/tools/tool-configuration/searchapi.md b/zh_CN/guides/tools/tool-configuration/searchapi.md new file mode 100644 index 00000000..e63faa5d --- /dev/null +++ b/zh_CN/guides/tools/tool-configuration/searchapi.md @@ -0,0 +1,33 @@ +# SearchApi +SearchApi 是一个实时 SERP API,提供来自多种搜索引擎的结构化数据,包括 Google 搜索、Google 购物、Google 工作、YouTube、Amazon 等。 + +## 1. 获取 SearchApi API 密钥 +在 searchapi.io 注册一个免费账户并获取 API 密钥。 + +## 2. 使用 Google 搜索、Google 新闻、Google 工作或 YouTube 字幕工具 +- Google 搜索、Google 新闻、Google 工作:这些引擎需要一个搜索查询。 +- YouTube 字幕工具:这个工具需要一个 `video_id`。 + +SearchAPI 类允许你查询这些工具并处理结果。 + +### 对于 Google 搜索,结果可以包括: + +对于 `result_type=text`: +- `answer_box`(字段:`answer`,`snippet`) +- `knowledge_graph`(字段:`description`) +- `organic_results`(字段:`snippet`,`link`) + +对于 `result_type=link`: +- answer_box(字段:`organic_result`,子字段:`title`,`link`) +- organic_results(字段:`title`,`link`) +- related_questions(字段:`title`,`link`) +- related_searches(字段:`title`,`link`) + +## 集成新的 SearchApi 引擎 +要将新引擎集成到 SearchApi 中,请按照以下步骤操作: + +1. 复制现有的工具代码。 +2. 修改 `get_params` 请求参数以适应新引擎。 +3. 调整 `_process_response` 以处理并返回根据你的需求处理的响应。 + +按照这些说明,你可以轻松扩展 SearchApi 的功能,包括新的搜索引擎,并自定义数据处理和返回的方式。