Troubleshooting of OpenAI API in Mandarin: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
Line 284: Line 284:
   * AGI -> 通用人工智慧
   * AGI -> 通用人工智慧


</pre>
== 如何解決 AI 會忘記訓練內容 ==
📝 詢問內容:
<pre>
我想進一步請教一個問題:如果我們採用「層層優化提示詞」這種漸進式的方法來改善AI表現,會不會遇到以下情況:在經過多次提示詞優化後,AI確實學會了相關技能並表現良好,但是過了一段時間後,它又忘記了這些已經訓練好的能力?
我想了解現在各大主流AI模型平台是否都具備穩定的記憶保留功能,也就是說,它們能夠持續記住之前我們給予的訓練提示和指導內容嗎?
我有時候會感覺AI的記憶力似乎不太穩定。在同一個專案進行過程中,明明之前已經向AI詳細說明過的內容和要求,過了一陣子卻需要重新從頭解釋一遍,這讓我對AI的學習持續性產生疑問。
</pre>
💬 回覆內容:
確實,早期的AI模型由於context window(上下文視窗)長度限制較短,很容易出現偏離原本設定方向的情況。當我遇到這種狀況時,我通常會選擇開啟一個全新的對話,重新開始整個互動過程。
現在的AI模型在這方面應該有顯著的改善。如果這次的對話效果令人滿意,我建議你可以給AI下達一個指令,要求它總結並收斂整個對話過程,將對話中累積的互動原則和經驗歸納整合到最初的提示詞中:
<pre>
假設我要開啟一個新的對話來討論相同的主題,請你建議我應該使用怎樣的完整提示詞。
這個提示詞需要包含我們整個討論過程中的重要內容:
(1) 原本提示詞想要解決的核心問題和目標
(2) 與原本問題相關聯,但是一開始的解決方法沒有充分考慮到的重要面向和細節
</pre>
</pre>



Revision as of 10:10, 8 June 2025

OpenAI API 技術問題疑難排解

🌐 Switch language: EN, 漢字


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

如何解決「發生錯誤」

  • 錯誤訊息:"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」

錯誤訊息

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

解決方案:

  • 嘗試重新發送 API 請求。

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

  • 錯誤訊息:'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'"」

  • 錯誤訊息:
{
    "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'」

  • 錯誤訊息:
{
  "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」

錯誤訊息:

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」

錯誤訊息:

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

解決方案:

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

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

  • 錯誤訊息: "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"
  }
}

解決方案:

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

錯誤訊息:

{
  "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」

錯誤訊息: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.」

錯誤訊息:

{
  "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」

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

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` 參數或其他參數之後沒有多餘字符或指令,避免類似錯誤。

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

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

範例:

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

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

延伸閱讀

參考資料