Skip to content

phppho/Gpt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI-ChatGPT3.5-TelegramBot-Render

一個使用FastAPI框架和GPT3.5 turbo模型官方API,創造一個TelegramBot,快速建置於平台Render。

GPT3 TelegramBot Vercel部署版本。程式猿影音教學參考。請支持且訂閱加按讚感謝他的辛勞。

https://www.youtube.com/watch?v=eKKEa6NhCd0

1. 本專案因部屬在Render上,所以程式碼和Docker版本不同,使用FastAPI和設定webhook。

2. 設定webhook請參考以下網址。Render網站中,選擇新增「Web Services」,可用github帳號匯入此專案,可先fork到自己的帳號,然後設定自己的名稱和選擇免費free方案。記得按下方「Advanced」,設定環境變數。

https://zaoldyeck.medium.com/%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E6%80%8E%E9%BA%BC%E6%89%93%E9%80%A0-telegram-bot-a7b539c3402a

3. 必須在Render的Environment Variables設定兩個環境變數,分別是OPENAI_API_KEY和TELEGRAM_BOT_TOKEN。然後開始部屬,可能要花上一些時間。成功後複製自己的URL。例如:

https://xxx.onrender.com/

4. Start Command請輸入:

uvicorn main:app --host 0.0.0.0

5. 等待完成後,打開瀏覽器,輸入以下網址,設定webhook為部屬完Render的最後步驟,格式為:https://api.telegram.org/bot{$token}/setWebhook?url={$webhook_url}。

故實際範例就像以下範例(非直接複製使用,請改用自己的telegram token和Render專案的URL):

https://api.telegram.org/bot606248605:AAGv_TOJdNNMc_v3toHK_X6M-dev_1tG-JA/setWebhook?url=https://xxx.onrender.com/callback

5. 成功後會顯示以下文字:

{ ok: true, result: true, description: "Webhook was set" }

創建Telegram機器人和取得token,請參考:

https://ithelp.ithome.com.tw/articles/10245264

https://tcsky.cc/tips-01-telegram-chatbot/

FastAPI Render設置請參考:

https://salaivv.com/2023/01/04/telegram-bot-fastapi

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages