Tutorial Dify: chatbot com IA no seu site

Aproveite e me siga no Instagram https://instagram.com/leonardoamoyr

Meu agradecimento especial ao mathuzabr do canal Pack TypeBot

O que é Dify?

Dify.ai é uma plataforma voltada para a criação de aplicações impulsionadas por inteligência artificial, como chatbots e assistentes virtuais. Ela oferece uma interface simples que permite aos usuários integrarem IA em seus projetos sem necessidade de habilidades avançadas de programação. Além disso, o Dify.ai facilita o uso de modelos de linguagem natural, como os desenvolvidos pela OpenAI, para melhorar interações automatizadas com usuários, promovendo soluções rápidas e eficientes para empresas e desenvolvedores.

Fazer os apontamentos no Zone DNS do tipo A para o IP da sua VPS:

  • appdify (backend)
  • apidify (api) dify (frontend)
  • portainer
  • www.portainer
  • traefik
  • www.traefik
  • edge
  • www.edge

Para criar sua senha htpasswd clique aqui:

https://packtypebot.com.br/gerador/htpasswd.php

sudo apt update && sudo apt install -y git && git clone https://github.com/mathuzabr/portainer-packtypebot.git && cd portainer-packtypebot && sudo chmod +x install.sh && ./install.sh

Antes de criar a stack no Portainer, crie uma network chamada “Dify” e atribua no Traefik, conforme eu ensino no vídeo.

Código da stack do Dify para copiar e colar no Portainer:

