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

Add SearchApi tutorial #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 en/tutorials/tool-configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
33 changes: 33 additions & 0 deletions en/tutorials/tool-configuration/searchapi.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion zh_CN/guides/tools/tool-configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Dify 支持各种工具来增强应用的功能。每个工具都有独特的功
## 工具集成指南

- [StableDiffusion](./stable-diffusion.md):一种基于文本提示生成图像的工具。
- [SearXNG](./searxng.md):一个免费的互联网元搜索引擎,整合了各种搜索服务的结果。用户不会被跟踪,也不会被分析。
- [SearXNG](./searxng.md):一个免费的互联网元搜索引擎,整合了各种搜索服务的结果。用户不会被跟踪,也不会被分析。
- [SearchApi](./searchapi.md):一个从 Google、Google 新闻、Google 工作或 YouTube 视频字幕中提取有机结果的工具。
33 changes: 33 additions & 0 deletions zh_CN/guides/tools/tool-configuration/searchapi.md
Original file line number Diff line number Diff line change
@@ -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 的功能,包括新的搜索引擎,并自定义数据处理和返回的方式。