Last active
March 8, 2023 14:03
-
-
Save jibeetz/d2aa59bc7bfa191fd29757243576f0c5 to your computer and use it in GitHub Desktop.
Basic TelegramGPT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install node-telegram-bot-api openai | |
node index.js | |
-------------------- | |
index.js | |
const TelegramBot = require('node-telegram-bot-api') | |
const { Configuration, OpenAIApi } = require('openai') | |
const OPENAI_TOKEN = <OPENAI-TOKEN> | |
const BOT_TOKEN = <BOT-TOKEN> | |
const configuration = new Configuration({ | |
apiKey: OPENAI_TOKEN, | |
}) | |
const openai = new OpenAIApi(configuration) | |
const token = BOT_TOKEN | |
const bot = new TelegramBot(token, { polling: true }) | |
bot.on('message', async (msg) => { | |
const completion = await openai.createChatCompletion({ | |
model: 'gpt-3.5-turbo', | |
messages: [{ role: 'user', content: msg.text }], | |
}) | |
bot.sendMessage(msg.chat.id, completion.data.choices[0].message.content) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment