当前位置: 代码网 > it编程>编程语言>Asp.net > AI智能体研发之路-工程篇(二):Dify智能体开发平台一键部署

AI智能体研发之路-工程篇(二):Dify智能体开发平台一键部署

2024年07月31日 Asp.net 我要评论
本文首先结合自己的工作写了一些对Agent AI智能体的见解,接着介绍了Dify框架快捷部署的过程,最后阐述了Dify框架的特点。个人认为Dify的发展会让Agent AI智能体开发提效,涌现更多有趣有价值的AI应用。

博客导读:

《ai—工程篇》

ai智能体研发之路-工程篇(一):docker助力ai智能体开发提效​​​​​​​

ai智能体研发之路-工程篇(二):dify智能体开发平台一键部署

ai智能体研发之路-工程篇(三):大模型推理服务框架ollama一键部署

ai智能体研发之路-工程篇(四):大模型推理服务框架xinference一键部署

ai智能体研发之路-工程篇(五):大模型推理服务框架localai一键部署

《ai—模型篇》

ai智能体研发之路-模型篇(一):大模型训练框架llama-factory在国内网络环境下的安装、部署及使用

ai智能体研发之路-模型篇(二):deepseek-v2-chat 训练与推理实战

目录

1.引言

2.docker compose一行命令部署dify

3.dify主要特色 

3.1多种大语言模型集成

3.2丰富工具内置+自定义工具支持​

3.3工作流​

3.4agent 编排​

 4.总结


1.引言

先分享dify项目的github:https://github.com/langgenius/dify

“项目由前腾讯云devops团队成员创建。我们发现基于openai的api开发gpt应用程序有些麻烦。凭借我们多年在开发者效率工具方面的研发经验,我们希望能够让更多的人使用自然语言开发有趣的应用程序。”

dify由10+全职团队和100+社区贡献者共同维护,迭代非常快,我下载的时候还是0.6.3,现在已经升级为0.6.6,基本上每周都会升级一个版本。

我认为,了解dify以及其中依赖的上下游技术、架构,利用dify快速建立ai智能体demo原型,其实对推进ai智能体开发是有意义的。今天我先简要介绍一下dify的部署过程,后面的篇幅会具体分享基于dify的ai智能体开发经验,以及ai智能体开发所依赖的底层技术。

2.docker compose一行命令部署dify

首先将dify项目下载至服务器上,

git clone https://github.com/langgenius/dify.git

项目主要分为api(后端)和web(前端)两大部分,具体代码后面再分析,进入docker目录

cd docker

目录中包含几个文件,docker-compose.yaml可以通过docker compose直接启动所有服务和依赖,docker-compose.middleware.yaml可以先启动依赖的关系数据库、向量数据库等组件,再单独启动api和web端,隔离做得可以说太棒了。

先看一下docker-compose.yaml的源码

