version: '3.8'

services:
  api:
    image: samepaage/open-assistant-api:main
    restart: always
    build: .
    volumes:
      - ./volumes/logs/api:/app/logs
    networks:
      - r2r-network
    ports:
      - '8086:8086'
    environment:
      # app
      MODE: api
      APP_NAME: open-assistant-api
      APP_DEBUG: true
      APP_ENV: prod

      APP_SERVER_WORKERS: 40
      APP_API_PREFIX: /api

      APP_AUTH_ENABLE: true
      APP_AUTH_ADMIN_TOKEN: cocorobo-xjw-admin

      LOG_LEVEL: DEBUG

      # celery
      CELERY_BROKER_URL: redis://:123456@redis:6379/1

      MIGRATION_ENABLED: true

      # database
      DB_HOST: db
      DB_PORT: 3306
      DB_DATABASE: open_assistant1
      DB_USER: open_assistant
      DB_PASSWORD: 123456
      DB_POOL_SIZE: 1000
      DB_POOL_RECYCLE: 3600

      # redis
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 0
      REDIS_PASSWORD: 123456

      # s3 storage
      #S3_ENDPOINT: http://minio:9000
      #S3_BUCKET_NAME: oas
      #S3_ACCESS_KEY: minioadmin
      #S3_SECRET_KEY: minioadmin
      #S3_REGION: us-east-1
      #S3_ENDPOINT: None
      S3_BUCKET_NAME: ccrb
      S3_ACCESS_KEY: AKIATLPEDU37QV5CHLMH
      S3_SECRET_KEY: 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
      S3_REGION: cn-northwest-1

      # file service
      #FILE_SERVICE_MODULE: app.services.file.impl.oss_file.OSSFileService
      FILE_SERVICE_MODULE: app.services.file.impl.r2r_file.R2RFileService
      # file search tool
      R2R_BASE_URL: http://r2r:7272
      R2R_USERNAME: xujiawei@cocorobo.cc
      R2R_PASSWORD: usestudio-1
      R2R_SEARCH_LIMIT: 10

      # secret
      APP_AES_ENCRYPTION_KEY: 7700b2f9c8dd982dfaddf8b47a92f1d900507ee8ac335f96a64e9ca0f018b195

    depends_on:
      - db
      - redis
      - minio

  worker:
    image: samepaage/open-assistant-api:main
    restart: always
    build: .
    networks:
      - r2r-network
    volumes:
      - ./volumes/logs/worker:/app/logs
    environment:
      # app
      MODE: worker
      APP_DEBUG: true
      APP_ENV: prod

      APP_AUTH_ENABLE: true
      APP_AUTH_ADMIN_TOKEN: cocorobo-xjw-admin

      LOG_LEVEL: DEBUG

      # celery
      CELERY_BROKER_URL: redis://:123456@redis:6379/1
      CELERY_WORKERS: 50

      # database
      DB_HOST: db
      DB_PORT: 3306
      DB_DATABASE: open_assistant1
      DB_USER: open_assistant
      DB_PASSWORD: 123456
      DB_POOL_SIZE: 1000
      DB_POOL_RECYCLE: 3600

      # redis
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 0
      REDIS_PASSWORD: 123456

      # s3 storage
      #S3_ENDPOINT: http://minio:9000
      #S3_BUCKET_NAME: oas
      #S3_ACCESS_KEY: minioadmin
      #S3_SECRET_KEY: minioadmin
      #S3_REGION: us-east-1
      #S3_ENDPOINT: None
      S3_BUCKET_NAME: ccrb
      S3_ACCESS_KEY: AKIATLPEDU37QV5CHLMH
      S3_SECRET_KEY: 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
      S3_REGION: cn-northwest-1

      # llm
      OPENAI_API_BASE: http://172.16.12.13:3000/v1
      OPENAI_API_KEY: sk-vTqeBKDC2j6osbGt89A2202dAd1c4fE8B1D294388b569e54
      LLM_MAX_STEP: 2

      # tool
      TOOL_WORKER_NUM: 200
      TOOL_WORKER_EXECUTION_TIMEOUT: 180

      # web search tool
      BING_SEARCH_URL: https://www.searchapi.io/api/v1/search
      BING_SUBSCRIPTION_KEY: ZYLf8VLMoW8QRJ86bXEec9rX
      WEB_SEARCH_NUM_RESULTS: 50

      # file service
      #FILE_SERVICE_MODULE: app.services.file.impl.oss_file.OSSFileService
      FILE_SERVICE_MODULE: app.services.file.impl.r2r_file.R2RFileService

      # file search tool
      R2R_BASE_URL: http://r2r:7272
      R2R_USERNAME: xujiawei@cocorobo.cc
      R2R_PASSWORD: usestudio-1
      R2R_SEARCH_LIMIT: 10 # secret
      APP_AES_ENCRYPTION_KEY: 7700b2f9c8dd982dfaddf8b47a92f1d900507ee8ac335f96a64e9ca0f018b195

    depends_on:
      - db
      - redis
      - minio

  playground-ui:
    image: samepaage/open-assistant-playground-ui:main
    restart: always
    build:
      context: ./playground-ui
    networks:
      - r2r-network
    ports:
      - "8090:80"
    depends_on:
      - api

  db:
    image: mysql:5.7.44
    platform: linux/x86_64
    restart: always
    volumes:
      - ./volumes/mysql/data:/var/lib/mysql
    networks:
      - r2r-network
    ports:
      - '3307:3306'
    environment:
      MYSQL_ROOT_PASSWORD: 'open-assistant-api@2023'
      MYSQL_USER: open_assistant
      MYSQL_PASSWORD: '123456'
      MYSQL_DATABASE: open_assistant1
      # TZ: Asia/Shanghai
    command: [ 'mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ]
    healthcheck:
      test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
      timeout: 20s
      retries: 10

  redis:
    image: redis:6-alpine
    platform: linux/x86_64
    restart: always
    networks:
      - r2r-network
    volumes:
      - ./volumes/redis/data:/data
    ports:
      - '6379:6379'
    command: redis-server --requirepass 123456
    healthcheck:
      test: [ "CMD", "redis-cli", "ping" ]

  minio:
    image: minio/minio:RELEASE.2023-03-20T20-16-18Z
    platform: linux/x86_64
    restart: always
    volumes:
      - ./volumes/minio/data:/minio_data
    networks:
      - r2r-network
    ports:
      - '9001:9001'
      - '9000:9000'
    environment:
      MINIO_ACCESS_KEY: minioadmin
      MINIO_SECRET_KEY: minioadmin
    command: minio server /minio_data --console-address ':9001'
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:9000/minio/health/live" ]
      interval: 30s
      timeout: 20s
      retries: 3

  create-buckets:
    image: minio/mc
    platform: linux/x86_64
    environment:
      MINIO_ACCESS_KEY: minioadmin
      MINIO_SECRET_KEY: minioadmin
      BUCKET_NAME: 'oas'
    depends_on:
      - minio
    entrypoint: >
      /bin/sh -c " /usr/bin/mc alias set minio http://minio:9000 $${MINIO_ACCESS_KEY} $${MINIO_SECRET_KEY}; /usr/bin/mc mb -p minio/$${BUCKET_NAME}; exit 0; "
networks:
  r2r-network:
    external: true
