-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ AyiinXd/modules/sql_helper/__pycache__/* | |
bin/* | ||
venv | ||
*.pyc | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
# (C) 2020-2023 by TgCatUB@Github. | ||
|
||
import openai | ||
from AyiinXd import CMD_HELP | ||
from .. import var | ||
|
||
openai.api_key = var.OPENAI_API_KEY | ||
conv = {} | ||
|
||
def gen_resp(input_text, chat_id): | ||
global conv | ||
model = "gpt-3.5-turbo" | ||
system_message = None | ||
messages = conv.get(chat_id, []) | ||
if system_message and not messages: | ||
messages.append({"role": "system", "content": system_message}) | ||
messages.append({"role": "user", "content": input_text}) | ||
try: | ||
response = openai.ChatCompletion.create( | ||
model=model, | ||
messages=messages, | ||
) | ||
generated_text = response.choices[0].message.content.strip() | ||
messages.append({"role": "assistant", "content": generated_text}) | ||
conv[chat_id] = messages | ||
except Exception as e: | ||
generated_text = f"`Error generating GPT response: {str(e)}`" | ||
return generated_text | ||
|
||
|
||
def gen_edited_resp(input_text, instructions): | ||
try: | ||
response = openai.Edit.create( | ||
model="text-davinci-edit-001", | ||
input=input_text, | ||
instruction=instructions, | ||
) | ||
edited_text = response.choices[0].text.strip() | ||
except Exception as e: | ||
edited_text = f"Error generating GPT edited response`: {str(e)}`" | ||
return edited_text | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright by (C) 2020-2023 by TgCatUB@Github. | ||
|
||
from AyiinXd import CMD_HELP | ||
from AyiinXd.ayiin import ( | ||
ayiin_cmd, | ||
eod, | ||
eor, | ||
) | ||
from ..ayiin.aihelp import ( | ||
gen_edited_resp, | ||
gen_resp | ||
) | ||
from . import cmd | ||
|
||
|
||
@ayiin_cmd(pattern=r"ai(?:\s|$)([\s\S]*)") | ||
async def chatgpt(event): | ||
text = event.pattern_match.group(1) | ||
reply = await event.get_reply_message() | ||
chat_id = event.chat_id | ||
if "-r" in text: | ||
text = text.replace("-e", "").strip() | ||
if not reply or not reply.text or not text: | ||
return await eod( | ||
event, | ||
"Balas ke pesan dan berikan pesan instruksi setelah tag -e.__", | ||
) | ||
await eor(event, "`Searching edited text..`") | ||
response = gen_edited_resp(reply.text, text) | ||
return await eor(event, response) | ||
if not text and reply: | ||
text = reply.text | ||
if not text: | ||
return await eod(event, "Berikan Saya sebuah text ") | ||
|
||
ayiinevent = await eor(event, "__Searching...__") | ||
gptresp = gen_resp(text, chat_id) | ||
await eor(ayiinevent, gptresp) | ||
|
||
CMD_HELP.update( | ||
{ | ||
"Open AI": f"**Plugin : **`Open AI`\ | ||
\n\n » **Perintah :** `{cmd}ai` <berikan text>\ | ||
\n » **Kegunaan : **Untuk Bertanya Kepada ChatGPT.\ | ||
\n\n » **Perintah :** `{cmd}ai -r` <sambil reply chat>\ | ||
\n » **Kegunaan : **Untuk Bertanya Kepada ChatGPT dari pertanyaan orang pesan orang lain.\ | ||
" | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ markdown | |
natsort | ||
nekos.py | ||
opencv-python-headless | ||
openai | ||
pafy | ||
pendulum | ||
pillow==9.5.0 | ||
|