version: '3'
services:
  # api service
  api:
    image: langgenius/dify-api:0.6.6
    restart: always
    environment:
      # startup mode, 'api' starts the api server.
      mode: api
      # the log level for the application. supported values are `debug`, `info`, `warning`, `error`, `critical`
      log_level: info
      # a secret key that is used for securely signing the session cookie and encrypting sensitive information on the database. you can generate a strong key using `openssl rand -base64 42`.
      secret_key: sk-9f73s3ljtxvcmt3blb3ljtqtskighxvcmt3blbkfjlk7u
      # the base url of console application web frontend, refers to the console base url of web service if console domain is
      # different from api or web app domain.
      # example: http://cloud.dify.ai
      console_web_url: ''
      # password for admin user initialization.
      # if left unset, admin user will not be prompted for a password when creating the initial admin account.
      init_password: ''
      # the base url of console application api server, refers to the console base url of web service if console domain is
      # different from api or web app domain.
      # example: http://cloud.dify.ai
      console_api_url: ''
      # the url prefix for service api endpoints, refers to the base url of the current api service if api domain is
      # different from console domain.
      # example: http://api.dify.ai
      service_api_url: ''
      # the url prefix for web app frontend, refers to the web app base url of web service if web app domain is different from
      # console or api domain.
      # example: http://udify.app
      app_web_url: ''
      # file preview or download url prefix.
      # used to display file preview or download url to the front-end or as multi-model inputs;
      # url is signed and has expiration time.
      files_url: ''
      # when enabled, migrations will be executed prior to application startup and the application will start after the migrations have completed.
      migration_enabled: 'true'
      # the configurations of postgres database connection.
      # it is consistent with the configuration in the 'db' service below.
      db_username: postgres
      db_password: difyai123456
      db_host: db
      db_port: 5432
      db_database: dify
      # the configurations of redis connection.
      # it is consistent with the configuration in the 'redis' service below.
      redis_host: redis
      redis_port: 6379
      redis_username: ''
      redis_password: difyai123456
      redis_use_ssl: 'false'
      # use redis db 0 for redis cache
      redis_db: 0
      # the configurations of celery broker.
      # use redis as the broker, and redis db 1 for celery broker.
      celery_broker_url: redis://:difyai123456@redis:6379/1
      # specifies the allowed origins for cross-origin requests to the web api, e.g. https://dify.app or * for all origins.
      web_api_cors_allow_origins: '*'
      # specifies the allowed origins for cross-origin requests to the console api, e.g. https://cloud.dify.ai or * for all origins.
      console_cors_allow_origins: '*'
      # csrf cookie settings
      # controls whether a cookie is sent with cross-site requests,
      # providing some protection against cross-site request forgery attacks
      #
      # default: `samesite=lax, secure=false, httponly=true`
      # this default configuration supports same-origin requests using either http or https,
      # but does not support cross-origin requests. it is suitable for local debugging purposes.
      #
      # if you want to enable cross-origin support,
      # you must use the https protocol and set the configuration to `samesite=none, secure=true, httponly=true`.
      #
      # the type of storage to use for storing user files. supported values are `local` and `s3` and `azure-blob` and `google-storage`, default: `local`
      storage_type: local
      # the path to the local storage directory, the directory relative the root path of api service codes or absolute path. default: `storage` or `/home/john/storage`.
      # only available when storage_type is `local`.
      storage_local_path: storage
      # the s3 storage configurations, only available when storage_type is `s3`.
      s3_endpoint: 'https://xxx.r2.cloudflarestorage.com'
      s3_bucket_name: 'difyai'
      s3_access_key: 'ak-difyai'
      s3_secret_key: 'sk-difyai'
      s3_region: 'us-east-1'
      # the azure blob storage configurations, only available when storage_type is `azure-blob`.
      azure_blob_account_name: 'difyai'
      azure_blob_account_key: 'difyai'
      azure_blob_container_name: 'difyai-container'
      azure_blob_account_url: 'https://<your_account_name>.blob.core.windows.net'
      # the google storage configurations, only available when storage_type is `google-storage`.
      google_storage_bucket_name: 'yout-bucket-name'
      google_storage_service_account_json_base64: 'your-google-service-account-json-base64-string'
      # the type of vector store to use. supported values are `weaviate`, `qdrant`, `milvus`, `relyt`.
      vector_store: weaviate
      # the weaviate endpoint url. only available when vector_store is `weaviate`.
      weaviate_endpoint: http://weaviate:8080
      # the weaviate api key.
      weaviate_api_key: wvf5ythahlkywhgusmcrgsx3td5ngdn8pkih
      # the qdrant endpoint url. only available when vector_store is `qdrant`.
      qdrant_url: http://qdrant:6333
      # the qdrant api key.
      qdrant_api_key: difyai123456
      # the qdrant client timeout setting.
      qdrant_client_timeout: 20
      # the qdrant client enable grpc mode.
      qdrant_grpc_enabled: 'false'
      # the qdrant server grpc mode port.
      qdrant_grpc_port: 6334
      # milvus configuration only available when vector_store is `milvus`.
      # the milvus host.
      milvus_host: 127.0.0.1
      # the milvus host.
      milvus_port: 19530
      # the milvus username.
      milvus_user: root
      # the milvus password.
      milvus_password: milvus
      # the milvus tls switch.
      milvus_secure: 'false'
      # relyt configurations
      relyt_host: db
      relyt_port: 5432
      relyt_user: postgres
      relyt_password: difyai123456
      relyt_database: postgres
      # mail configuration, support: resend, smtp
      mail_type: ''
      # default send from email address, if not specified
      mail_default_send_from: 'your email from (eg: no-reply <no-reply@dify.ai>)'
      smtp_server: ''
      smtp_port: 587
      smtp_username: ''
      smtp_password: ''
      smtp_use_tls: 'true'
      # the api-key for resend (https://resend.com)
      resend_api_key: ''
      resend_api_url: https://api.resend.com
      # the dsn for sentry error reporting. if not set, sentry error reporting will be disabled.
      sentry_dsn: ''
      # the sample rate for sentry events. default: `1.0`
      sentry_traces_sample_rate: 1.0
      # the sample rate for sentry profiles. default: `1.0`
      sentry_profiles_sample_rate: 1.0
      # notion import configuration, support public and internal
      notion_integration_type: public
      notion_client_secret: you-client-secret
      notion_client_id: you-client-id
      notion_internal_secret: you-internal-secret
      # the sandbox service endpoint.
      code_execution_endpoint: "http://sandbox:8194"
      code_execution_api_key: dify-sandbox
      code_max_number: 9223372036854775807
      code_min_number: -9223372036854775808
      code_max_string_length: 80000
      template_transform_max_length: 80000
      code_max_string_array_length: 30
      code_max_object_array_length: 30
      code_max_number_array_length: 1000
    depends_on:
      - db
      - redis
    volumes:
      # mount the storage directory to the container, for storing user files.
      - ./volumes/app/storage:/app/api/storage
    # uncomment to expose dify-api port to host
    # ports:
    #   - "5001:5001"

  # worker service
  # the celery worker for processing the queue.
  worker:
    image: langgenius/dify-api:0.6.6
    restart: always
    environment:
      # startup mode, 'worker' starts the celery worker for processing the queue.
      mode: worker

      # --- all the configurations below are the same as those in the 'api' service. ---

      # the log level for the application. supported values are `debug`, `info`, `warning`, `error`, `critical`
      log_level: info
      # a secret key that is used for securely signing the session cookie and encrypting sensitive information on the database. you can generate a strong key using `openssl rand -base64 42`.
      # same as the api service
      secret_key: sk-9f73s3ljtxvcmt3blb3ljtqtskighxvcmt3blbkfjlk7u
      # the configurations of postgres database connection.
      # it is consistent with the configuration in the 'db' service below.
      db_username: postgres
      db_password: difyai123456
      db_host: db
      db_port: 5432
      db_database: dify
      # the configurations of redis cache connection.
      redis_host: redis
      redis_port: 6379
      redis_username: ''
      redis_password: difyai123456
      redis_db: 0
      redis_use_ssl: 'false'
      # the configurations of celery broker.
      celery_broker_url: redis://:difyai123456@redis:6379/1
      # the type of storage to use for storing user files. supported values are `local` and `s3` and `azure-blob`, default: `local`
      storage_type: local
      storage_local_path: storage
      # the s3 storage configurations, only available when storage_type is `s3`.
      s3_endpoint: 'https://xxx.r2.cloudflarestorage.com'
      s3_bucket_name: 'difyai'
      s3_access_key: 'ak-difyai'
      s3_secret_key: 'sk-difyai'
      s3_region: 'us-east-1'
      # the azure blob storage configurations, only available when storage_type is `azure-blob`.
      azure_blob_account_name: 'difyai'
      azure_blob_account_key: 'difyai'
      azure_blob_container_name: 'difyai-container'
      azure_blob_account_url: 'https://<your_account_name>.blob.core.windows.net'
      # the type of vector store to use. supported values are `weaviate`, `qdrant`, `milvus`, `relyt`.
      vector_store: weaviate
      # the weaviate endpoint url. only available when vector_store is `weaviate`.
      weaviate_endpoint: http://weaviate:8080
      # the weaviate api key.
      weaviate_api_key: wvf5ythahlkywhgusmcrgsx3td5ngdn8pkih
      # the qdrant endpoint url. only available when vector_store is `qdrant`.
      qdrant_url: http://qdrant:6333
      # the qdrant api key.
      qdrant_api_key: difyai123456
      # the qdrant clinet timeout setting.
      qdrant_client_timeout: 20
      # the qdrant client enable grpc mode.
      qdrant_grpc_enabled: 'false'
      # the qdrant server grpc mode port.
      qdrant_grpc_port: 6334
      # milvus configuration only available when vector_store is `milvus`.
      # the milvus host.
      milvus_host: 127.0.0.1
      # the milvus host.
      milvus_port: 19530
      # the milvus username.
      milvus_user: root
      # the milvus password.
      milvus_password: milvus
      # the milvus tls switch.
      milvus_secure: 'false'
      # mail configuration, support: resend
      mail_type: ''
      # default send from email address, if not specified
      mail_default_send_from: 'your email from (eg: no-reply <no-reply@dify.ai>)'
      # the api-key for resend (https://resend.com)
      resend_api_key: ''
      resend_api_url: https://api.resend.com
      # relyt configurations
      relyt_host: db
      relyt_port: 5432
      relyt_user: postgres
      relyt_password: difyai123456
      relyt_database: postgres
      # notion import configuration, support public and internal
      notion_integration_type: public
      notion_client_secret: you-client-secret
      notion_client_id: you-client-id
      notion_internal_secret: you-internal-secret
    depends_on:
      - db
      - redis
    volumes:
      # mount the storage directory to the container, for storing user files.
      - ./volumes/app/storage:/app/api/storage

  # frontend web application.
  web:
    image: langgenius/dify-web:0.6.6
    restart: always
    environment:
      # the base url of console application api server, refers to the console base url of web service if console domain is
      # different from api or web app domain.
      # example: http://cloud.dify.ai
      console_api_url: ''
      # the url for web app api server, refers to the web app base url of web service if web app domain is different from
      # console or api domain.
      # example: http://udify.app
      app_api_url: ''
      # the dsn for sentry error reporting. if not set, sentry error reporting will be disabled.
      sentry_dsn: ''
    # uncomment to expose dify-web port to host
    # ports:
    #   - "3000:3000"

  # the postgres database.
  db:
    image: postgres:15-alpine
    restart: always
    environment:
      pguser: postgres
      # the password for the default postgres user.
      postgres_password: difyai123456
      # the name of the default postgres database.
      postgres_db: dify
      # postgres data directory
      pgdata: /var/lib/postgresql/data/pgdata
    volumes:
      - ./volumes/db/data:/var/lib/postgresql/data
    # uncomment to expose db(postgresql) port to host
    # ports:
    #   - "5432:5432"
    healthcheck:
      test: [ "cmd", "pg_isready" ]
      interval: 1s
      timeout: 3s
      retries: 30

  # the redis cache.
  redis:
    image: redis:6-alpine
    restart: always
    volumes:
      # mount the redis data directory to the container.
      - ./volumes/redis/data:/data
    # set the redis password when startup redis server.
    command: redis-server --requirepass difyai123456
    healthcheck:
      test: [ "cmd", "redis-cli", "ping" ]
    # uncomment to expose redis port to host
    # ports:
    #   - "6379:6379"

  # the weaviate vector store.
  weaviate:
    image: semitechnologies/weaviate:1.19.0
    restart: always
    volumes:
      # mount the weaviate data directory to the container.
      - ./volumes/weaviate:/var/lib/weaviate
    environment:
      # the weaviate configurations
      # you can refer to the [weaviate](https://weaviate.io/developers/weaviate/config-refs/env-vars) documentation for more information.
      query_defaults_limit: 25
      authentication_anonymous_access_enabled: 'false'
      persistence_data_path: '/var/lib/weaviate'
      default_vectorizer_module: 'none'
      cluster_hostname: 'node1'
      authentication_apikey_enabled: 'true'
      authentication_apikey_allowed_keys: 'wvf5ythahlkywhgusmcrgsx3td5ngdn8pkih'
      authentication_apikey_users: 'hello@dify.ai'
      authorization_adminlist_enabled: 'true'
      authorization_adminlist_users: 'hello@dify.ai'
    # uncomment to expose weaviate port to host
    # ports:
    #  - "8080:8080"

  # the difysandbox
  sandbox:
    image: langgenius/dify-sandbox:0.1.0
    restart: always
    cap_add:
    # why is sys_admin permission needed?
    # https://docs.dify.ai/getting-started/install-self-hosted/install-faq#id-16.-why-is-sys_admin-permission-needed
      - sys_admin
    environment:
      # the difysandbox configurations
      api_key: dify-sandbox
      gin_mode: release
      worker_timeout: 15

  # qdrant vector store.
  # uncomment to use qdrant as vector store.
  # (if uncommented, you need to comment out the weaviate service above,
  # and set vector_store to qdrant in the api & worker service.)
  # qdrant:
  #   image: langgenius/qdrant:v1.7.3
  #   restart: always
  #   volumes:
  #     - ./volumes/qdrant:/qdrant/storage
  #   environment:
  #     qdrant_api_key: 'difyai123456'
  #   # uncomment to expose qdrant port to host
  #   # ports:
  #   #  - "6333:6333"
  #   #  - "6334:6334"

  # the nginx reverse proxy.
  # used for reverse proxying the api service and web service.
  nginx:
    image: nginx:latest
    restart: always
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/proxy.conf:/etc/nginx/proxy.conf
      - ./nginx/conf.d:/etc/nginx/conf.d
      #- ./nginx/ssl:/etc/ssl
    depends_on:
      - api
      - web
    ports:
      - "80:80"
      #- "443:443"

