初始化默认服务器
This commit is contained in:
136
test.sh
136
test.sh
@@ -47,73 +47,83 @@ message "$response" "登錄"
|
||||
session_id=$(echo "$response" | head -n -1 | grep -o '"id": "[^"]*' | cut -d '"' -f 4)
|
||||
#echo "session_id: $session_id"
|
||||
|
||||
# 获取模型列表
|
||||
response=$(curl -X GET -H "Content-Type: application/json" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models)
|
||||
message "$response" "模型列表" true
|
||||
|
||||
# 上傳圖片 (POST /api/images)
|
||||
response=$(curl -X POST -H "Content-Type: multipart/form-data" -F "file=@./data/test.jpeg" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/images)
|
||||
message "$response" "上傳圖片" true
|
||||
|
||||
# 臨時退出
|
||||
exit_service "測試結束, 全部通過, 用費時間: $(($(date +%s) - $start_time)) 秒"
|
||||
|
||||
# 創建數據集, 應當在cookie中攜帶session_id (POST /api/datasets)
|
||||
response=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"test","description":"test"}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets)
|
||||
message "$response" "創建數據集"
|
||||
|
||||
|
||||
# 取數據集id的值, 值爲 int
|
||||
dataset_id=$(echo "${response%???}" | grep -o '"id": [0-9]*' | awk '{print $2}')
|
||||
#echo "dataset_id: $dataset_id"
|
||||
|
||||
|
||||
# 獲取數據集列表 (GET /api/datasets)
|
||||
response=$(curl -X GET -H "Content-Type: application/json" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets)
|
||||
message "$response" "數據集列表"
|
||||
|
||||
|
||||
# 修改數據集, images 中增加 url (PATCH /api/datasets/:id)
|
||||
response=$(curl -X PATCH -H "Content-Type: application/json" -d '{"images":["https://img.gameui.net/article-7258-1677745322000@1x456.webp","https://img.gameui.net/article-6477-1682109454000@1x456.webp"]}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets/$dataset_id)
|
||||
message "$response" "修改數據集"
|
||||
|
||||
|
||||
# 添加服務器 (POST /api/servers)
|
||||
response=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"GPU-T4","type":"訓練","ip":"106.15.192.42","port":7860}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/servers)
|
||||
message "$response" "添加服務器"
|
||||
|
||||
|
||||
# 服務器列表
|
||||
response=$(curl -X GET -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/servers)
|
||||
message "$response" "服務器列表"
|
||||
|
||||
|
||||
# 創建模型訓練任務 (POST /api/models)
|
||||
response=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"test","type":"dreambooth","trigger_words":"miao~","base_model":"sd1.5","epochs":20,"description":"test","dataset_id":'$dataset_id'}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models)
|
||||
message "$response" "創建模型訓練任務" true
|
||||
|
||||
|
||||
# 取模型id的值, 值爲 int
|
||||
# 使用第一个模型的id, 执行推理生成图像
|
||||
model_id=$(echo "${response%???}" | grep -o '"id": [0-9]*' | awk '{print $2}')
|
||||
#echo "model_id: $model_id"
|
||||
echo "model_id: $model_id"
|
||||
|
||||
response=$(curl -X POST -H "Content-Type: application/json" -d '{"model_id":'$model_id',"text":"miao~"}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/images)
|
||||
message "$response" "推理生成图像" true
|
||||
|
||||
## 上傳圖片 (POST /api/images)
|
||||
#response=$(curl -X POST -H "Content-Type: multipart/form-data" -F "file=@./data/test.jpeg" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/images)
|
||||
#message "$response" "上傳圖片"
|
||||
#
|
||||
## 臨時退出
|
||||
##exit_service "測試結束, 全部通過, 用費時間: $(($(date +%s) - $start_time)) 秒"
|
||||
#
|
||||
## 創建數據集, 應當在cookie中攜帶session_id (POST /api/datasets)
|
||||
#response=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"test","description":"test"}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets)
|
||||
#message "$response" "創建數據集"
|
||||
#
|
||||
#
|
||||
## 取數據集id的值, 值爲 int
|
||||
#dataset_id=$(echo "${response%???}" | grep -o '"id": [0-9]*' | awk '{print $2}')
|
||||
##echo "dataset_id: $dataset_id"
|
||||
#
|
||||
#
|
||||
## 獲取數據集列表 (GET /api/datasets)
|
||||
#response=$(curl -X GET -H "Content-Type: application/json" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets)
|
||||
#message "$response" "數據集列表"
|
||||
#
|
||||
#
|
||||
## 修改數據集, images 中增加 url (PATCH /api/datasets/:id)
|
||||
#response=$(curl -X PATCH -H "Content-Type: application/json" -d '{"images":["https://img.gameui.net/article-7258-1677745322000@1x456.webp","https://img.gameui.net/article-6477-1682109454000@1x456.webp"]}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/datasets/$dataset_id)
|
||||
#message "$response" "修改數據集"
|
||||
|
||||
|
||||
# 循環獲取模型訓練進度, 直到訓練完成
|
||||
while true; do
|
||||
# 獲取模型訓練進度 (GET /api/models/:id)
|
||||
response=$(curl -X GET -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models/$model_id)
|
||||
progress=$(echo "${response%???}" | grep -o '"progress": [0-9]*' | awk '{print $2}')
|
||||
status=$(echo "${response%???}" | grep -o '"status": "[^"]*' | cut -d '"' -f 4)
|
||||
message "$response" "獲取模型訓練進度 $progress% $status"
|
||||
# 如果進度爲 100, 訓練完成, 跳出循環
|
||||
[[ $progress -eq 100 ]] && { echo "訓練完成"; break; }
|
||||
# 測試訓練時間不超過10秒, 超過則退出
|
||||
[[ $(($(date +%s) - $start_time)) -gt 10 ]] && exit_service "訓練時間超過20秒"
|
||||
# 休眠 3 秒
|
||||
sleep 3
|
||||
done
|
||||
|
||||
|
||||
## 模型列表 (GET /api/models)
|
||||
#response=$(curl -X GET -H "Content-Type: application/json" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models)
|
||||
#message "$response" "模型列表"
|
||||
## 添加服務器 (POST /api/servers)
|
||||
#response=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"GPU-T4","type":"訓練","ip":"106.15.192.42","port":7860}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/servers)
|
||||
#message "$response" "添加服務器"
|
||||
#
|
||||
#
|
||||
## 服務器列表
|
||||
#response=$(curl -X GET -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/servers)
|
||||
#message "$response" "服務器列表"
|
||||
#
|
||||
#
|
||||
## 創建模型訓練任務 (POST /api/models)
|
||||
#response=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"test","type":"dreambooth","trigger_words":"miao~","base_model":"sd1.5","epochs":20,"description":"test","dataset_id":'$dataset_id'}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models)
|
||||
#message "$response" "創建模型訓練任務" true
|
||||
#
|
||||
#
|
||||
## 取模型id的值, 值爲 int
|
||||
#model_id=$(echo "${response%???}" | grep -o '"id": [0-9]*' | awk '{print $2}')
|
||||
##echo "model_id: $model_id"
|
||||
#
|
||||
#
|
||||
## 循環獲取模型訓練進度, 直到訓練完成
|
||||
#while true; do
|
||||
# # 獲取模型訓練進度 (GET /api/models/:id)
|
||||
# response=$(curl -X GET -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models/$model_id)
|
||||
# progress=$(echo "${response%???}" | grep -o '"progress": [0-9]*' | awk '{print $2}')
|
||||
# status=$(echo "${response%???}" | grep -o '"status": "[^"]*' | cut -d '"' -f 4)
|
||||
# message "$response" "獲取模型訓練進度 $progress% $status"
|
||||
# # 如果進度爲 100, 訓練完成, 跳出循環
|
||||
# [[ $progress -eq 100 ]] && { echo "訓練完成"; break; }
|
||||
# # 測試訓練時間不超過10秒, 超過則退出
|
||||
# [[ $(($(date +%s) - $start_time)) -gt 10 ]] && exit_service "訓練時間超過20秒"
|
||||
# # 休眠 3 秒
|
||||
# sleep 3
|
||||
#done
|
||||
#
|
||||
#
|
||||
### 模型列表 (GET /api/models)
|
||||
##response=$(curl -X GET -H "Content-Type: application/json" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models)
|
||||
##message "$response" "模型列表"
|
||||
|
||||
|
||||
exit_service "測試結束, 全部通過, 用費時間: $(($(date +%s) - $start_time)) 秒"
|
||||
|
Reference in New Issue
Block a user