Delete GPT.py
Browse files
GPT.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 1 |
-
import openai
|
| 2 |
-
import telegram
|
| 3 |
-
from telegram.ext import Updater, MessageHandler
|
| 4 |
-
from telegram.bot import Bot
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
def get_openai_response(message):
|
| 8 |
-
response = openai.Completion.create(
|
| 9 |
-
model="text-davinci-003",
|
| 10 |
-
prompt=f"This is a conversation with an AI assistant. The assistant is helpful, creative, clever and friendly.\nHuman: Hello, can you help me?\nAI: Of course! How may I help you?\nHuman: {message}\nAI: ",
|
| 11 |
-
temperature=0.9,
|
| 12 |
-
max_tokens=1500,
|
| 13 |
-
top_p=1,
|
| 14 |
-
frequency_penalty=0.0,
|
| 15 |
-
presence_penalty=0.6,
|
| 16 |
-
stop=[" Human:", " AI:"]
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
# Return the response generated by openai
|
| 20 |
-
return (response["choices"][0]["text"])
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def send_telegram_message(chat_id, message):
|
| 24 |
-
bot.send_message(chat_id=chat_id, text=message)
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
def handle_telegram_message(update, context):
|
| 28 |
-
# Verify that the update is a message and has the required attributes
|
| 29 |
-
if isinstance(update.message, telegram.Message) and update.message.chat_id and update.message.text:
|
| 30 |
-
# Get the chat ID and message from the update
|
| 31 |
-
chat_id = update.message.chat_id
|
| 32 |
-
text = update.message.text
|
| 33 |
-
|
| 34 |
-
# Get the response from openai
|
| 35 |
-
response = get_openai_response(text)
|
| 36 |
-
|
| 37 |
-
# Send the response back to the user
|
| 38 |
-
send_telegram_message(chat_id, response)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
if __name__ == "__main__":
|
| 42 |
-
# Replace <YOUR_API_TOKEN> with your openai API token
|
| 43 |
-
openai.api_key = "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"
|
| 44 |
-
|
| 45 |
-
# Replace <YOUR_TELEGRAM_BOT_TOKEN> with your Telegram bot's token
|
| 46 |
-
bot = Bot(token="6244576299:AAHHH_z2mKlyUihCtD2_9Vztzw8BVFrG9lE")
|
| 47 |
-
|
| 48 |
-
# Create an updater object to handle updates
|
| 49 |
-
updater = Updater(bot=bot, request_kwargs={'pool_size': 8})
|
| 50 |
-
|
| 51 |
-
# Create a message handler that will call the `handle_message` function
|
| 52 |
-
# whenever a new message is received
|
| 53 |
-
message_handler = MessageHandler(filters=None, callback=handle_telegram_message)
|
| 54 |
-
|
| 55 |
-
# Tell the updater to use the message handler
|
| 56 |
-
updater.dispatcher.add_handler(message_handler)
|
| 57 |
-
|
| 58 |
-
# Start the updater, which will listen for new messages and call
|
| 59 |
-
# the `handle_telegram_message` function when a new message is received
|
| 60 |
-
updater.start_polling()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|