# 1. 提交任务
RESPONSE=$(curl -sS -X POST http://localhost:8080/api/v1/tasks \
-H "X-API-Key: sk_test_123456" \
-H "Content-Type: application/json" \
-d '{
"query": "法国的首都是什么?"
}')
# 2. 提取任务 ID
TASK_ID=$(echo $RESPONSE | jq -r '.task_id')
echo "任务 ID: $TASK_ID"
# 3. 轮询结果
while true; do
STATUS=$(curl -sS http://localhost:8080/api/v1/tasks/$TASK_ID \
-H "X-API-Key: sk_test_123456")
STATE=$(echo $STATUS | jq -r '.status')
if [ "$STATE" = "TASK_STATUS_COMPLETED" ]; then
echo $STATUS | jq -r '.result'
break
elif [ "$STATE" = "TASK_STATUS_FAILED" ]; then
echo "错误: $(echo $STATUS | jq -r '.error')"
exit 1
fi
sleep 2
done