免费POC, 零成本试错
AI知识库

AI知识库

学习大模型的前沿技术与行业落地应用


收藏

部署dify集成chatglm3搭建本地知识库调通

发布日期:2024-04-25 11:47:19 浏览次数: 6707
作者:忽如一夜娇妹来

微信搜一搜,关注“忽如一夜娇妹来”

部署dify集成chatglm3搭建本地知识库调通

dify 搭建:

项目地址:https://github.com/langgenius/dify

先拉取他的代码,因为docker目录下面有对应的配置,git clone 或者下载zip然后解压都行,看自己

1.进入到对应的docker目录

2.直接使用命令即可,没有image,会自动pull

 docker compose up -d

需要修改yaml文件看下面即可

docker compose 文件

原文件地址:https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml

注意:

除了db 自带的端口映射:5434:5432

其他的使用的db的端口都是5432 ,使用的docker的网络172xxxx:5432

而不是对应的宿主机的ip:5434

例如:

下面的文件就是,我只改了db的端口,因为我本地已经有了一个pgsql了5432已经被占用了

还有一个就是nginx的端口,我是不可能给他80的。懂得都懂。需要修改。我的是10888

此时就涉及到后面他生成的url地址:这里需要修改成你实际的地址或者域名。不然就是默认的http://ip,因为默认它是80端口

主要注意的是如果修改db的端口,不需要修改调用db的端口5432,因为走的docker的网络,而不是宿主机的。