主要包含如下几个模块及docker镜像

  • api:langgenius/dify-api:0.6.6
  • worker:langgenius/dify-api:0.6.6
  • web:langgenius/dify-web:0.6.6
  • db:postgres:15-alpine
  • redis:redis:6-alpine
  • weaviate:semitechnologies/weaviate:1.19.0
  • sandbox:langgenius/dify-sandbox:0.1.0
  • nginx:nginx:latest

docker compose一键部署安装

docker compose up -d

从dockerhub逐个pulling依赖镜像,感觉还挺爽的

等待镜像下载部署完成后,打开webui:123.123.123.123:80,默认占用80端口,可以在docker compose配置文件中更改nignx端口。

经过账号初始化等工作后,欢迎来到dify工作界面,就是这么丝滑

3.dify主要特色 

3.1多种大语言模型集成

相较于fastgpt+oneapi的方案,集成度更高:

  • 大模型厂商模型:仅需到大模型厂商注册账号,申请鉴权apikey,即可快速体验比较每个大模型厂商的优劣,项目还贴心的附带了每个厂商的注册跳转链接,每个厂商基本都会给几百万的token用于测试。
  • 本地部署模型:支持xinference,ollama,openllm,localai等推理框架部署的模型一键接入
  • ​huggingface开源模型:只需配置apikey和模型名字即可接入,不过要求服务器能翻墙噢
  • openai-api-compatible:接入兼容openai规范的api,目前xinference,openllm等很多推理框架,都是直接支持openai api接口规范的,但对于每家大模型厂商,一般都要设计自己的规范,可能是想构建生态,或者是与众不同?这里多说一下:对于国内互联网中小厂,如果不自建大模型,可能要试用或买入多加公司的大模型,多加大模型给多个业务部门使用,就要有一个代理平台专门计算成本,这个平台最好对业务暴露的是兼容openai的api接口,如果不是的话,当接入dify平台时,就需要包一层与openai兼容的api接口。

