Skip to content

Commit 20a9372

Browse files
authored
Merge pull request #102 from netease-youdao/develop_for_v1.2.0
Fix known issues, optimize user experience.
2 parents baa64fd + 462f009 commit 20a9372

File tree

7 files changed

+262
-110
lines changed

7 files changed

+262
-110
lines changed

FAQ_zh.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,12 @@ We recommend to activate the WSL integration in Docker Desktop settings.
6161

6262
## 执行run.sh时拉取镜像失败: ⠼ error getting credentials - err: exit status 1, out: `error getting credentials - err: exit status 1, out: `A specified logon session does not exist. It may already have been terminated.``
6363
- 解决方案:尝试手动拉取镜像,如执行:docker pull milvusdb/milvus:v2.3.4,然后再重新执行bash run.sh
64+
65+
66+
## 执行run.sh时报错:Illegal instruction (core dumped),或OCR服务无法启动
67+
- 原因:cpu不支持avx指令集,而PaddleOCR依赖avx指令集,导致无法启动OCR服务
68+
- 解决方案:可进入容器后执行"cat /proc/cpuinfo | grep -i avx",如果没有输出,则说明cpu不支持avx指令集,可参考paddle官网的解决办法,在容器内重装paddleocr:https://www.paddlepaddle.org.cn/en/install/quick?docurl=/documentation/docs/en/install/pip/linux-pip_en.html#old-version-anchor-5-Choose%20CPU%2FGPU
69+
```
70+
# If you want to install the Paddle package with avx and openblas, you can use the following command to download the wheel package to the local, and then use python3 -m pip install [name].whl to install locally ([name] is the name of the wheel package):
71+
python3 -m pip download paddlepaddle==2.6.0 -f https://www.paddlepaddle.org.cn/whl/linux/openblas/avx/stable.html --no-index --no-deps
72+
```

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
- [What is QAnything](#What-is-QAnything)
4242
- [Key features](#Key-features)
4343
- [Architecture](#Architecture)
44+
- [Before You Start](#Before-You-Start)
45+
- [Latest Updates](#-Latest-Updates)
4446
- [Getting Started](#getting-started)
4547
- [Prerequisites](#prerequisites)
4648
- [Installation](#installation)
@@ -137,6 +139,12 @@ If you need to use it for commercial purposes, please follow the license of Qwen
137139
* [🛠️ Only use our BCEmbedding(embedding & rerank)](https://github.com/netease-youdao/BCEmbedding)
138140
* [📖 FAQ](FAQ_zh.md)
139141

142+
## 🚀 Latest Updates
143+
144+
- ***2024-01-29***: **Support for custom large models, including OpenAI API and other open-source large models, with a minimum GPU requirement of GTX 1050Ti, greatly improving deployment, debugging, and user experience.** - See More👉 [v1.2.0](https://github.com/netease-youdao/QAnything/releases/tag/v1.2.0)
145+
- ***2024-01-23***: **Enable rerank by default and fix various issues when starting on Windows.** - See More👉 [v1.1.1](https://github.com/netease-youdao/QAnything/releases/tag/v1.1.1)
146+
- ***2024-01-18***: **Support one-click startup, support Windows deployment, improve PDF, XLSX, HTML parsing efficiency.** - See More👉 [v1.1.0](https://github.com/netease-youdao/QAnything/releases/tag/v1.1.0)
147+
140148
## Getting Started
141149

142150
### Prerequisites

README_zh.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
- [什么是QAnything](#什么是QAnything)
3737
- [特点](#特点)
3838
- [架构](#架构)
39+
- [开始之前](#开始之前)
40+
- [最近更新](#-最近更新-)
3941
- [开始](#开始)
4042
- [必要条件](#必要条件)
4143
- [下载安装](#下载安装)
@@ -128,6 +130,12 @@ QAnything使用的检索组件[BCEmbedding](https://github.com/netease-youdao/BC
128130
* [🛠️ 想只使用BCEmbedding(embedding & rerank)](https://github.com/netease-youdao/BCEmbedding)
129131
* [📖 常见问题](FAQ_zh.md)
130132

133+
## 🚀 最近更新
134+
135+
- ***2024-01-29***: **支持自定义大模型,包括OpenAI API和其他开源大模型,GPU需求最低降至GTX 1050Ti,极大提升部署,调试等方面的用户体验** - 详见👉 [v1.2.0](https://github.com/netease-youdao/QAnything/releases/tag/v1.2.0)
136+
- ***2024-01-23***: **默认开启rerank,修复在windows上启动时存在的各类问题** - 详见👉 [v1.1.1](https://github.com/netease-youdao/QAnything/releases/tag/v1.1.1)
137+
- ***2024-01-18***: **支持一键启动,支持windows部署,提升pdf,xlsx,html解析效果** - 详见👉 [v1.1.0](https://github.com/netease-youdao/QAnything/releases/tag/v1.1.0)
138+
131139
## 开始
132140

133141
### 必要条件

qanything_kernel/connector/llm/llm_for_openai_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _call(self, prompt: str, history: List[List[str]], streaming: bool=False) ->
151151
top_p=self.top_p,
152152
stop=[self.stop_words] if self.stop_words is not None else None,
153153
)
154-
154+
logging.info(f"OPENAI RES: {response}")
155155
for event in response:
156156
if not isinstance(event, dict):
157157
event = event.model_dump()

run.sh

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,40 @@ Note: You can choose the most suitable Service Startup Command based on your own
5151
exit 1
5252
}
5353

54+
# 检查master分支是否有新代码
55+
# 定义颜色
56+
RED='\033[0;31m'
57+
GREEN='\033[0;32m'
58+
YELLOW='\033[1;33m'
59+
NC='\033[0m' # No Color
60+
61+
# 定义醒目的提示信息
62+
print_important_notice() {
63+
echo -e "${YELLOW}====================================================${NC}"
64+
echo -e "${YELLOW}******************** 重要提示 ********************${NC}"
65+
echo -e "${YELLOW}====================================================${NC}"
66+
echo
67+
echo -e "${RED}检测到master分支有新的代码更新,请执行 git pull 来同步最新的代码。${NC}"
68+
echo
69+
sleep 5
70+
}
71+
72+
# 获取最新的远程仓库信息
73+
git fetch origin master
74+
75+
# 获取本地master分支的最新提交
76+
LOCAL=$(git rev-parse master)
77+
# 获取远程master分支的最新提交
78+
REMOTE=$(git rev-parse origin/master)
79+
80+
if [ $LOCAL != $REMOTE ]; then
81+
# 本地分支与远程分支不一致,需要更新
82+
print_important_notice
83+
else
84+
echo -e "${GREEN}当前master分支已是最新,无需更新。${NC}"
85+
fi
86+
87+
5488
llm_api="local"
5589
device_id="0"
5690
runtime_backend="default"
@@ -109,8 +143,6 @@ if ! [[ $gpu_id1 =~ ^[0-9]+$ ]] || ! [[ $gpu_id2 =~ ^[0-9]+$ ]]; then
109143
exit 1
110144
fi
111145

112-
# echo "GPUID1=${gpu_id1}" >> .env
113-
# echo "GPUID2=${gpu_id2}" >> .env
114146
update_or_append_to_env "GPUID1" "$gpu_id1"
115147
update_or_append_to_env "GPUID2" "$gpu_id2"
116148

@@ -142,7 +174,6 @@ else
142174
OCR_USE_GPU="False"
143175
fi
144176
echo "OCR_USE_GPU=$OCR_USE_GPU because $compute_capability >= 7.5"
145-
# echo "OCR_USE_GPU=$OCR_USE_GPU" >> .env
146177
update_or_append_to_env "OCR_USE_GPU" "$OCR_USE_GPU"
147178

148179
# 使用nvidia-smi命令获取GPU的显存大小(以MiB为单位)
@@ -154,7 +185,28 @@ echo "******************** 重要提示 ********************"
154185
echo "===================================================="
155186
echo ""
156187

157-
if [ "$GPU1_MEMORY_SIZE" -lt 8000 ]; then # 显存小于8GB
188+
# 使用默认后端且model_size_num不为0
189+
if [ "$runtime_backend" = "default" ] && [ "$model_size_num" -ne 0 ]; then
190+
if [ -z "$gpu_series" ]; then # 不是Nvidia 30系列或40系列
191+
echo "您的显卡型号 $gpu_model 部署默认后端FasterTransformer需要Nvidia RTX 30系列或40系列显卡,将自动为您切换后端:"
192+
# 如果显存大于等于24GB且计算力大于等于8.6,则可以使用vllm后端
193+
if [ "$GPU1_MEMORY_SIZE" -ge 24000 ] && [ $(echo "$compute_capability >= 8.6" | bc) -eq 1 ]; then
194+
echo "根据匹配算法,已自动为您切换为vllm后端(推荐)"
195+
runtime_backend="vllm"
196+
else
197+
# 自动切换huggingface后端
198+
echo "根据匹配算法,已自动为您切换为huggingface后端"
199+
runtime_backend="hf"
200+
fi
201+
fi
202+
fi
203+
204+
if [ "$GPU1_MEMORY_SIZE" -lt 4000 ]; then # 显存小于4GB
205+
echo "您当前的显存为 $GPU1_MEMORY_SIZE MiB 不足以部署本项目,建议升级到GTX 1050Ti或以上级别的显卡"
206+
exit 1
207+
elif [ "$model_size_num" -eq 0 ]; then # 模型大小为0B, 表示使用openai api,4G显存就够了
208+
echo "您当前的显存为 $GPU1_MEMORY_SIZE MiB 可以使用在线的OpenAI API"
209+
elif [ "$GPU1_MEMORY_SIZE" -lt 8000 ]; then # 显存小于8GB
158210
# 显存小于8GB,仅推荐使用在线的OpenAI API
159211
echo "您当前的显存为 $GPU1_MEMORY_SIZE MiB 仅推荐使用在线的OpenAI API"
160212
if [ "$model_size_num" -gt 0 ]; then # 模型大小大于0B
@@ -229,7 +281,6 @@ elif [ "$GPU1_MEMORY_SIZE" -gt 25000 ]; then # 显存大于24GB
229281
OFFCUT_TOKEN=0
230282
fi
231283

232-
# echo "OFFCUT_TOKEN=$OFFCUT_TOKEN" >> .env
233284
update_or_append_to_env "OFFCUT_TOKEN" "$OFFCUT_TOKEN"
234285

235286
if [ $llm_api = 'cloud' ]; then
@@ -287,15 +338,6 @@ echo "conv_template is set to [$conv_template]"
287338
echo "tensor_parallel is set to [$tensor_parallel]"
288339
echo "gpu_memory_utilization is set to [$gpu_memory_utilization]"
289340

290-
# 写入环境变量.env文件
291-
#echo "LLM_API=${llm_api}" >> .env
292-
#echo "DEVICE_ID=$device_id" >> .env
293-
#echo "RUNTIME_BACKEND=$runtime_backend" >> .env
294-
#echo "MODEL_NAME=$model_name" >> .env
295-
#echo "CONV_TEMPLATE=$conv_template" >> .env
296-
#echo "TP=$tensor_parallel" >> .env
297-
#echo "GPU_MEM_UTILI=$gpu_memory_utilization" >> .env
298-
299341
update_or_append_to_env "LLM_API" "$llm_api"
300342
update_or_append_to_env "DEVICE_ID" "$device_id"
301343
update_or_append_to_env "RUNTIME_BACKEND" "$runtime_backend"
@@ -403,22 +445,26 @@ if [[ -f "$user_file" ]]; then
403445
read -p "Do you want to use the previous host: $host? (yes/no) 是否使用上次的host: $host?(yes/no) 回车默认选yes,请输入:" use_previous
404446
use_previous=${use_previous:-yes}
405447
if [[ $use_previous != "yes" && $use_previous != "" ]]; then
406-
read -p "Are you running the code on a cloud server or on your local machine? (cloud/local) 您是在云服务器上还是本地机器上启动代码?(cloud/local) " answer
448+
read -p "Are you running the code on a remote server or on your local machine? (remote/local) 您是在远程服务器上还是本地机器上启动代码?(remote/local) " answer
407449
if [[ $answer == "local" || $answer == "本地" ]]; then
408450
host="localhost"
409451
else
410-
read -p "Please enter the server IP address 请输入服务器IP地址(示例:10.234.10.144): " host
452+
read -p "Please enter the server IP address 请输入服务器公网IP地址(示例:10.234.10.144): " host
453+
echo "当前设置的远程服务器IP地址为 $host, QAnything启动后,本地前端服务(浏览器打开[http://$user_ip:5052/qanything/])将远程访问[http://$host:8777]上的后端服务,请知悉!"
454+
sleep 5
411455
fi
412456
# 保存新的配置到用户文件
413457
echo "$host" > "$user_file"
414458
fi
415459
else
416460
# 如果用户文件不存在,询问用户并保存配置
417-
read -p "Are you running the code on a cloud server or on your local machine? (cloud/local) 您是在云服务器上还是本地机器上启动代码?(cloud/local) " answer
461+
read -p "Are you running the code on a remote server or on your local machine? (remotelocal) 您是在云服务器上还是本地机器上启动代码?(remote/local) " answer
418462
if [[ $answer == "local" || $answer == "本地" ]]; then
419463
host="localhost"
420464
else
421-
read -p "Please enter the server IP address 请输入服务器IP地址(示例:10.234.10.144): " host
465+
read -p "Please enter the server IP address 请输入服务器公网IP地址(示例:10.234.10.144): " host
466+
echo "当前设置的远程服务器IP地址为 $host, QAnything启动后,本地前端服务(浏览器打开[http://$user_ip:5052/qanything/])将远程访问[http://$host:8777]上的后端服务,请知悉!"
467+
sleep 5
422468
fi
423469
# 保存配置到用户文件
424470
echo "$host" > "$user_file"

scripts/run_for_cloud_option.sh

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ update_or_append_to_env() {
1515
fi
1616
}
1717

18+
function check_log_errors() {
19+
local log_file=$1 # 将第一个参数赋值给变量log_file,表示日志文件的路径
20+
21+
# 检查日志文件是否存在
22+
if [[ ! -f "$log_file" ]]; then
23+
echo "指定的日志文件不存在: $log_file"
24+
return 1
25+
fi
26+
27+
# 使用grep命令检查"core dumped"或"Error"的存在
28+
# -C 5表示打印匹配行的前后各5行
29+
local pattern="core dumped|Error|error"
30+
if grep -E -C 5 "$pattern" "$log_file"; then
31+
echo "检测到错误信息,请查看上面的输出。"
32+
exit 1
33+
else
34+
echo "$log_file 中未检测到明确的错误信息。请手动排查 $log_file 以获取更多信息。"
35+
fi
36+
}
37+
1838
script_name=$(basename "$0")
1939

2040
usage() {
@@ -127,8 +147,6 @@ CUDA_VISIBLE_DEVICES=$gpuid1 nohup /opt/tritonserver/bin/tritonserver --model-st
127147

128148
update_or_append_to_env "EMBED_PORT" "9001"
129149
update_or_append_to_env "RERANK_PORT" "9001"
130-
# echo "RERANK_PORT=9001" >> /workspace/qanything_local/.env
131-
# echo "EMBED_PORT=9001" >> /workspace/qanything_local/.env
132150

133151
cd /workspace/qanything_local || exit
134152
nohup python3 -u qanything_kernel/dependent_server/rerank_for_local_serve/rerank_server.py > /workspace/qanything_local/logs/debug_logs/rerank_server.log 2>&1 &
@@ -144,8 +162,6 @@ echo "The qanything backend service is ready! (4/8)"
144162
echo "qanything后端服务已就绪! (4/8)"
145163

146164

147-
timeout_time=300 # npm下载超时时间300秒,triton_server启动超时时间600秒
148-
149165
env_file="/workspace/qanything_local/front_end/.env.production"
150166
user_file="/workspace/qanything_local/user.config"
151167
user_ip=$(cat "$user_file")
@@ -165,11 +181,11 @@ cd /workspace/qanything_local/front_end || exit
165181
# 安装依赖
166182
echo "Waiting for [npm run install](5/8)"
167183
npm config set registry https://registry.npmmirror.com
168-
timeout $timeout_time npm install
184+
timeout 180 npm install
169185
if [ $? -eq 0 ]; then
170186
echo "[npm run install] Installed successfully(5/8)"
171187
elif [ $? -eq 124 ]; then
172-
echo "npm install 下载超时,可能是网络问题,请修改 npm 代理。"
188+
echo "npm install 下载超时(180秒),可能是网络问题,请修改 npm 代理。"
173189
exit 1
174190
else
175191
echo "Failed to install npm dependencies."
@@ -178,9 +194,12 @@ fi
178194

179195
# 构建前端项目
180196
echo "Waiting for [npm run build](6/8)"
181-
npm run build
197+
timeout 180 npm run build
182198
if [ $? -eq 0 ]; then
183199
echo "[npm run build] build successfully(6/8)"
200+
elif [ $? -eq 124 ]; then
201+
echo "npm run build 编译超时(180秒),请查看上面的输出。"
202+
exit 1
184203
else
185204
echo "Failed to build the front end."
186205
exit 1
@@ -190,7 +209,7 @@ fi
190209
nohup npm run serve 1>/workspace/qanything_local/logs/debug_logs/npm_server.log 2>&1 &
191210

192211
# 监听前端页面服务
193-
tail -f npm_server.log &
212+
tail -f /workspace/qanything_local/logs/debug_logs/npm_server.log &
194213

195214
front_end_start_time=$(date +%s)
196215

@@ -212,41 +231,54 @@ done
212231
echo "The front-end service is ready!...(7/8)"
213232
echo "前端服务已就绪!...(7/8)"
214233

215-
current_time=$(date +%s)
216-
elapsed=$((current_time - start_time)) # 计算经过的时间(秒)
217-
echo "Time elapsed: ${elapsed} seconds."
218-
echo "已耗时: ${elapsed} 秒."
234+
embed_rerank_log_file="/workspace/qanything_local/logs/debug_logs/embed_rerank_tritonserver.log"
235+
236+
tail -f $embed_rerank_log_file & # 后台输出日志文件
237+
tail_pid=$! # 获取tail命令的进程ID
219238

239+
now_time=$(date +%s)
220240
while true; do
241+
current_time=$(date +%s)
242+
elapsed_time=$((current_time - now_time))
243+
221244
if [ "$runtime_backend" = "default" ]; then
222245
response_embed_rerank=$(curl -s -w "%{http_code}" http://localhost:9000/v2/health/ready -o /dev/null)
223246
echo "health response_embed_rerank = $response_embed_rerank"
224247

248+
# 检查是否超时
249+
if [ $elapsed_time -ge 60 ]; then
250+
kill $tail_pid # 关闭后台的tail命令
251+
echo "启动 embedding and rerank 服务超时,自动检查 $embed_rerank_log_file 中是否存在Error..."
252+
253+
check_log_errors $embed_rerank_log_file
254+
255+
exit 1
256+
fi
257+
225258
if [ "$response_embed_rerank" -eq 200 ]; then
226-
echo "The llm service is ready!, now you can use the qanything service. (8/8)"
227-
echo "LLM 服务已准备就绪!现在您可以使用qanything服务。(8/8)"
259+
kill $tail_pid # 关闭后台的tail命令
260+
echo "The embedding and rerank service is ready!, now you can use the qanything service. (8/8)"
261+
echo "Embedding 和 Rerank 服务已准备就绪!现在您可以使用qanything服务。(8/8)"
228262
break
229-
else
230-
echo "The llm service is starting up, it can be long... you have time to make a coffee :)"
231-
echo "LLM 服务正在启动,可能需要一段时间...你有时间去冲杯咖啡 :)"
232-
233-
current_time=$(date +%s)
234-
elapsed_time=$((current_time - start_time))
235-
236-
# 检查是否超时
237-
if [ $elapsed_time -ge $((timeout_time * 2)) ]; then
238-
echo "启动 LLM 服务超时,请检查项目根目录下 logs/debug_logs/embed_rerank_tritonserver.log 以获取更多信息。"
239-
exit 1
240-
fi
241-
sleep 5
242263
fi
264+
265+
echo "The embedding and rerank service is starting up, it can be long... you have time to make a coffee :)"
266+
echo "Embedding and Rerank 服务正在启动,可能需要一段时间...你有时间去冲杯咖啡 :)"
267+
sleep 10
268+
243269
else
244270
# cloud版本runtime只支持default
245271
echo "runtime_backend only support default in cloud version."
246272
exit 1
247273
fi
248274
done
249275

276+
echo "开始检查日志文件中的错误信息..."
277+
# 调用函数并传入日志文件路径
278+
check_log_errors "/workspace/qanything_local/logs/debug_logs/rerank_server.log"
279+
check_log_errors "/workspace/qanything_local/logs/debug_logs/ocr_server.log"
280+
check_log_errors "/workspace/qanything_local/logs/debug_logs/sanic_api.log"
281+
250282
current_time=$(date +%s)
251283
elapsed=$((current_time - start_time)) # 计算经过的时间(秒)
252284
echo "Time elapsed: ${elapsed} seconds."

0 commit comments

Comments
 (0)