然后nginx端口改了的话,需要修改url,或者域名,不然你自动跳转chat url不会对,你自己测试手动改url也能访问,不方便。(仅限测试可)

 version: '3.1'
 services:
   # API service
 api:
   image: langgenius/dify-api:0.3.32
   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: ''
       # 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 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: 'http://192.168.1.104:10888'
       # 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: 'http://192.168.1.104:10888'
       # 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`, 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 type of vector store to use. Supported values are `weaviate`, `qdrant`, `milvus`.
     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
       # 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: ''
       # 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
   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.3.32
   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`, Default: `local`
     STORAGE_TYPE: local
     STORAGE_LOCAL_PATH: storage
       # The type of vector store to use. Supported values are `weaviate`, `qdrant`, `milvus`.
     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
       # 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: ''
   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.3.32
   restart: always
   environment:
     EDITION: SELF_HOSTED
       # 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
   ports:
     - "5434: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"
 
   # 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:latest
   #   restart: always
   #   volumes:
   #     - ./volumes/qdrant:/qdrant/storage
   #   environment:
   #     QDRANT__API_KEY: 'difyai123456'
   #   # uncomment to expose qdrant port to host
   #   # ports:
   #   #- "6333:6333"
 
   # The nginx reverse proxy.
   # used for reverse proxying the API service and Web service.
 nginx:
   image: nginx:latest
   volumes:
     - ./nginx/nginx.conf:/etc/nginx/nginx.conf
     - ./nginx/proxy.conf:/etc/nginx/proxy.conf
     - ./nginx/conf.d:/etc/nginx/conf.d
   depends_on:
     - api
     - web
   ports:
     - "10888:80"
 


dify使用

1.容器都运行成功之后,

After running, you can access the Dify dashboard in your browser at http://localhost/install and start the initialization installation process.

访问http://localhost/install,然后初始化一切。设置管理员账号密码。然后登陆即可。这里我已经完整了。没法截图了,只有登录界面了


2.点击右上角头像,进入设置界面,首先需要设置你的模型

往下面拉,找到chatglm

填入你自己搭建的chatglm3的apiurl,我的是http://192.168.1.105:18000(如何搭建chatglm3 api 看我之前的博客)

点击创建应用,名字自己随便起,选择对话型应用。然后点击创建即可

下面的预览就是ai对话,请求你的配置的模型的api地址。

重点在于提示词编排和上下文的设置,修改完毕之后,每次记得点击发布


这里的上下文在数据集里面上传 ,点击创建数据集

上传你的文本,支持的格式如图。后面看这个样子是会支持你的web站点内容,这个我还是蛮期待的。

由于我是本地搭建的chatglm3,数据是在自己本地的,很安全。
然后不能选择高质量,是因为openai的openai的api带对应的embedding分片api,chatglm3是不带的,点击保存并处理即可

点击前往文档即可看见你的文档的状态。

回到构建应用你之前创建的应用,添加上下文即可


这个是我们的chatglm3的日志,可以看到没有命中知识库,


这个命中了知识库,这个是我的txt文档里面的内容。ui界面我忘记截图了


总的来说,这个还挺好用的,我现在只做环境搭建,还没深入研究和使用。这个想使用的好,文本分片的长度其实蛮重要的。

缺点或者说我的期望:由于像我这种文档大多是markdown的,带图片的,这个应该是无法识别图片的。我们的各种环境搭建教程。包括博客。大量的图片。后续如果支持图片估计很好。


这个能很方便的接入你的系统,因为给出了api,很方便集成。同时也很好嵌入你的各个网站。


嵌入代码

 <script>
  window.difyChatbotConfig = {
   token: 'T8OIDYX15C9wG3kQ',
   baseUrl: 'http://192.168.1.104:10888'
  }
 </script>
 <script
  src="http://192.168.1.104:10888/embed.min.js"
  id="T8OIDYX15C9wG3kQ"
  defer>
 </script>

如图:很容易嵌入到自己的博客或者其他的网站。如果那个同步自己的网站内容开发完成,这个等于自动同步你的博客知识。直接ai对话即可查询使用你写的博客






53AI,企业落地大模型首选服务商

产品:场景落地咨询+大模型应用平台+行业解决方案

承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业

联系我们

售前咨询
186 6662 7370
预约演示
185 8882 0121

微信扫码

添加专属顾问

回到顶部

加载中...

扫码咨询

扫码登录
登录即表示您同意《53AI网站服务协议》
服务协议

欢迎您使用【53AI 官方网站】(以下简称“本网站”或“我们”)。本《会员服务协议》(以下简称“本协议”)是您(以下简称“会员”或“用户”)与【深圳市博思协创网络科技有限公司】之间关于注册、登录及使用本网站会员服务所订立的法律协议。

在您注册或登录前,请务必审慎阅读、充分理解各条款内容,特别是免除或限制责任的条款、知识产权条款、争议解决条款等。此类条款将以加粗形式提示您注意。 当您通过微信公众号授权、手机验证码验证或其他方式成功登录本网站时,即视为您已完全理解并同意接受本协议的全部内容。

一、 定义

本网站:指由【深圳市博思协创网络科技有限公司】运营的,域名为【53ai.com】的网站及相关移动端页面。

会员服务:指本网站向注册会员提供的知识库文章查阅、内容检索及其他相关增值服务。

知识库内容:指本网站发布的包括但不限于文字、图表、数据、研究报告、行业分析等数字化内容资源。

二、 账号注册与登录

登录方式:本网站支持以下登录方式,您可根据实际情况选择:

微信公众号授权登录:您同意将您的微信OpenID信息授权给本网站,用于创建或关联会员账号。

手机验证码登录:您需提供真实有效的手机号码,并通过短信验证码完成身份验证与登录/注册。

账号安全:您的账号仅限您本人使用,禁止赠与、借用、租用、转让或售卖。因您保管不善导致的账号被盗、密码泄露等损失,由您自行承担。

实名认证:根据相关法律法规要求,我们可能要求您在特定功能下完成实名认证。如您拒绝提供,可能无法使用部分或全部服务。

未成年人保护:若您未满18周岁,请在法定监护人的陪同下阅读本协议,并在征得监护人同意后使用本服务。

三、 服务内容与规范

知识库查阅权限:会员登录后,有权按照其会员等级对应的权限范围,在线浏览、检索本网站知识库中的相关文章及内容。

服务变更:我们有权根据业务发展需要,调整、变更或终止部分服务内容,并将以网站公告、公众号消息等方式提前通知。

禁止行为:您在使用服务时不得实施以下行为:

利用技术手段批量爬取、下载、转存知识库内容;

将知识库内容用于商业目的或未经授权地向第三方传播;

干扰本网站正常运行或侵犯其他用户合法权益;

发布违法违规信息或从事违反公序良俗的活动。

四、 知识产权声明

权利归属:本网站知识库中的排版设计、软件代码等内容的知识产权均归【公司全称】或原权利人所有,受《中华人民共和国著作权法》等法律保护。

有限许可:本网站授予会员一项非独占、不可转让、不可转授权的普通许可,仅限于个人学习、研究之目的在线查阅知识库内容。

侵权追责:未经书面许可,任何单位或个人不得以任何形式复制、转载、摘编、镜像、汇编或以其他方式使用上述内容。一经发现,我们保留追究其法律责任的权利。

五、 个人信息保护

我们重视对您个人信息的保护。关于我们如何收集、使用、存储和保护您的个人信息,请单独阅读 《隐私政策》。

您通过微信公众号授权或手机号验证所提供的信息,我们将严格按照《个人信息保护法》的规定处理,仅用于身份识别、服务提供及安全验证等必要用途。

您可以随时通过网站设置或联系客服行使查阅、更正、删除个人信息及撤回授权同意的权利。

六、 免责声明

内容准确性:知识库内容仅供参考,不构成专业建议。我们不对其完整性、准确性、时效性作任何明示或暗示的保证,您应自行判断并承担使用风险。

不可抗力:因自然灾害、政策法规变化、网络故障、第三方平台接口异常(如微信接口维护、运营商短信通道故障)等不可抗力导致的服务中断或延迟,我们不承担违约责任。

第三方链接:本网站可能包含指向第三方网站的链接,该等网站的内容和服务不受我们控制,请您自行甄别风险。

七、 违约责任

如您违反本协议约定,我们有权视情节采取警告、限制功能、暂停服务、注销账号等措施,并保留要求赔偿损失的权利。

如因您的违约行为导致我们遭受行政处罚、第三方索赔或商誉损失,您应承担全部赔偿责任(包括但不限于罚款、赔偿金、律师费、公证费等)。

八、 法律适用与争议解决

本协议的订立、执行和解释均适用中华人民共和国大陆地区法律。

因本协议产生的或与本协议有关的任何争议,双方应友好协商解决;协商不成的,任何一方均可向【公司所在地】有管辖权的人民法院提起诉讼。

九、 其他

本协议构成双方就本服务达成的完整协议,取代此前任何口头或书面约定。

本协议任一条款被认定为无效或不可执行的,不影响其他条款的效力。

我们对本协议享有最终解释权,并在法律允许的范围内保留随时修改的权利。修改后的协议一经公布即生效,继续使用服务即视为同意修订内容。


已查阅