3.2丰富工具内置+自定义工具支持

 dify内置了包含搜索引擎、天气预报、维基百科、sd等工具,同时自定义工具的配置化接入,团队成员一人接入,全组复用,高效!

3.3工作流

 只需连接各个节点,既能在几分钟内快速完成ai智能体创作,且逻辑非常清晰。

3.4agent 编排

编写提示词,导入知识库,添加工具,选择模型,运行测试,发布为api,一条龙创作! 

还有很多特色,在此不再赘述了,附上一张官方的表格吧

 4.总结

临下班了,本来只是想参加个话题活动,洋洋洒洒几千字。可能加入了太多感慨吧。希望感兴趣的朋友可以关注我、点赞、收藏和评论,您的鼓励是我持续码字的动力。

本文首先结合自己的工作写了一些对agent ai智能体的见解,接着介绍了dify框架快捷部署的过程,最后阐述了dify框架的特点。个人认为dify的发展会让agent ai智能体开发提效,涌现更多有趣有价值的ai应用。

最后,写一下我对未来ai智能体发展的看法吧,从流量与用户来看,2000年-2004年,以新浪、搜狐、网易为代表的门户网站是流量入口,2004年-2014年,以百度为代表的搜索引擎是流量入口,2014-2024,以抖音、快手、微博、小红书为代表的移动互联网推荐系统是流量入口,抓住了流量入口就抓住了用户,抓住了用户就抓住了商业变现。2024-未来,极大的可能出现一家基于ai的平台型企业,通过ai智能体抓住流量,比如你要去哪玩,ai智能体在为你做出规划的过程中,夹杂酒店、航班的广告私货,你想吃什么,ai智能体夹杂着饭店的广告私货。

ai领域,乾坤未定,你我皆是黑马。

如果对ai感兴趣,可以接着看看我的其他文章:

《ai—工程篇》

ai智能体研发之路-工程篇(一):docker助力ai智能体开发提效​​​​​​​

ai智能体研发之路-工程篇(二):dify智能体开发平台一键部署

ai智能体研发之路-工程篇(三):大模型推理服务框架ollama一键部署

ai智能体研发之路-工程篇(四):大模型推理服务框架xinference一键部署

ai智能体研发之路-工程篇(五):大模型推理服务框架localai一键部署

《ai—模型篇》

ai智能体研发之路-模型篇(一):大模型训练框架llama-factory在国内网络环境下的安装、部署及使用

ai智能体研发之路-模型篇(二):deepseek-v2-chat 训练与推理实战

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com