おっしゃる通り、当初はネットワークスタックの問題だと思っていましたが、同じコンテナからOpenAI APIを繰り返し呼び出しても問題なく動作します。
これは非常に最近のビルド、2月21日時点のコミットでも同様です。
これを証明するために(トークンを消費する犠牲を払って)、OpenAIネットワークスタックをテストする簡単なスクリプトを作成しました。
- 600秒(10分)実行されます
- 1秒間に1回のチャット補完呼び出しを行います
- キャッシュを回避するためにプロンプトを変更します
コンテナ内で ./launcher enter app を実行し、以下のスクリプトを保存し、chmod +x test_openai.sh で実行可能にしてから、OPENAI_API_KEY=.... ./test_openai.sh で呼び出してください。
test_openai.sh
#!/bin/bash
# Duration to run
DURATION_SECS=600
# Initialize counters
successful=0
unsuccessful=0
declare -A error_messages
# Function to calculate percentage
calc_percentage() {
local total=$(($1 + $2))
if [ $total -eq 0 ]; then
echo "0.00"
else
echo "scale=2; ($2 * 100) / $total" | bc
fi
}
# Function to print statistics
print_stats() {
local percent=$(calc_percentage $successful $unsuccessful)
echo "-------------------"
echo "Successful calls: $successful"
echo "Failed calls: $unsuccessful"
echo "Failure rate: ${percent}%"
echo "Error messages:"
for error in "${!error_messages[@]}"; do
echo " - $error (${error_messages[$error]} times)"
done
}
end_time=$((SECONDS + DURATION_SECS))
counter=1
while [ $SECONDS -lt $end_time ]; do
# Make the API call with timeout
response=$(curl -s -w "\n%{http_code}" \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d "{
\"model\": \"gpt-4o-mini\",
\"messages\": [{\"role\": \"user\", \"content\": \"Use this number to choose a one word response: $counter\"}]
}" \
--connect-timeout 5 \
--max-time 10 \
https://api.openai.com/v1/chat/completions 2>&1)
# Get the last line (status code) and response body
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
# Check if the call was successful
if [ "$http_code" = "200" ]; then
((successful++))
else
((unsuccessful++))
# Extract error message
error_msg=$(echo "$body" | grep -o '"message":"[^"]*"' | cut -d'"' -f4)
if [ -z "$error_msg" ]; then
error_msg="Connection error: $body"
fi
# Increment error message counter
((error_messages["$error_msg"]++))
fi
# Print current statistics
print_stats
((counter++))
# Wait for 1 second before next call
sleep 1
done
テストスクリプトでは、失敗率は0.5%未満で、その規模では許容範囲内でした。
これは、問題がコンテナやそれを支えるネットワークスタックではなく、Discourseソフトウェアにあることを示しています。
最近のコミットで修正されていない場合は、さらに詳しく調査します。