Upload chatgpt.py
Browse files- Akeno/plugins/chatgpt.py +9 -4
Akeno/plugins/chatgpt.py
CHANGED
@@ -88,9 +88,9 @@ async def chatbot_talk(client: Client, message: Message):
|
|
88 |
query = message.text.strip()
|
89 |
try:
|
90 |
genai.configure(api_key=GOOGLE_API_KEY)
|
91 |
-
|
92 |
model_name="gemini-1.5-flash",
|
93 |
-
system_instruction="
|
94 |
safety_settings={
|
95 |
genai.types.HarmCategory.HARM_CATEGORY_HATE_SPEECH: genai.types.HarmBlockThreshold.BLOCK_NONE,
|
96 |
genai.types.HarmCategory.HARM_CATEGORY_HARASSMENT: genai.types.HarmBlockThreshold.BLOCK_NONE,
|
@@ -98,8 +98,11 @@ async def chatbot_talk(client: Client, message: Message):
|
|
98 |
genai.types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: genai.types.HarmBlockThreshold.BLOCK_NONE,
|
99 |
}
|
100 |
)
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
103 |
if len(output) > 4096:
|
104 |
with open("chat.txt", "w+", encoding="utf8") as out_file:
|
105 |
out_file.write(output)
|
@@ -110,6 +113,8 @@ async def chatbot_talk(client: Client, message: Message):
|
|
110 |
os.remove("chat.txt")
|
111 |
else:
|
112 |
await message.reply_text(output)
|
|
|
|
|
113 |
except Exception as e:
|
114 |
LOGS.error(str(e))
|
115 |
return await message.reply_text(str(e))
|
|
|
88 |
query = message.text.strip()
|
89 |
try:
|
90 |
genai.configure(api_key=GOOGLE_API_KEY)
|
91 |
+
model_flash = genai.GenerativeModel(
|
92 |
model_name="gemini-1.5-flash",
|
93 |
+
system_instruction="Kamu seekor kucing. Namamu Neko.",
|
94 |
safety_settings={
|
95 |
genai.types.HarmCategory.HARM_CATEGORY_HATE_SPEECH: genai.types.HarmBlockThreshold.BLOCK_NONE,
|
96 |
genai.types.HarmCategory.HARM_CATEGORY_HARASSMENT: genai.types.HarmBlockThreshold.BLOCK_NONE,
|
|
|
98 |
genai.types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: genai.types.HarmBlockThreshold.BLOCK_NONE,
|
99 |
}
|
100 |
)
|
101 |
+
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
102 |
+
backup_chat.append({"role": "user", "parts": [{"text": query}]})
|
103 |
+
chat_session = model_flash.start_chat(history=backup_chat)
|
104 |
+
response_data = chat_session.send_message(query)
|
105 |
+
output = response_data.text
|
106 |
if len(output) > 4096:
|
107 |
with open("chat.txt", "w+", encoding="utf8") as out_file:
|
108 |
out_file.write(output)
|
|
|
113 |
os.remove("chat.txt")
|
114 |
else:
|
115 |
await message.reply_text(output)
|
116 |
+
backup_chat.append({"role": "model", "parts": [{"text": output}]})
|
117 |
+
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
118 |
except Exception as e:
|
119 |
LOGS.error(str(e))
|
120 |
return await message.reply_text(str(e))
|