Troubleshooting of OpenAI API in Mandarin

From LemonWiki共筆
Jump to navigation Jump to search

OpenAI API 技術問題疑難排解

🌐 Switch language: EN, 漢字


Raise_hand.png 如果您對 OpenAI API 有任何疑問,您可以在 OpenAI 開發者論壇的最新 API 主題 下發表文章。

如何解決「發生錯誤」[edit]

  • 錯誤訊息:"An error occurred. If this issue persists please contact us through our help center at help.openai.com."
  • 解決方案:重新載入網頁 https://chat.openai.com/chat

如何解決「502 Bad Gateway」[edit]

錯誤訊息

{
  "error": {
    "code": 502,
    "message": "Bad gateway.",
    "param": null,
    "type": "cf_bad_gateway"
  }
}

解決方案:

  • 嘗試重新發送 API 請求。

如何解決「messages 是必須的屬性」[edit]

  • 錯誤訊息:'messages' is a required property
{
    "error": {
        "message": "'messages' is a required property",
        "type": "invalid_request_error",
        "param": null,
        "code": null
    }
}
  • 範例輸入:
{
    "model": "gpt-4",
    "max_tokens": 1000,
    "temperature": 0.9,
  }
  • 解決方案:檢查是否有 `messages` 屬性,例如:
{
    "model": "gpt-4",
    "max_tokens": 1000,
    "temperature": 0.9,
    "messages": [
        {"role": "system", "content": "#zh-TW 您是一個有幫助的助手,請幫我摘要文章"},
        {"role": "user", "content": "您的文章內容..."}
    ]
}

如何解決「"' ' is not of type 'array' - 'messages'"」[edit]

  • 錯誤訊息:
{
    "error": {
        "message": "'' is not of type 'array' - 'messages'",
        "type": "invalid_request_error",
        "param": null,
        "code": null
    }
}
  • 範例輸入:
{
    "model": "gpt-4",
    "max_tokens": 1000,
    "temperature": 0.9,
    "messages": ""
}
  • 解決方案:`messages` 屬性應該為陣列,例如:
{
    "model": "gpt-4",
    "max_tokens": 1000,
    "temperature": 0.9,
    "messages": [
        {"role": "system", "content": "#zh-TW 您是一個有幫助的助手,請幫我摘要文章"},
        {"role": "user", "content": "您的文章內容..."}
    ]
}

如何解決「'2000' 不是類型 'integer' 的值 - 'max_tokens'」[edit]

  • 錯誤訊息:
{
  "error": {
    "message": "'2000' is not of type 'integer' - 'max_tokens'",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

解決方案:

  • 將 "max_tokens" 參數修改為整數,而非字串。
{
    "model": "gpt-4",
    "max_tokens": 1000,
    "temperature": 0.9,
    "messages": ""
}

如何解決「Invalid parameter: 'response_format' of type 'json_object' is not supported with this model」[edit]

錯誤訊息:

Invalid parameter: 'response_format' of type 'json_object' is not supported with this model.
  • 範例輸入:
{
    "model": "gpt-4",
    "max_tokens": 1000,
    "temperature": 0.9,
    "messages": [
        {"role": "system", "content": "#zh-TW 您是一個有幫助的助手,請幫我摘要文章"},
        {"role": "user", "content": null}
    ]
}

解決方案:

  • 模型 "gpt-4" 不支援該參數。需要使用 gpt-3.5-turbo-1106gpt-4-1106-previewgpt-4o
{
    "model": "gpt-4-1106-preview",
    "max_tokens": 1000,
    "temperature": 0.9,
    "response_format": { "type": "json_object" },
    "messages": [
        {"role": "system", "content": "#zh-TW 您是一個有幫助的助手,請幫我摘要文章"},
        {"role": "user", "content": "您的文章內容..."}
    ]
}

如何解決「Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out」[edit]

錯誤訊息:

Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600)

解決方案:

  • 可能是伺服器未在設定的時間內(600 秒)回應,請等待幾分鐘後再嘗試。

如何解決「The model `gtp-4` does not exist」[edit]

  • 錯誤訊息: "The model `gtp-4` does not exist" 或 "The model: `gpt-4` does not exist"
{
  "error": {
    "message": "The model: `gpt-4` does not exist",
    "type": "invalid_request_error",
    "param": null,
    "code": "model_not_found"
  }
}

解決方案:

如何解決「該模型當前因其他請求超載」[edit]

錯誤訊息:

{
  "error": {
    "message": "That model is currently overloaded with other requests. You can retry your request, or contact us through our help center at help.openai.com if the error persists. (Please include the request ID XXX in your message.)",
    "type": "server_error",
    "param": null,
    "code": null
  }
}

解決方案:

如何解決「RateLimitError: Rate limit reached for default-gpt-3.5-turbo」[edit]

錯誤訊息:RateLimitError: Rate limit reached for default-gpt-3.5-turbo

RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-XXX on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method.

其他類似錯誤訊息:

Rate limit reached for default-gpt-4 in organization org-xxx on tokens per min. Limit: 40000 / min. Please try again in 1ms. Contact us through our help center at help.openai.com if you continue to have issues.

解決方案:

  • 調整 API 請求的頻率。在腳本中加入 Sleep 函數於每次 API 請求之間。更多關於速率限制的資訊,請參考 OpenAI 文件:[1].
  • 了解如何在程式中隨機 Sleep 若干秒以避免速率限制。

如何解決「You exceeded your current quota, please check your plan and billing details.」[edit]

錯誤訊息:

{
  "error": {
    "message": "You exceeded your current quota, please check your plan and billing details.",
    "type": "insufficient_quota",
    "param": null,
    "code": null
  }
}

解決方案: 1. 訪問 https://platform.openai.com/account/usage 檢視 API 使用量。 2. 查找 "OpenAI API - Hard Limit Notice" 電子郵件,並根據內含表單申請額度增加。 3. 獲得額度增加後,前往 https://platform.openai.com/account/billing/limits 調整您的硬性限制。

如何解決「zsh: command not found: -d」[edit]

執行以下指令時遇到錯誤:

curl https://api.openai.com/v1/vector_stores \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2" 
  -d '{
    "name": "Enter your preferred name here"
  }'

錯誤訊息:

zsh: command not found: -d

修正後的指令:

curl https://api.openai.com/v1/vector_stores \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
    "name": "Enter your preferred name here"
  }'

解釋:

  • 每行結尾的反斜線 \ 表示指令尚未完成,會延續到下一行。確保 `-d` 參數或其他參數之後沒有多餘字符或指令,避免類似錯誤。

如何解決「強制保持繁體中文輸出」[edit]

  • 在問題前加上 #zh-TW。[1]
  • 或指定「使用臺灣常用的繁體中文」。

範例:

請使用台灣常用的繁體中文:

規則:
- 使用全形標點符號,中英文之間加入空格。
- 以下是常見的 AI 相關術語詞彙對應表(English -> 中文):
  * Transformer -> Transformer
  * Token -> Token
  * LLM/Large Language Model -> 大語言模型
  * Zero-shot -> 零樣本
  * Few-shot -> 少樣本
  * AI Agent -> AI 代理
  * AGI -> 通用人工智慧

延伸閱讀[edit]

參考資料[edit]