1. 创建虚拟环境
$ conda create -n rasa_py38 python==3.8.10
$ source activate rasa_py38
💡 Rasa 只支持 Python 3.6 ~ 3.8,不支持 3.9 版本。
2. 安装Poetry
安装 Poetry 还有点复杂,可以参考教程来安装。
🍎CentOS7 基础环境
3. 安装 Rasa
$ git clone https://github.com/RasaHQ/rasa.git
$ make install
$ make install install-docs
4. 配置Nginx
我们可以通过 Nginx 反向代理来提升 Rasa API 并发稳定性,修改 /etc/nginx/nginx.conf
文件:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
# include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 5001;
server_name localhost;
location /tieniuapi {
rewrite /tieniuapi/(.*) /$1 break;
proxy_pass http://localhost:5005/webhooks/xxxapi/webhook;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
}
}
5. 启动 Rasa
$ rasa run -p 5005 --endpoints ./endpoints.yml \
--credentials ./credentials.yml -m models/ \
--enable-api --quiet