文章目录
一、dify 配置
1.管理员账号配置
在输入http://<your_ip>
进行登陆(本地配置可以登陆 http://127.0.0.1 或者http://localhost),进行Dify的设置
默认会跳转到# 本地环境http://<your_ip>/install
页面。
2.模型配置
模型配置路径位置为:主页-设置-模型供应商
如图所示:
模型配置时,可根据具体需求进行选择Ollama 模型配置或者其他模型供应商的模型。
(1)Ollama 模型配置
在模型供应商界面选择ollama。
基础URL 为ollama 服务,默认是 http://127.0.0.1:11434。如果是remote ollama 填写http://<your_ip>:port
即可。
(2)硅基流动模型配置
硅基流动的api-key获取,需要首先在硅基流动官网 完成注册,然后在个人中心 > API 密钥 中创建 。如图所示:
二、deepseek 联网搜索配置
1.Web Search API配置
这里的Web Search API 使用博查,主要考虑方便购买API,并且价格相对bing,Serply等便宜不少。
配置时,通过创建自定义工具的方法,将BochaWebSearch设置为自定义工具,然后在工作流中接入BochaWebSearch 节点即可。
创建自定义工具的方法为在dify的工具界面,点击创建自定义工具。复制以下的shema 到 自定义工具的shema 配置下。
openapi: 3.0.3
info:
title: 博查
description: 博查是一个给AI用的中文搜索引擎,让你的AI应用从近百亿网页和生态内容源中获取高质量的世界知识,涵盖天气、新闻、百科、医疗、火车票、图片等多种领域。
version: 1.0.0
servers:
- url: https://api.bochaai.com/v1
paths:
/web-search:
post:
summary: 从博查搜索全网信息和网页链接,返回结果包括网页标题、网页URL、网页摘要、网站名称、网站图标、发布时间、图片链接等
operationId: BochaWebSearch
requestBody:
description: 请求参数
content:
application/json:
schema:
type: object
properties:
query:
type: string
description: 搜索关键字或语句
example: "阿里巴巴2024年的ESG报告"
summary:
type: boolean
description: 是否在搜索结果中包含摘要
default: true
example: true
freshness:
type: string
description: 搜索指定时间范围内的网页(可选值 "noLimit"、"oneDay"、"oneWeek"、"oneMonth"、"oneYear")
default: "noLimit"
enum:
- "noLimit"
- "oneDay"
- "oneWeek"
- "oneMonth"
- "oneYear"
example: "noLimit"
count:
type: integer
description: 返回的搜索结果数量(1-10),默认为10
default: 10
minimum: 1
maximum: 10
example: 10
required:
- query
responses:
'200':
description: 成功的搜索响应
content:
application/json:
schema:
type: object
properties:
code:
type: integer
description: 响应的状态码
example: 200
log_id:
type: string
description: 请求的唯一日志ID
example: "0d0eb34abc6eec9d"
msg:
type: string
nullable: true
description: 请求的消息提示(如果有的话)
example: null
data:
type: object
properties:
_type:
type: string
description: 搜索的类型
example: "SearchResponse"
queryContext:
type: object
properties:
originalQuery:
type: string
description: 原始的搜索关键字
example: "阿里巴巴2024年的ESG报告"
webPages:
type: object
properties:
webSearchUrl:
type: string
description: 网页搜索的URL
example: "https://bochaai.com/search?q=阿里巴巴2024年的ESG报告"
totalEstimatedMatches:
type: integer
description: 搜索匹配的网页总数
example: 1618000
value:
type: array
items:
type: object
properties:
id:
type: string
nullable: true
description: 网页的排序ID
name:
type: string
description: 网页的标题
url:
type: string
description: 网页的URL
displayUrl:
type: string
description: 网页的展示URL
snippet:
type: string
description: 网页内容的简短描述
summary:
type: string
description: 网页内容的文本摘要
siteName:
type: string
description: 网页的网站名称
siteIcon:
type: string
description: 网页的网站图标
dateLastCrawled:
type: string
format: date-time
description: 网页的收录时间或发布时间
cachedPageUrl:
type: string
nullable: true
description: 网页的缓存页面URL
language:
type: string
nullable: true
description: 网页的语言
isFamilyFriendly:
type: boolean
nullable: true
description: 是否为家庭友好的页面
isNavigational:
type: boolean
nullable: true
description: 是否为导航性页面
images:
type: object
properties:
id:
type: string
nullable: true
description: 图片搜索结果的ID
webSearchUrl:
type: string
nullable: true
description: 图片搜索的URL
value:
type: array
items:
type: object
properties:
webSearchUrl:
type: string
nullable: true
description: 图片搜索结果的URL
name:
type: string
nullable: true
description: 图片的名称
thumbnailUrl:
type: string
description: 图像缩略图的URL
example: "http://dayu-img.uc.cn/columbus/img/oc/1002/45628755e2db09ccf7e6ea3bf22ad2b0.jpg"
datePublished:
type: string
nullable: true
description: 图像的发布日期
contentUrl:
type: string
description: 访问全尺寸图像的URL
example: "http://dayu-img.uc.cn/columbus/img/oc/1002/45628755e2db09ccf7e6ea3bf22ad2b0.jpg"
hostPageUrl:
type: string
description: 图片所在网页的URL
example: "http://dayu-img.uc.cn/columbus/img/oc/1002/45628755e2db09ccf7e6ea3bf22ad2b0.jpg"
contentSize:
type: string
nullable: true
description: 图片内容的大小
encodingFormat:
type: string
nullable: true
description: 图片的编码格式
hostPageDisplayUrl:
type: string
nullable: true
description: 图片所在网页的显示URL
width:
type: integer
description: 图片的宽度
example: 553
height:
type: integer
description: 图片的高度
example: 311
thumbnail:
type: string
nullable: true
description: 图片缩略图(如果有的话)
videos:
type: object
properties:
id:
type: string
nullable: true
description: 视频搜索结果的ID
readLink:
type: string
nullable: true
description: 视频的读取链接
webSearchUrl:
type: string
nullable: true
description: 视频搜索的URL
isFamilyFriendly:
type: boolean
description: 是否为家庭友好的视频
scenario:
type: string
description: 视频的场景
value:
type: array
items:
type: object
properties:
webSearchUrl:
type: string
description: 视频搜索结果的URL
name:
type: string
description: 视频的名称
description:
type: string
description: 视频的描述
thumbnailUrl:
type: string
description: 视频的缩略图URL
publisher:
type: array
items:
type: object
properties:
name:
type: string
description: 发布者名称
creator:
type: object
properties:
name:
type: string
description: 创作者名称
contentUrl:
type: string
description: 视频内容的URL
hostPageUrl:
type: string
description: 视频所在网页的URL
encodingFormat:
type: string
description: 视频编码格式
hostPageDisplayUrl:
type: string
description: 视频所在网页的显示URL
width:
type: integer
description: 视频的宽度
height:
type: integer
description: 视频的高度
duration:
type: string
description: 视频的长度
motionThumbnailUrl:
type: string
description: 动态缩略图的URL
embedHtml:
type: string
description: 用于嵌入视频的HTML代码
allowHttpsEmbed:
type: boolean
description: 是否允许HTTPS嵌入
viewCount:
type: integer
description: 视频的观看次数
thumbnail:
type: object
properties:
height:
type: integer
description: 视频缩略图的高度
width:
type: integer
description: 视频缩略图的宽度
allowMobileEmbed:
type: boolean
description: 是否允许移动端嵌入
isSuperfresh:
type: boolean
description: 是否为最新视频
datePublished:
type: string
description: 视频的发布日期
'400':
description: 请求参数错误
'401':
description: 未授权 - API 密钥无效或缺失
'500':
description: 搜索服务内部错误
security:
- apiKeyAuth: []
/ai-search:
post:
summary: 在博查网页搜索的基础上,AI识别搜索词语义并额外返回垂直领域内容的结构化模态卡,例如天气卡、日历卡、百科卡等
operationId: BochaAISearch
requestBody:
description: 请求参数
content:
application/json:
schema:
type: object
properties:
query:
type: string
description: 搜索关键字或语句
example: "阿里巴巴2024年的ESG报告"
freshness:
type: string
description: 搜索指定时间范围内的网页(可选值 "noLimit"、"oneDay"、"oneWeek"、"oneMonth"、"oneYear")
default: "noLimit"
enum:
- "noLimit"
- "oneDay"
- "oneWeek"
- "oneMonth"
- "oneYear"
example: "noLimit"
answer:
type: boolean
description: 是否返回大模型总结的答案,参数留空则不返回
count:
type: integer
description: 返回的搜索结果数量(1-50),默认为10
default: 10
minimum: 1
maximum: 50
example: 10
required:
- query
responses:
'200':
description: 成功的搜索响应
content:
application/json:
schema:
type: object
properties:
code:
type: integer
description: 响应的状态码
example: 200
log_id:
type: string
description: 请求的唯一日志ID
example: "0d0eb34abc6eec9d"
conversation_id:
type: string
nullable: true
description: 请求的唯一会话ID
example: null
messages:
type: array
items:
type: object
properties:
role:
type: string
nullable: true
description: 消息发送者(user或assistant)
type:
type: string
description: 消息的类型(source,answer,follow_up等)
content_type:
type: string
description: 消息的模态卡类型(webpage,image,video,baike_pro,weather_china,weather_international,medical_common,medical_pro,calendar,text等)
content:
type: string
description: 消息内容(json encode后的文本)
'400':
description: 请求参数错误
'401':
description: 未授权 - API 密钥无效或缺失
'500':
description: 搜索服务内部错误
security:
- apiKeyAuth: []
components:
securitySchemes:
apiKeyAuth:
type: apiKey
in: header
name: Authorization
博查API-Key获取链接为:https://open.bochaai.com/api-keys
使用时需要充值,按最小金额充值就行。
创建完成后的结果如图所示:
2.工作流配置
这里使用导入自定义DSL文件的方式创建工作流。
DSL文件内容如下:
app:
description: 使用DeepSeek-R1+博查搜索插件,1分钟搭建一个AI搜索助手
icon: 🤖
icon_background: '#FFEAD5'
mode: advanced-chat
name: DeepSeek-R1 + 博查实现联网搜索
use_icon_as_answer_icon: false
kind: app
version: 0.1.5
workflow:
conversation_variables: []
environment_variables: []
features:
file_upload:
allowed_file_extensions:
- .JPG
- .JPEG
- .PNG
- .GIF
- .WEBP
- .SVG
allowed_file_types:
- image
allowed_file_upload_methods:
- local_file
- remote_url
enabled: false
fileUploadConfig:
audio_file_size_limit: 50
batch_count_limit: 5
file_size_limit: 15
image_file_size_limit: 10
video_file_size_limit: 100
workflow_file_upload_limit: 10
image:
enabled: false
number_limits: 3
transfer_methods:
- local_file
- remote_url
number_limits: 3
opening_statement: ''
retriever_resource:
enabled: true
sensitive_word_avoidance:
enabled: false
speech_to_text:
enabled: false
suggested_questions: []
suggested_questions_after_answer:
enabled: false
text_to_speech:
enabled: false
language: ''
voice: ''
graph:
edges:
- data:
sourceType: llm
targetType: answer
id: llm-answer
selected: false
source: llm
sourceHandle: source
target: answer
targetHandle: target
type: custom
- data:
isInIteration: false
sourceType: start
targetType: tool
id: 1740023321466-source-1740023353496-target
selected: false
source: '1740023321466'
sourceHandle: source
target: '1740023353496'
targetHandle: target
type: custom
zIndex: 0
- data:
isInIteration: false
sourceType: tool
targetType: code
id: 1740023353496-source-1740023701313-target
selected: false
source: '1740023353496'
sourceHandle: source
target: '1740023701313'
targetHandle: target
type: custom
zIndex: 0
- data:
isInIteration: false
sourceType: code
targetType: llm
id: 1740023701313-source-llm-target
selected: false
source: '1740023701313'
sourceHandle: source
target: llm
targetHandle: target
type: custom
zIndex: 0
nodes:
- data:
desc: ''
selected: false
title: 开始
type: start
variables: []
height: 54
id: '1740023321466'
position:
x: 30
y: 251.5
positionAbsolute:
x: 30
y: 251.5
selected: false
sourcePosition: right
targetPosition: left
type: custom
width: 244
- data:
context:
enabled: false
variable_selector: []
desc: ''
memory:
query_prompt_template: '{{#sys.query#}}'
role_prefix:
assistant: ''
user: ''
window:
enabled: false
size: 10
model:
completion_params:
temperature: 0.7
mode: chat
name: deepseek-ai/DeepSeek-R1
provider: siliconflow
prompt_template:
- id: bd405ae6-0133-44bc-aae9-c1789a07155b
role: system
text: '# 角色
你是一个由博查精心打造的 AI 搜索助手,能够在网络世界中精准搜索,并以中立客观、新闻式的专业语气为用户答疑解惑。
## 技能
### 技能 1: 精准回应用户问题
1. 当用户提出问题时,首先以一个单独的段落简短直接地回答核心问题,随后通过若干独立的段落详细分析问题的各个方面和细节,确保答案完整且逻辑清晰。
2. 提供的答案应具备中等到较长的篇幅,信息量满满且紧密关联,但切勿重复用户问题。
3. 结构化地拆解内容,明确表达内部的分类及逻辑关系,并以 markdown 格式提供详尽内容。
### 技能 2:在答案中适当地使用引用编号来引证上下文信息
1. 您将获得一组与该问题相关的上下文,每个上下文都以参考编号开头,例如 [[引用:x]],其中 x 是一个数字。请使用上下文进行参考作答,但无需显示引用的编号。
### 技能 3:不要盲目的重复上下文,提供扩展的见解和解释
1. 对上下文信息进行分析、综合和评价,提供更深入的见解和解释。
2. 融入你的专业知识和经验,以提供更加丰富和有深度的答案。
3. 始终保持对用户问题的敏感度和对信息准确性的追求。
## 限制
1. 禁止告知用户通过打开链接或访问网站获取答案,除非用户明确要求提供链接。
2. 必须基于上下文信息来回答问题并引用相关内容,然而无需在回应中提及上下文。
3. 只有在必要的时候,才使用无序列表、有序列表等格式。
4. 只有在必要的时候,才通过独立段落详细分析问题、总结关键点和主要信息。
'
- id: cfc616d5-b6ce-432a-8023-59b75726911d
role: user
text: '以下是上下文:
{{#1740023701313.context#}}
以下是用户问题:
{{#sys.query#}}'
retry_config:
max_retries: 3
retry_enabled: false
retry_interval: 1000
selected: false
title: LLM
type: llm
variables: []
vision:
enabled: false
height: 98
id: llm
position:
x: 942
y: 251.5
positionAbsolute:
x: 942
y: 251.5
selected: true
sourcePosition: right
targetPosition: left
type: custom
width: 244
- data:
answer: '{{#llm.text#}}'
desc: ''
selected: false
title: 直接回复
type: answer
variables: []
height: 103
id: answer
position:
x: 1244.5714285714284
y: 251.5
positionAbsolute:
x: 1244.5714285714284
y: 251.5
selected: false
sourcePosition: right
targetPosition: left
type: custom
width: 244
- data:
desc: ''
provider_id: 83b527cc-07a2-4dae-a45b-0336b7506a27
provider_name: BochaAI
provider_type: api
selected: false
title: BochaWebSearch
tool_configurations: {}
tool_label: BochaWebSearch
tool_name: BochaWebSearch
tool_parameters:
freshness:
type: mixed
value: noLimit
query:
type: mixed
value: '{{#sys.query#}}'
summary:
type: mixed
value: 'true'
type: tool
height: 54
id: '1740023353496'
position:
x: 334
y: 251.5
positionAbsolute:
x: 334
y: 251.5
selected: false
sourcePosition: right
targetPosition: left
type: custom
width: 244
- data:
code: "def main(resp: str) -> dict:\n try:\n response = json.loads(resp)\n\
\ if \"data\" in response:\n data = response[\"data\"\
]\n if \"webPages\" in data:\n webPages = data[\"\
webPages\"]\n if \"value\" in webPages:\n \
\ contexts = webPages[\"value\"]\n max_context =\
\ min(len(contexts), 10)\n format_contexts = []\n \
\ for i in range(max_context):\n \
\ formatted_context = f\"[[引用:{i + 1}]]\\n网页标题:{contexts[i]['name']}\\n网页链接:{contexts[i]['url']}\\\
n网页内容:{contexts[i]['summary']}\\发布时间:{contexts[i]['dateLastCrawled']}\\\
n网站名称:{contexts[i]['name']}\"\n format_contexts.append(formatted_context)\n\
\n context = \"\\n\\n\".join(format_contexts)\n \
\ return {\n \"context\": context\n\
\ }\n return {\n \"context\": \"暂无搜索结果\"\
\n }\n except:\n return {\n \"context\": \"\
暂无搜索结果\"\n }\n"
code_language: python3
desc: ''
outputs:
context:
children: null
type: string
selected: false
title: Result to Context
type: code
variables:
- value_selector:
- '1740023353496'
- text
variable: resp
height: 54
id: '1740023701313'
position:
x: 638
y: 251.5
positionAbsolute:
x: 638
y: 251.5
selected: false
sourcePosition: right
targetPosition: left
type: custom
width: 244
viewport:
x: 11.231986768088575
y: -37.556322882123936
zoom: 1.0339273406623841
将以上代码复制出来,新建一个.yml
后缀的文件,然后进行导入。
导入后效果如下:
需要将上图中箭头所指节点替换为第一部分新建的自定义节点。替换方式如下
BochaWebSearch 节点配置如下:
Result to Context 节点配置如下
节点配置完成后,点击运行即可。
效果如下
参考链接
https://aq6ky2b8nql.feishu.cn/wiki/XgeXwsn7oiDEC0kH6O3cUKtknSR