Spaces:
Runtime error
Runtime error
Commit
·
1ec7fd7
1
Parent(s):
b460e0e
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from telegram.ext import Updater, MessageHandler, Filters
|
2 |
+
import openai
|
3 |
+
|
4 |
+
openai.api_key = "<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>"
|
5 |
+
TELEGRAM_API_TOKEN = "<6074730982:AAGKU2_gpogdkTQvmE4Ya63n9ot2dHVzA7I>"
|
6 |
+
|
7 |
+
def text_message(update, context):
|
8 |
+
response = openai.ChatCompletion.create(
|
9 |
+
model="gpt-3.5-turbo",
|
10 |
+
messages= [{"role": "system", "content": "Ass a silly phrase after each one of your answers"}]
|
11 |
+
)
|
12 |
+
update.message.reply_text(response["choices"][0]["message"]["content"])
|
13 |
+
|
14 |
+
|
15 |
+
updater = Updater(TELEGRAM_API_TOKEN, use_context=True)
|
16 |
+
dispatcher = updater.dispatcher
|
17 |
+
dispatcher.add_handler(MessageHandler(Filters.text & (~Filters.command), text_message))
|
18 |
+
updater.start_polling()
|
19 |
+
updater.idle()
|