Drag
commited on
Commit
·
07829e3
1
Parent(s):
9a5da4b
Update and rename chatbot.py.txt to chatbot.py
Browse files
Mikobot/plugins/{chatbot.py.txt → chatbot.py}
RENAMED
@@ -1,8 +1,8 @@
|
|
1 |
# <============================================== IMPORTS =========================================================>
|
2 |
import asyncio
|
3 |
import html
|
4 |
-
import json
|
5 |
import re
|
|
|
6 |
from typing import Optional
|
7 |
|
8 |
import requests
|
@@ -31,7 +31,6 @@ from Mikobot.plugins.log_channel import gloggable
|
|
31 |
|
32 |
# <=======================================================================================================>
|
33 |
|
34 |
-
|
35 |
# <================================================ FUNCTION =======================================================>
|
36 |
@gloggable
|
37 |
async def kukirm(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
@@ -49,7 +48,7 @@ async def kukirm(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
49 |
)
|
50 |
else:
|
51 |
await update.effective_message.edit_text(
|
52 |
-
f"Chatbot
|
53 |
parse_mode=ParseMode.HTML,
|
54 |
)
|
55 |
|
@@ -72,7 +71,7 @@ async def kukiadd(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
72 |
)
|
73 |
else:
|
74 |
await update.effective_message.edit_text(
|
75 |
-
f"Hey Darling Chatbot
|
76 |
parse_mode=ParseMode.HTML,
|
77 |
)
|
78 |
|
@@ -97,6 +96,31 @@ async def kuki(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
97 |
)
|
98 |
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
async def kuki_message(context: ContextTypes.DEFAULT_TYPE, message):
|
101 |
reply_message = message.reply_to_message
|
102 |
if message.text.lower() == "kuki":
|
@@ -122,15 +146,14 @@ async def chatbot(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
122 |
return
|
123 |
Message = message.text
|
124 |
await bot.send_chat_action(chat_id, action="typing")
|
125 |
-
kukiurl = requests.get(
|
126 |
-
f"http://api.brainshop.ai/get?bid=176809&key=lbMN8CXTGzhn1NKG&uid=[user]&msg={Message}"
|
127 |
-
)
|
128 |
|
129 |
-
|
130 |
-
|
|
|
|
|
131 |
|
132 |
await asyncio.sleep(0.3)
|
133 |
-
await message.reply_text(
|
134 |
|
135 |
|
136 |
async def list_all_chats(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
|
1 |
# <============================================== IMPORTS =========================================================>
|
2 |
import asyncio
|
3 |
import html
|
|
|
4 |
import re
|
5 |
+
import json
|
6 |
from typing import Optional
|
7 |
|
8 |
import requests
|
|
|
31 |
|
32 |
# <=======================================================================================================>
|
33 |
|
|
|
34 |
# <================================================ FUNCTION =======================================================>
|
35 |
@gloggable
|
36 |
async def kukirm(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
|
48 |
)
|
49 |
else:
|
50 |
await update.effective_message.edit_text(
|
51 |
+
f"Chatbot disabled by {mention_html(user.id, user.first_name)}.",
|
52 |
parse_mode=ParseMode.HTML,
|
53 |
)
|
54 |
|
|
|
71 |
)
|
72 |
else:
|
73 |
await update.effective_message.edit_text(
|
74 |
+
f"Hey Darling Chatbot enabled by {mention_html(user.id, user.first_name)}.",
|
75 |
parse_mode=ParseMode.HTML,
|
76 |
)
|
77 |
|
|
|
96 |
)
|
97 |
|
98 |
|
99 |
+
async def fetch_chatgpt_response(prompt: str) -> str:
|
100 |
+
"""Fetches response from OpenAI's ChatGPT API."""
|
101 |
+
openai_api_url = "https://api.openai.com/v1/chat/completions"
|
102 |
+
openai_api_key = "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" # Replace with your OpenAI API key
|
103 |
+
|
104 |
+
headers = {
|
105 |
+
"Authorization": f"Bearer {openai_api_key}",
|
106 |
+
"Content-Type": "application/json",
|
107 |
+
}
|
108 |
+
|
109 |
+
payload = {
|
110 |
+
"model": "gpt-3.5-turbo", # Specify the model (e.g., gpt-3.5-turbo)
|
111 |
+
"messages": [{"role": "user", "content": prompt}],
|
112 |
+
"temperature": 0.7, # Adjust for creativity
|
113 |
+
}
|
114 |
+
|
115 |
+
async with requests.Session() as session:
|
116 |
+
async with session.post(openai_api_url, headers=headers, json=payload) as response:
|
117 |
+
if response.status_code == 200:
|
118 |
+
data = await response.json()
|
119 |
+
return data["choices"][0]["message"]["content"].strip()
|
120 |
+
else:
|
121 |
+
return "I'm having trouble connecting to ChatGPT right now."
|
122 |
+
|
123 |
+
|
124 |
async def kuki_message(context: ContextTypes.DEFAULT_TYPE, message):
|
125 |
reply_message = message.reply_to_message
|
126 |
if message.text.lower() == "kuki":
|
|
|
146 |
return
|
147 |
Message = message.text
|
148 |
await bot.send_chat_action(chat_id, action="typing")
|
|
|
|
|
|
|
149 |
|
150 |
+
try:
|
151 |
+
response_text = await fetch_chatgpt_response(Message)
|
152 |
+
except Exception as e:
|
153 |
+
response_text = "Sorry, I couldn't process that request."
|
154 |
|
155 |
await asyncio.sleep(0.3)
|
156 |
+
await message.reply_text(response_text)
|
157 |
|
158 |
|
159 |
async def list_all_chats(update: Update, context: ContextTypes.DEFAULT_TYPE):
|