version: '3.1'
services:
  api:
    image: langgenius/dify-api:latest
    restart: always
    environment:
      OPENBLAS_NUM_THREADS: 1
      MODE: api
      LOG_LEVEL: INFO
      SECRET_KEY: # https://leonardoamoyr.com/gerador-de-api-key/
      INIT_PASSWORD: 'senhainicial123456'
      CONSOLE_WEB_URL: 'https://appdify.seusite.com'
      CONSOLE_API_URL: 'https://appdify.seusite.com'
      SERVICE_API_URL: 'https://apidify.seusite.com'
      APP_WEB_URL: 'https://dify.seusite.com'
      FILES_URL: ''
      MIGRATION_ENABLED: 'true'
      DB_USERNAME: postgres
      DB_PASSWORD: senhainicial123456
      DB_HOST: db
      DB_PORT: 5432
      DB_DATABASE: dify
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_USERNAME: ''
      REDIS_PASSWORD: senhainicial123456
      REDIS_USE_SSL: 'false'
      REDIS_DB: 0
      CELERY_BROKER_URL: redis://:senhainicial123456@redis:6379/1
      WEB_API_CORS_ALLOW_ORIGINS: '*'
      CONSOLE_CORS_ALLOW_ORIGINS: '*'
      STORAGE_TYPE: local
      STORAGE_LOCAL_PATH: storage
      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'
      VECTOR_STORE: qdrant
      QDRANT_URL: http://qdrant:6333
      QDRANT_API_KEY: senhainicial123456
      QDRANT_CLIENT_TIMEOUT: 20
      MILVUS_HOST: 127.0.0.1
      MILVUS_PORT: 19530
      MILVUS_USER: root
      MILVUS_PASSWORD: Milvus
      MILVUS_SECURE: 'false'
      MAIL_TYPE: 'smtp'
      MAIL_DEFAULT_SEND_FROM: 'smtp@seusite.com'
      SMTP_SERVER: 'smtp.hostinger.com'
      SMTP_PORT: '465'
      SMTP_USERNAME: 'smtp@seusite.com'
      SMTP_PASSWORD: 'senhasmtp'
      SENTRY_DSN: ''
      SENTRY_TRACES_SAMPLE_RATE: 1.0
      SENTRY_PROFILES_SAMPLE_RATE: 1.0
    depends_on:
      - db
      - redis
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=dify"
      - "traefik.http.routers.dify-api.rule=Host(`appdify.seusite.com`)"
      - "traefik.http.routers.dify-api.tls.certresolver=leresolver"
      - "traefik.http.routers.dify-api.entrypoints=web,websecure"
      - "traefik.http.routers.dify-api.tls=true"
      - "traefik.http.routers.dify-api.service=dify-api"
      - "traefik.http.services.dify-api.loadbalancer.server.port=5001"
      - "traefik.http.routers.dify-web.rule=Host(`apidify.seusite.com`)"
      - "traefik.http.routers.dify-web.tls.certresolver=leresolver"
      - "traefik.http.routers.dify-web.entrypoints=web,websecure"
      - "traefik.http.routers.dify-web.tls=true"
      - "traefik.http.routers.dify-web.service=dify-web"
      - "traefik.http.services.dify-web.loadbalancer.server.port=5001"

  worker:
    image: langgenius/dify-api:latest
    restart: always
    environment:
      MODE: worker
      LOG_LEVEL: INFO
      SECRET_KEY: # https://leonardoamoyr.com/gerador-de-api-key/
      DB_USERNAME: postgres
      DB_PASSWORD: senhainicial123456
      DB_HOST: db
      DB_PORT: 5432
      DB_DATABASE: dify
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_USERNAME: ''
      REDIS_PASSWORD: senhainicial123456
      REDIS_DB: 0
      REDIS_USE_SSL: 'false'
      CELERY_BROKER_URL: redis://:senhainicial123456@redis:6379/1
      STORAGE_TYPE: local
      STORAGE_LOCAL_PATH: storage
      VECTOR_STORE: qdrant
      QDRANT_URL: http://qdrant:6333
      QDRANT_API_KEY: senhainicial123456
      QDRANT_CLIENT_TIMEOUT: 20
      MILVUS_HOST: 127.0.0.1
      MILVUS_PORT: 19530
      MILVUS_USER: root
      MILVUS_PASSWORD: Milvus
      MILVUS_SECURE: 'false'
      MAIL_TYPE: 'smtp'
      MAIL_DEFAULT_SEND_FROM: 'smtp@seusite.com'
      SMTP_SERVER: 'smtp.hostinger.com'
      SMTP_PORT: '465'
      SMTP_USERNAME: 'smtp@seusite.com'
      SMTP_PASSWORD: 'senhasmtp'
    depends_on:
      - db
      - redis
    volumes:
      - ./volumes/app/storage:/app/api/storage

  web:
    image: langgenius/dify-web:latest
    restart: always
    ports:
      - 3000:3000
    environment:
      EDITION: SELF_HOSTED
      CONSOLE_API_URL: 'https://appdify.seusite.com'
      APP_API_URL: 'https://dify.seusite.com'
      SENTRY_DSN: ''
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=dify"
      - "traefik.http.routers.dify-u.rule=Host(`dify.seusite.com`)"
      - "traefik.http.routers.dify-u.tls.certresolver=leresolver"
      - "traefik.http.routers.dify-u.entrypoints=web,websecure"
      - "traefik.http.routers.dify-u.tls=true"
      - "traefik.http.routers.dify-u.service=dify-u"
      - "traefik.http.services.dify-u.loadbalancer.server.port=3000"
      - "traefik.http.routers.dify-uapi.rule=Host(`dify.seusite.com`) && PathPrefix(`/api`)"
      - "traefik.http.routers.dify-uapi.tls.certresolver=leresolver"
      - "traefik.http.routers.dify-uapi.entrypoints=web,websecure"
      - "traefik.http.routers.dify-uapi.tls=true"
      - "traefik.http.routers.dify-uapi.service=dify-api"
      - "traefik.http.services.dify-uapi.loadbalancer.server.port=5001"
      
  db:
    image: postgres:15-alpine
    restart: always
    environment:
      PGUSER: postgres
      POSTGRES_PASSWORD: senhainicial123456
      POSTGRES_DB: dify
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - ./volumes/db/data:/var/lib/postgresql/data
    healthcheck:
      test: [ "CMD", "pg_isready" ]
      interval: 1s
      timeout: 3s
      retries: 30

  sandbox:
    image: langgenius/dify-sandbox:latest
    restart: always
    environment:
      API_KEY: fu89389oiasdj0983r33
      GIN_MODE: release
      WORKER_TIMEOUT: 15
      ENABLE_NETWORK: true
      SANDBOX_PORT: 8194
    volumes:
      - ./volumes/dify_sandbox:/dependencies
    labels:
      - "traefik.enable=false"    

  redis:
    image: redis:6-alpine
    restart: always
    volumes:
      - ./volumes/redis/data:/data
    command: redis-server --requirepass senhainicial123456
    healthcheck:
      test: [ "CMD", "redis-cli", "ping" ]
      
  weaviate:
    image: semitechnologies/weaviate:latest
    restart: always
    volumes:
      - ./volumes/weaviate:/var/lib/weaviate
    environment:
      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: 'smtp@seusite.com'
      AUTHORIZATION_ADMINLIST_ENABLED: 'true'
      AUTHORIZATION_ADMINLIST_USERS: 'smtp@seusite.com'

networks:
  default:
    name: dify
    external: true

Crie sua conta na OpenAI aqui: https://platform.openai.com/

Depois de criar sua conta, faça uma recarga de 5 dólares e crie sua chave API Key para conectar com a Dify. Crie seu atendimento humanizado com ChatGPT e seja feliz =)

Obrigado por sua audiência!

plugins premium WordPress
Rolar para cima