铁佛 发表于 2025-3-22 17:04:04

dify + BochaWebSearch 实现ollama与硅基流动deepseek的联网搜索

一、dify 设置

1.管理员账号设置

在输入http://<your_ip>进行登岸(本地设置可以登岸 http://127.0.0.1 大概http://localhost),进行Dify的设置
默认会跳转到# 本地情况http://<your_ip>/install页面。
https://i-blog.csdnimg.cn/direct/1d84ebfd59e34e5c8932bf6b5bc1c5e6.png#pic_center
2.模子设置

模子设置路径位置为:主页-设置-模子供应商
如图所示:
https://i-blog.csdnimg.cn/direct/4a65e585fb7e4c41a050c09e51b8113c.png#pic_center
https://i-blog.csdnimg.cn/direct/38113dd7aff74ceb8bed8b1320693952.png#pic_center
模子设置时,可根据详细需求进行选择Ollama 模子设置大概其他模子供应商的模子。
(1)Ollama 模子设置

在模子供应商界面选择ollama。
基础URL 为ollama 服务,默认是 http://127.0.0.1:11434。如果是remote ollama 填写http://<your_ip>:port即可。
https://i-blog.csdnimg.cn/direct/bcd99f5e9e5343ec8c07dfdb3f69ab6b.png#pic_center
(2)硅基流动模子设置

https://i-blog.csdnimg.cn/direct/b345f3619ef64ba8b5fc9fdf44019bef.png#pic_center
硅基流动的api-key获取,必要首先在硅基流动官网 完成注册,然后在个人中心 > API 密钥 中创建 。如图所示:
https://i-blog.csdnimg.cn/direct/fe71d7f7780d426ba6a766ff66c0a6fa.png#pic_center
二、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

https://i-blog.csdnimg.cn/direct/9bf625293b4843ed9c959dfed9b735e7.png#pic_center
https://i-blog.csdnimg.cn/direct/7cf6a3abc0654a2cb9e5241f44c4a5c2.png#pic_center
博查API-Key获取链接为:https://open.bochaai.com/api-keys
利用时必要充值,按最小金额充值就行。
https://i-blog.csdnimg.cn/direct/fee2b1fc29d248f08a83e94a037d808e.png#pic_center
创建完成后的效果如图所示:
https://i-blog.csdnimg.cn/direct/58c3b6becff54c4d93b060fda2dcc905.png#pic_center
2.工作流设置

这里利用导入自定义DSL文件的方式创建工作流。
https://i-blog.csdnimg.cn/direct/d54958837e764941a54833ef21212fc5.png#pic_center
DSL文件内容如下:
app:
description: 使用DeepSeek-R1+博查搜索插件,1分钟搭建一个AI搜索助手
icon:
页: [1]
查看完整版本: dify + BochaWebSearch 实现ollama与硅基流动deepseek的联网搜索