memochou1993 / gpt-ai-assistant

OpenAI + LINE + Vercel = GPT AI Assistant
https://memochou1993.github.io/gpt-ai-assistant-docs/
MIT License
7.42k stars 9.55k forks source link

[Ask] AxiosError: Request failed with status code 429 #2

Closed michaeloil closed 1 year ago

michaeloil commented 1 year ago

感謝大大的教學,不過我實際安裝起來再送訊息後,從vercel的後台會一直收到Request failed with status code 429的錯誤,不知道應可能是什麼錯誤造成的,再麻煩你幫忙了,謝謝

2022-12-11T12:50:46.500Z fb711c34-d5be-4f52-8193-3e8235f6ff43 ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"AxiosError: Request failed with status code 429","reason":{"message":"Request failed with status code 429","name":"AxiosError","stack":"AxiosError: Request failed with status code 429\n at settle (file:///var/task/node_modules/axios/lib/core/settle.js:19:12)\n at IncomingMessage.handleStreamEnd (file:///var/task/node_modules/axios/lib/adapters/http.js:505:11)\n at IncomingMessage.emit (node:events:525:35)\n at endReadableNT (node:internal/streams/readable:1359:12)\n at process.processTicksAndRejections (node:internal/process/task_queues:82:21)","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["xhr","http"],"transformRequest":[null],"transformResponse":[null],"timeout":60000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"env":{},"headers":{"Accept":"application/json, text/plain, /","Content-Type":"application/json","Authorization":"Bearer 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","User-Agent":"axios/1.2.1","Content-Length":"212","Accept-Encoding":"gzip, compress, deflate, br"},"baseURL":"https://api.openai.com","method":"post","url":"/v1/completions","data":"{\"model\":\"text-davinci-003\",\"prompt\":\"AI: 嗨!我可以怎麼幫助你?\nHuman: 請教我英文?\n\",\"temperature\":0.9,\"max_tokens\":240,\"frequency_penalty\":0,\"presence_penalty\":0.6,\"stop\":[\" AI:\",\" Human:\"]}"},"code":"ERR_BAD_REQUEST","status":429},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: AxiosError: Request failed with status code 429"," at process. (file:///var/runtime/index.mjs:1194:17)"," at process.emit (node:events:525:35)"," at emit (node:internal/process/promises:149:20)"," at processPromiseRejections (node:internal/process/promises:283:27)"," at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]} Unknown application error occurred Runtime.Unknown

memochou1993 commented 1 year ago

@michaeloil

嗨!

幫我檢查你的環境變數是否有將 LINE_API_KEY 設置為 LINE 的 Channel access token?

MIBlue119 commented 1 year ago

非常謝謝原PO分享這個流程~! 想借樓詢問,目前有在本地測試成功(openai那可以拿到response),不過部署至vercel後 在Line Messaging API那verify時會有這樣的回覆,想詢問看看這也會是Line acces token的問題嗎,非常謝謝您

圖片
memochou1993 commented 1 year ago

@MIBlue119

嗨!

這代表 LINE 請求程式的 Webhook URL 時失敗了,請幫我檢查你的 Webhook URL 有沒有設置成自己的應用程式網址,並且尾巴要帶有 /webhook 後綴。

michaeloil commented 1 year ago

@memochou1993 Hi, LINE_API_KEY應該有設定成功,從vercel可以看到,reissue也redeploy過了,錯誤訊息一樣還是AxiosError: Request failed with status code 429,不知道還有沒有什麼其他可能性會造成這個問題?感謝

MIBlue119 commented 1 year ago

@memochou1993 非常感謝您!

圖片
memochou1993 commented 1 year ago

@MIBlue119 恭喜!

Ken-ChangCK commented 1 year ago

[Ask for help] 感謝原PO分享教學。 我也有遇到跟樓主一樣的情況。 Line Webhook 和 Vercel皆驗證/部署成功, 並且已在vercel設定環境變數, 但是錯誤訊息裡面的 Authorization 後面的欄位數值卻跟vercel後台環境變數裡面的OPENAI_API_KEY一樣。 不知道是哪裡設定錯誤,再請你幫忙看一下,謝謝

截圖 2022-12-11 下午11 35 49

LINE 的 Channel access token 截圖 2022-12-11 下午11 34 33

chengcheng1231 commented 1 year ago

遇到相同狀況,我在想 header 應該是要抓 line 的 token,反而抓了 open ai 的 token? @memochou1993

memochou1993 commented 1 year ago

@chengcheng1231

嗨!我重新看了一次你貼的錯誤訊息,發現這是呼叫 OpenAI 時的問題。

代碼 429 代表請求次數過多,所以被擋了下來。

可以麻煩幫我照著文件執行以下步驟,然後在本地執行測試看看嗎?

開發

下載專案。

git@github.com:memochou1993/ai-assistant.git

進到專案目錄。

cd ai-assistant

安裝依賴套件。

npm ci

建立 .env 檔。

cp .env.example .env

設置相關環境變數。

APP_ENV=local
APP_DEBUG=true
APP_PORT=3000
OPENAI_API_KEY=<your_openai_api_key>
LINE_API_KEY=<empty_string>

測試

執行以下指令,執行測試,並且向 OpenAI 伺服器發送請求。

npm run test

查看結果。

memochou1993 commented 1 year ago

@Ken-ChangCK

嗨!你的環境變數設置是對的!

一樣也遇到了 429 的問題,也麻煩幫我在本地執行測試看看。

Ken-ChangCK commented 1 year ago

好的,但我在本地也是run 也是 429

截圖 2022-12-12 上午12 10 49

P.s. 請求次數太多😓 https://community.openai.com/t/how-to-fix-http-429-error/22790

memochou1993 commented 1 year ago

@Ken-ChangCK

嗨,可以幫我在 chat 方法裡加上這條 log,再跑一次測試,查看這個遞迴函式執行了幾次嗎?

console.log('choice', choice);
image
Ken-ChangCK commented 1 year ago

[已解決] 我在 open AI 裡面新增太多 API key,所以才可能造成 429問題,刪掉一些key後重新部署就沒問題了, 謝謝!

Note: 我倒是沒有註冊信用卡!

memochou1993 commented 1 year ago

@Ken-ChangCK

太好了!

Jakevin commented 1 year ago

========更新===========

自問自答: OpenGPT 登入信用卡後就正常了

============================ 我也遇到 openGPT那邊回傳 429的狀況

截圖 2022-12-12 下午3 05 58

key也只有一個

截圖 2022-12-12 下午3 06 49
memochou1993 commented 1 year ago

@Jakevin

感謝分享!

不過這樣是不是一超過用量,就會被扣款呀?

Jakevin commented 1 year ago

是的,但就當作學費吧 wwwww

chengcheng1231 commented 1 year ago

我也透過 @Jakevin 的方式解決!感謝!但我將 paid account cancel 了,這樣也還是可以用,只是不曉得這樣還會不會被扣款

也感謝 @memochou1993 的source code & 教學!

michaeloil commented 1 year ago

感謝分享, @Jakevin 的方法解決了429的狀況,也感謝 @memochou1993 的分享與教學

lisashih commented 1 year ago

沒程式底子的新手想請教,還請高抬貴手QQ 我下載專案後沒有看到ai-assistant的檔案?接下來的步驟都不知道要如何在終端機debug

memochou1993 commented 1 year ago

@lisashih

嗨,你有 fork 專案了嗎?

lisashih commented 1 year ago

有的,已經fork了!

memochou1993 commented 1 year ago

@lisashih

請到 Versel 匯入專案喔!