本文 2351字,需要 5.88 分钟
Rasa X 介绍
Rasa X can be used in local mode and in server mode. Rasa X in local mode is helpful for sharing your assistant before you have a server set up. Once your assistant is up and running, you will want to deploy Rasa X to a server so that it’s available 24/7 and everyone on your team can use it to review conversations and annotate new training data.
如上文所说的「Local Mode」[1]模式更多的是方便我们本地测试,如果需要提供给外界服务,我们还需要其他模式,官网提供的三种:
1.Server Quick-Install
2.Helm Chart
3.Docker Compose
因为我个人服务器用的 Docker 比较多,所以看看「Docker Compose」模式:
Docker Compose
要求服务器环境前提安装 python3
, docker
、docker-compose
。
主要四个步骤: 1. Download 2. Install 3. Start 4. Access
Download
因为 Rasa 的镜像主要放在 Docker Hub 上,所以在国内,有时候下载速度比较慢,虽然国内也提供了很多加速方法,但个人比较推荐使用使用 Google Cloud Platform 等第三方云服务器,通过云服务器和阿里云等国内服务器交互,把镜像托管回国内服务器,得到加速的目标。
具体大家可以搜索下使用方法。
本文主要下载的镜像包括:rasa/rasa-x
,rasa/duckling
,rasa/rasa
,rasa/rasa-x-demo
等。
// 加速下载 rasa-x
docker pull rasa/rasa-x:0.31.0
docker tag docker.io/rasa/rasa-x:0.31.0 registry.cn-hangzhou.aliyuncs.com/rasa/rasa-x:0.31.0
docker push registry.cn-hangzhou.aliyuncs.com/rasa/rasa-x:0.31.0
// 本地下载
docker pull registry.cn-hangzhou.aliyuncs.com/rasa/rasa-x:0.31.0
docker pull rasa/duckling:0.1.6.3
docker tag docker.io/rasa/duckling:0.1.6.3 registry.cn-hangzhou.aliyuncs.com/rasa/duckling:0.1.6.3
docker push registry.cn-hangzhou.aliyuncs.com/rasa/duckling:0.1.6.3
// 本地下载
docker pull registry.cn-hangzhou.aliyuncs.com/rasa/duckling:0.1.6.3
docker pull rasa/rasa:1.10.8-full
docker tag docker.io/rasa/rasa:1.10.8-full registry.cn-hangzhou.aliyuncs.com/rasa/rasa:1.10.8-full
docker push registry.cn-hangzhou.aliyuncs.com/rasa/rasa:1.10.8-full
// 本地下载
docker pull registry.cn-hangzhou.aliyuncs.com/rasa/rasa:1.10.8-full
docker pull rasa/nginx:0.31.0
docker tag docker.io/rasa/nginx:0.31.0 registry.cn-hangzhou.aliyuncs.com/rasa/nginx:0.31.0
docker push registry.cn-hangzhou.aliyuncs.com/rasa/nginx:0.31.0
// 本地下载
docker pull registry.cn-hangzhou.aliyuncs.com/rasa/nginx:0.31.0
docker pull rasa/rasa-x-demo:0.31.0
docker tag docker.io/rasa/rasa-x-demo:0.31.0 registry.cn-hangzhou.aliyuncs.com/rasa/rasa-x-demo:0.31.0
docker push registry.cn-hangzhou.aliyuncs.com/rasa/rasa-x-demo:0.31.0
// 本地下载
docker pull registry.cn-hangzhou.aliyuncs.com/rasa/rasa-x-demo:0.31.0
具体参考:https://cr.console.aliyun.com/[2]
加速后,重新修改官网提供的配置文件:
version: "3.4"
x-database-credentials: &database-credentials
DB_HOST: "db"
DB_PORT: "5432"
DB_USER: "${DB_USER:-admin}"
DB_PASSWORD: "${DB_PASSWORD}"
DB_LOGIN_DB: "${DB_LOGIN_DB:-rasa}"x-rabbitmq-credentials: &rabbitmq-credentials
RABBITMQ_HOST: "rabbit"
RABBITMQ_USERNAME: "user"
RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}x-redis-credentials: &redis-credentials
REDIS_HOST: "redis"
REDIS_PORT: "6379"
REDIS_PASSWORD: ${REDIS_PASSWORD}
REDIS_DB: "1"x-duckling-credentials: &duckling-credentials
RASA_DUCKLING_HTTP_URL: "http://duckling:8000"x-rasax-credentials: &rasax-credentials
RASA_X_HOST: "http://rasa-x:5002"
RASA_X_USERNAME: ${RASA_X_USERNAME:-admin}
RASA_X_PASSWORD: ${RASA_X_PASSWORD:-}
RASA_X_TOKEN: ${RASA_X_TOKEN}
JWT_SECRET: ${JWT_SECRET}
RASA_USER_APP: "http://app:5055"
RASA_PRODUCTION_HOST: "http://rasa-production:5005"
RASA_WORKER_HOST: "http://rasa-worker:5005"
RASA_TOKEN: ${RASA_TOKEN}x-rasa-credentials: &rasa-credentials
<<: *rabbitmq-credentials
<<: *rasax-credentials
<<: *database-credentials
<<: *redis-credentials
<<: *duckling-credentials
RASA_TOKEN: ${RASA_TOKEN}
RASA_MODEL_PULL_INTERVAL: 10
RABBITMQ_QUEUE: "rasa_production_events"x-rasa-services: &default-rasa-service
restart: always
image: "registry.cn-hangzhou.aliyuncs.com/rasa/rasa:${RASA_VERSION}-full"
expose:
- "5005" command: >
x
--no-prompt
--production
--config-endpoint http://rasa-x:5002/api/config?token=${RASA_X_TOKEN}
--port 5005
--jwt-method HS256
--jwt-secret ${JWT_SECRET}
--auth-token '${RASA_TOKEN}'
--cors "*"
depends_on:
- rasa-x - rabbit - redisservices:
rasa-x:
restart: always
image: "registry.cn-hangzhou.aliyuncs.com/rasa/rasa-x:${RASA_X_VERSION}"
expose:
- "5002" volumes:
- ./models:/app/models - ./environments.yml:/app/environments.yml - ./credentials.yml:/app/credentials.yml - ./endpoints.yml:/app/endpoints.yml - ./logs:/logs - ./auth:/app/auth environment:
<<: *database-credentials
<<: *rasa-credentials
SELF_PORT: "5002"
DB_DATABASE: "${DB_DATABASE:-rasa}"
RASA_MODEL_DIR: "/app/models"
PASSWORD_SALT: ${PASSWORD_SALT}
RABBITMQ_QUEUE: "rasa_production_events"
RASA_X_USER_ANALYTICS: "0"
SANIC_RESPONSE_TIMEOUT: "3600"
depends_on:
- db
rasa-production:
<<: *default-rasa-service
environment:
<<: *rasa-credentials
RASA_ENVIRONMENT: "production"
DB_DATABASE: "tracker"
RASA_MODEL_SERVER: "http://rasa-x:5002/api/projects/default/models/tags/production"
rasa-worker:
<<: *default-rasa-service
environment:
<<: *rasa-credentials
RASA_ENVIRONMENT: "worker"
DB_DATABASE: "worker_tracker"
RASA_MODEL_SERVER: "http://rasa-x:5002/api/projects/default/models/tags/production"
app:
restart: always
image: "registry.cn-hangzhou.aliyuncs.com/rasa/rasa-x-demo:${RASA_X_DEMO_VERSION}"
expose:
- "5055" depends_on:
- rasa-production
db:
restart: always
image: "daocloud.io/library/postgres:11.7"
expose:
- "5432" environment:
POSTGRES_USER: "${DB_USER:-admin}"
POSTGRES_PASSWORD: "${DB_PASSWORD}"
POSTGRES_DB: "${DB_DATABASE:-rasa}"
volumes:
- ./db:/bitnami/postgresql
rabbit:
restart: always
image: "daocloud.io/library/rabbitmq:3.8.3"
environment:
RABBITMQ_HOST: "rabbit"
RABBITMQ_USERNAME: "user"
RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}
RABBITMQ_DISK_FREE_LIMIT: "{mem_relative, 0.1}"
expose:
- "5672"
duckling:
restart: always
image: "registry.cn-hangzhou.aliyuncs.com/rasa/duckling:0.1.6.3"
expose:
- "8000" command: ["duckling-example-exe", "--no-access-log", "--no-error-log"]
nginx:
restart: always
image: "registry.cn-hangzhou.aliyuncs.com/rasa/nginx:${RASA_X_VERSION}"
ports:
- "80:8080" - "443:8443" volumes:
- ./certs:/opt/bitnami/certs - ./terms:/opt/bitnami/nginx/conf/bitnami/terms depends_on:
- rasa-x - rasa-production - app
redis:
restart: always
image: "daocloud.io/library/redis:5.0.8"
environment:
REDIS_PASSWORD: ${REDIS_PASSWORD}
expose:
- "6379"
start
编写完 docker-compose.yml 后就可以创建容器了:
docker-compose up -d
access
执行命令:
python rasa_x_commands.py create --update admin me <PASSWORD>
好了,利用新密码就可以进入 Rasa X 网页。
总结
其中配置项主要参考官网说的来,这里就不再赘述了。有了 docker 环境下的 Rasa X,接下来就可以进入我们的交互环节,结合一些使用场景 (如:微信公众号、Slack 等),制作我们的 AI 互动助手 (如,给 Slack 发送指令,回复微信公众号粉丝问题等)。
参考
[1] 「Local Mode」 https://mp.weixin.qq.com/s/HpPxrG2Sr67Sz_nEJHH2PA
[2] https://cr.console.aliyun.com/ https://cr.console.aliyun.com/