tahaluindo commited on
Commit
8af5e3b
1 Parent(s): 1c1b4b0
Files changed (3) hide show
  1. config.py +3 -0
  2. main.py +42 -0
  3. requirements.txt +0 -0
config.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ TELEGRAM_TOKEN = 'YOUR_TELEGRAM_TOKEN_HERE'
2
+ OPENAI_API_KEY = 'YOUR_OPENAI_API_HERE'
3
+ AUTHORIZED_USERS = [] #INSERT AUTHORIZED USER ID IF REQUIRED
main.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ from aiogram import Bot, types
3
+ from aiogram.dispatcher import Dispatcher
4
+ from aiogram.utils import executor
5
+ from config import TELEGRAM_TOKEN, OPENAI_API_KEY, AUTHORIZED_USERS
6
+
7
+ token = TELEGRAM_TOKEN
8
+ openai.api_key = OPENAI_API_KEY
9
+
10
+ bot = Bot(token)
11
+ dp = Dispatcher(bot)
12
+
13
+ async def is_authorized(user_id):
14
+ if not AUTHORIZED_USERS or user_id in AUTHORIZED_USERS:
15
+ return True
16
+ return False
17
+
18
+ async def generate_response(prompt):
19
+ response = openai.Completion.create(
20
+ model="text-davinci-003",
21
+ prompt=prompt,
22
+ temperature=0.7,
23
+ max_tokens=500,
24
+ top_p=0.9,
25
+ frequency_penalty=0.5,
26
+ presence_penalty=0.6,
27
+ stop=["You:"]
28
+ )
29
+ return response['choices'][0]['text']
30
+
31
+ @dp.message_handler()
32
+ async def send(message: types.Message):
33
+ if not await is_authorized(message.from_user.id):
34
+ await message.answer("Sorry, you don't have permission to use this bot.")
35
+ return
36
+
37
+ conversation_history = f"User: {message.text}\nAI:"
38
+ response = await generate_response(conversation_history)
39
+ await message.answer(response)
40
+
41
+ if __name__ == '__main__':
42
+ executor.start_polling(dp, skip_updates=True)
requirements.txt ADDED
Binary file (702 Bytes). View file