Skip to content

Commit

Permalink
Enable multiple workers to improve perf (#75)
Browse files Browse the repository at this point in the history
* Add fast bm25

* Update

* Fix bug

* Fix bm25 bug

* Fix bug

* Refine code

* Update multi-process

* Add API to support upload local files (#67)

* support upload file via API

* add Readme for upload API

* refactor query api

* modify load_knowledge with session_config

* use tempfile.mkdtemp() to store upload files

* add docker image timezone for China (#68)

* add image zone for China

* remove unused ENV

---------

Co-authored-by: shubao.sx <shubao.sx@alibaba-inc.com>
Co-authored-by: Yue Fei <luxun.fy@alibaba-inc.com>

* load data pipeline supports read config (#70)

* Add gpu docker image timezone for China (#74)

* Add fast bm25 (#66)

* Add fast bm25

* Fix bm25 bug

* Fix bug

* Fix test

* Update dockerfile

* Fix bug

* Update

* Update docker file

* Fix empty file bug

* Fix local index error

* Fix lint

* Decouple gradio and backend

* Add ui build

* Add gunicorn

* Fix gunicorn

* Update nginx

* add nginx image

* Fix deployment issue

* Fix upload

---------

Co-authored-by: 筱文 <zxw320697@alibaba-inc.com>
Co-authored-by: paradiseHIT <paradiseHIT@gmail.com>
Co-authored-by: shubao.sx <shubao.sx@alibaba-inc.com>
  • Loading branch information
4 people authored Jun 24, 2024
1 parent 7c2467e commit 9e68ac6
Show file tree
Hide file tree
Showing 37 changed files with 2,140 additions and 602 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ jobs:
docker tag ${{ env.REGISTRY }}/mybigpai/pairag:$IMAGE_TAG ${{ env.REGISTRY_HZ }}/mybigpai/pairag:$IMAGE_TAG
docker push ${{ env.REGISTRY }}/mybigpai/pairag:$IMAGE_TAG
docker push ${{ env.REGISTRY_HZ }}/mybigpai/pairag:$IMAGE_TAG
- name: Build and push UI image
env:
IMAGE_TAG: 0.0.2_ui
run: |
docker build -t ${{ env.REGISTRY }}/mybigpai/pairag:$IMAGE_TAG -f Dockerfile_ui .
docker tag ${{ env.REGISTRY }}/mybigpai/pairag:$IMAGE_TAG ${{ env.REGISTRY_HZ }}/mybigpai/pairag:$IMAGE_TAG
docker push ${{ env.REGISTRY }}/mybigpai/pairag:$IMAGE_TAG
docker push ${{ env.REGISTRY_HZ }}/mybigpai/pairag:$IMAGE_TAG
- name: Build and push nginx image
env:
IMAGE_TAG: 0.0.2_nginx
run: |
docker build -t ${{ env.REGISTRY }}/mybigpai/pairag:$IMAGE_TAG -f Dockerfile_nginx .
docker tag ${{ env.REGISTRY }}/mybigpai/pairag:$IMAGE_TAG ${{ env.REGISTRY_HZ }}/mybigpai/pairag:$IMAGE_TAG
docker push ${{ env.REGISTRY }}/mybigpai/pairag:$IMAGE_TAG
docker push ${{ env.REGISTRY_HZ }}/mybigpai/pairag:$IMAGE_TAG
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,4 @@ output
*.local.toml

localdata/
*.tmp
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ RUN apt-get update && apt-get install -y libgl1 libglib2.0-0
WORKDIR /app
COPY . .
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
ENTRYPOINT ["pai_rag", "run"]
CMD ["pai_rag", "run"]
2 changes: 1 addition & 1 deletion Dockerfile_gpu
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ RUN apt-get update && apt-get install -y libgl1 libglib2.0-0
WORKDIR /app
COPY . .
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
ENTRYPOINT ["pai_rag", "run"]
CMD ["pai_rag", "run"]
3 changes: 3 additions & 0 deletions Dockerfile_nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:latest
COPY ./nginx/default.conf etc/nginx/conf.d/default.conf
COPY ./nginx/nginx.conf etc/nginx/nginx.conf
27 changes: 27 additions & 0 deletions Dockerfile_ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.10-slim AS builder

RUN pip3 install poetry

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

WORKDIR /app
COPY . .

RUN poetry install && rm -rf $POETRY_CACHE_DIR

FROM python:3.10-slim AS prod

RUN rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Harbin /etc/localtime

ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"

RUN apt-get update && apt-get install -y libgl1 libglib2.0-0

WORKDIR /app
COPY . .
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
CMD ["pai_rag", "ui"]
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ poetry install
load_data -c src/pai_rag/config/settings.yaml -d directory_path
```

#### Step4: 启动程序
#### Step4: 启动RAG服务

使用OpenAI API,需要在命令行引入环境变量 export OPENAI_API_KEY=""
使用DashScope API,需要在命令行引入环境变量 export DASHSCOPE_API_KEY=""

```bash
# 启动,支持自定义host(默认0.0.0.0), port(默认8000), config(默认src/pai_rag/config/settings.yaml)
pai_rag run [--host HOST] [--port PORT] [--config CONFIG_FILE]
# 启动,支持自定义host(默认0.0.0.0), port(默认8001), config(默认src/pai_rag/config/settings.yaml)
pai_rag serve [--host HOST] [--port PORT] [--config CONFIG_FILE]
```

现在你可以使用命令行向服务侧发送API请求,或者直接打开http://localhost:8000
你可以使用命令行向服务侧发送API请求。比如调用[Upload API](#upload-api)上传知识库文件。

1. 对话
##### Query API

- **Rag Query请求**

Expand Down Expand Up @@ -77,7 +77,7 @@ curl -X 'POST' http://127.0.0.1:8000/service/query -H "Content-Type: application
curl -X 'POST' http://127.0.0.1:8000/service/query/agent -H "Content-Type: application/json" -d '{"question":"今年是2024年,10年前是哪一年?"}'
```

2. 评估
##### Evaluation API

支持三种评估模式:全链路评估、检索效果评估、生成效果评估。

Expand Down Expand Up @@ -144,7 +144,7 @@ curl -X 'POST' http://127.0.0.1:8000/service/batch_evaluate/response
}
```

3. 上传
##### Upload API

支持通过API的方式上传本地文件,并支持指定不同的faiss_path,每次发送API请求会返回一个task_id,之后可以通过task_id来查看文件上传状态(processing、completed、failed)。

Expand All @@ -164,6 +164,15 @@ curl http://127.0.0.1:8077/service/get_upload_state\?task_id\=2c1e557733764fdb9f
# Return: {"task_id":"2c1e557733764fdb9fefa063538914da","status":"completed"}
```

### RAG WEB UI

```bash
# 启动,支持自定义host(默认0.0.0.0), port(默认8002), config(默认localhost:8001)
pai_rag ui [--host HOST] [--port PORT] [rag-url RAG_URL]
```

你也可以打开http://127.0.0.1:8002/ 来配置RAG服务以及上传本地数据。

### 独立脚本文件:不依赖于整体服务的启动,可独立运行

1. 向当前索引存储中插入新文件
Expand Down
67 changes: 67 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

server {
listen 8000;
listen [::]:8000;
server_name localhost;
client_max_body_size 50m;

#access_log /var/log/nginx/host.access.log main;

location / {
proxy_set_header Host \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8002;
}

#Websocket configuration
location /queue/ {
proxy_pass http://127.0.0.1:8002/queue/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

location /service {
proxy_set_header Host \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8001;
}

location /docs {
proxy_set_header Host \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8001;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
33 changes: 33 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

user nginx;
daemon off;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}
Loading

0 comments on commit 9e68ac6

Please # to comment.