Update Akeno/plugins/cohere.py
Browse files- Akeno/plugins/cohere.py +14 -3
Akeno/plugins/cohere.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import asyncio
|
|
|
2 |
from json import tool
|
3 |
from Akeno.utils.handler import *
|
4 |
from Akeno.utils.database import db
|
@@ -21,19 +22,29 @@ async def coheres_(c: Client, message: Message):
|
|
21 |
prompt = message.reply_to_message.text
|
22 |
else:
|
23 |
await message.edit_text(
|
24 |
-
f"<b>Usage: </b><code
|
25 |
)
|
26 |
return
|
27 |
chat_history.append({"role": "USER", "message": prompt})
|
28 |
-
await message.edit_text("<code>
|
29 |
response = co.chat(
|
30 |
chat_history=chat_history,
|
31 |
model="command-r-plus",
|
32 |
message=prompt
|
33 |
)
|
34 |
output = response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
chat_history.append({"role": "CHATBOT", "message": output})
|
36 |
await db._update_cohere_chat_in_db(user_id, chat_history)
|
37 |
-
await message.edit_text(output, disable_web_page_preview=True)
|
38 |
except Exception as e:
|
39 |
await message.edit_text(f"An error occurred: {e}")
|
|
|
1 |
import asyncio
|
2 |
+
import os
|
3 |
from json import tool
|
4 |
from Akeno.utils.handler import *
|
5 |
from Akeno.utils.database import db
|
|
|
22 |
prompt = message.reply_to_message.text
|
23 |
else:
|
24 |
await message.edit_text(
|
25 |
+
f"<b>Usage: </b><code>.cohere [prompt/reply to message]</code>"
|
26 |
)
|
27 |
return
|
28 |
chat_history.append({"role": "USER", "message": prompt})
|
29 |
+
pro = await message.edit_text("<code>Processing...</code>")
|
30 |
response = co.chat(
|
31 |
chat_history=chat_history,
|
32 |
model="command-r-plus",
|
33 |
message=prompt
|
34 |
)
|
35 |
output = response.text
|
36 |
+
if len(output) > 4096:
|
37 |
+
with open("chat.txt", "w+", encoding="utf8") as out_file:
|
38 |
+
out_file.write(output)
|
39 |
+
await message.reply_document(
|
40 |
+
document="chat.txt",
|
41 |
+
disable_notification=True
|
42 |
+
)
|
43 |
+
await pro.delete()
|
44 |
+
os.remove("chat.txt")
|
45 |
+
else:
|
46 |
+
await message.edit_text(output, disable_web_page_preview=True)
|
47 |
chat_history.append({"role": "CHATBOT", "message": output})
|
48 |
await db._update_cohere_chat_in_db(user_id, chat_history)
|
|
|
49 |
except Exception as e:
|
50 |
await message.edit_text(f"An error occurred: {e}")
|