Spaces:
Running
Running
Update akn/Akeno/chatgpt.py
Browse files- akn/Akeno/chatgpt.py +33 -18
akn/Akeno/chatgpt.py
CHANGED
@@ -31,16 +31,38 @@ from akn.utils.handler import *
|
|
31 |
from akn.utils.logger import LOGS
|
32 |
from akn.utils.prefixprem import command
|
33 |
from akn import Randydev, send_log
|
|
|
|
|
34 |
from config import *
|
35 |
|
36 |
bot = Randydev()
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
async def mistraai(messagestr):
|
39 |
url = "https://private-akeno.randydev.my.id/akeno/mistralai"
|
40 |
payload = {"args": messagestr}
|
41 |
async with aiohttp.ClientSession() as session:
|
42 |
async with session.post(url, json=payload) as response:
|
43 |
-
if response.
|
44 |
return None
|
45 |
return await response.json()
|
46 |
|
@@ -143,37 +165,30 @@ async def chatgpt_old_(client: Client, message: Message):
|
|
143 |
& filters.me
|
144 |
& ~filters.forwarded
|
145 |
)
|
146 |
-
async def
|
147 |
if len(message.command) > 1:
|
148 |
prompt = message.text.split(maxsplit=1)[1]
|
149 |
elif message.reply_to_message:
|
150 |
prompt = message.reply_to_message.text
|
151 |
else:
|
152 |
-
return await message.reply_text("Give ask from
|
153 |
try:
|
154 |
-
|
155 |
-
|
|
|
156 |
with open("chat.txt", "w+", encoding="utf8") as out_file:
|
157 |
-
out_file.write(
|
158 |
await message.reply_document(
|
159 |
document="chat.txt",
|
160 |
disable_notification=True
|
161 |
)
|
162 |
os.remove("chat.txt")
|
163 |
else:
|
164 |
-
await message.reply_text(
|
165 |
except Exception as e:
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
f"**Chat ID**: `{message.chat.id}`\n"
|
170 |
-
f"**Error Response**: {e}"
|
171 |
-
)
|
172 |
-
response = await send_log(user_detail)
|
173 |
-
if response is None:
|
174 |
-
LOGS.warning("Error response")
|
175 |
-
LOGS.info(response)
|
176 |
-
await message.reply_text(str(e))
|
177 |
|
178 |
module = modules_help.add_module("chatgpt", __file__)
|
179 |
module.add_command("ask", "to question from chatgpt-4o")
|
|
|
31 |
from akn.utils.logger import LOGS
|
32 |
from akn.utils.prefixprem import command
|
33 |
from akn import Randydev, send_log
|
34 |
+
from openai import AsyncOpenAI as openai
|
35 |
+
import akenoai.openai as akeno
|
36 |
from config import *
|
37 |
|
38 |
bot = Randydev()
|
39 |
|
40 |
+
async def openailatest(message_str):
|
41 |
+
BASE_PROMPT = f"""
|
42 |
+
You are my name Akeno AI and python language powered by @xtdevs on telegram support and language models GPT-5-ULTRA
|
43 |
+
- off topic free questions
|
44 |
+
- language code etc convert to requests python
|
45 |
+
- fix spell check in word
|
46 |
+
|
47 |
+
{datetime.datetime.now()}
|
48 |
+
"""
|
49 |
+
response = await akeno.OpenAI.run(
|
50 |
+
...,
|
51 |
+
openai_meta=openai,
|
52 |
+
model="gpt-4o-mini-2024-07-18",
|
53 |
+
messages=[
|
54 |
+
{"role": "system", "content": BASE_PROMPT},
|
55 |
+
{"role": "user", "content": message_str}
|
56 |
+
]
|
57 |
+
)
|
58 |
+
return response
|
59 |
+
|
60 |
async def mistraai(messagestr):
|
61 |
url = "https://private-akeno.randydev.my.id/akeno/mistralai"
|
62 |
payload = {"args": messagestr}
|
63 |
async with aiohttp.ClientSession() as session:
|
64 |
async with session.post(url, json=payload) as response:
|
65 |
+
if response.status != 200:
|
66 |
return None
|
67 |
return await response.json()
|
68 |
|
|
|
165 |
& filters.me
|
166 |
& ~filters.forwarded
|
167 |
)
|
168 |
+
async def askren(client: Client, message: Message):
|
169 |
if len(message.command) > 1:
|
170 |
prompt = message.text.split(maxsplit=1)[1]
|
171 |
elif message.reply_to_message:
|
172 |
prompt = message.reply_to_message.text
|
173 |
else:
|
174 |
+
return await message.reply_text("Give ask from GPT-5")
|
175 |
try:
|
176 |
+
response = await openailatest(prompt)
|
177 |
+
output = response
|
178 |
+
if len(output) > 4096:
|
179 |
with open("chat.txt", "w+", encoding="utf8") as out_file:
|
180 |
+
out_file.write(output)
|
181 |
await message.reply_document(
|
182 |
document="chat.txt",
|
183 |
disable_notification=True
|
184 |
)
|
185 |
os.remove("chat.txt")
|
186 |
else:
|
187 |
+
await message.reply_text(output)
|
188 |
except Exception as e:
|
189 |
+
LOGS.error(str(e))
|
190 |
+
return await message.reply_text(str(e))
|
191 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
module = modules_help.add_module("chatgpt", __file__)
|
194 |
module.add_command("ask", "to question from chatgpt-4o")
|