diff --git a/README.md b/README.md index 9f5fe2ec..7d494d9a 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ If you want help me fixing some error in my bot, you can make pull request to th * `DATABASE_NAME`: Name of the database in MongoDB * `COMMAND_HANDLER`: List of handler bot command splitted by space. Ex: `. !` > so bot will respond with `.cmd` or `!cmd` * `SUDO`: User ID that have access to bot, split by space -* `OPENAI_API`: Get it from OpenAI Web -* `BARD_API`: Learn from this https://github.com/dsdanielpark/Bard-API to get cookies and set it as api key. +* `OPENAI_KEY`: Get api key from https://platform.openai.com/account/api-keys +* `GOOGEAI_KEY`: Learn how to get api key from this https://ai.google.dev/tutorials/python_quickstart?hl=en. * `CURRENCY_API`: Get API Key from https://app.exchangerate-api.com/sign-up ## [7] Tutorial Deploy (Recommended using Docker/Docker Compose) diff --git a/misskaty/plugins/chatbot_ai.py b/misskaty/plugins/chatbot_ai.py index 62d5ba4a..a9368f83 100644 --- a/misskaty/plugins/chatbot_ai.py +++ b/misskaty/plugins/chatbot_ai.py @@ -14,30 +14,48 @@ from pyrogram.types import Message from misskaty import app from misskaty.core import pyro_cooldown from misskaty.helper import check_time_gap, fetch, post_to_telegraph, use_chat_lang -from misskaty.vars import BARD_API, COMMAND_HANDLER, OPENAI_API, SUDO +from misskaty.vars import GOOGLEAI_KEY, COMMAND_HANDLER, OPENAI_KEY, SUDO -# This only for testing things, since maybe in future it will got blocked -@app.on_message(filters.command("bard", COMMAND_HANDLER) & pyro_cooldown.wait(10)) +__MODULE__ = "ChatBot" +__HELP__ = """ +/ai - Generate text response from AI using Gemini AI By Google. +/ask - Generate text response from AI using OpenAI. +""" + + +@app.on_message(filters.command("ai", COMMAND_HANDLER) & pyro_cooldown.wait(10)) @use_chat_lang() -async def bard_chatbot(_, ctx: Message, strings): +async def gemini_chatbot(_, ctx: Message, strings): if len(ctx.command) == 1: return await ctx.reply_msg( strings("no_question").format(cmd=ctx.command[0]), quote=True, del_in=5 ) - if not BARD_API: - return await ctx.reply_msg("BARD_API env is missing!!!") + if not GOOGLEAI_KEY: + return await ctx.reply_msg("GOOGLEAI_KEY env is missing!!!") msg = await ctx.reply_msg(strings("find_answers_str"), quote=True) try: - req = await fetch.get( - f"https://yasirapi.eu.org/bard?input={ctx.text.split(maxsplit=1)[1]}&key={BARD_API}" - ) - random_choice = random.choice(req.json().get("choices")) - await msg.edit_msg( - html.escape(random_choice["content"][0]) - if req.json().get("content") != "" - else "Failed getting data from Bard" + params = { + 'key': GOOGLEAI_KEY, + } + json_data = { + 'contents': [ + { + 'parts': [ + { + 'text': ctx.text.split(maxsplit=1)[1], + }, + ], + }, + ], + } + response = await fetch.post( + 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent', + params=params, + json=json_data, + timeout=20.0, ) + await msg.edit_msg(response.json()["candidates"][0]["content"]["parts"][0]["text"]) except Exception as e: await msg.edit_msg(str(e)) diff --git a/misskaty/vars.py b/misskaty/vars.py index 37873fb3..a8180b09 100644 --- a/misskaty/vars.py +++ b/misskaty/vars.py @@ -55,8 +55,8 @@ SUDO = list( ) SUPPORT_CHAT = environ.get("SUPPORT_CHAT", "YasirPediaChannel") AUTO_RESTART = environ.get("AUTO_RESTART", False) -OPENAI_API = environ.get("OPENAI_API") -BARD_API = environ.get("BARD_API") +OPENAI_KEY = environ.get("OPENAI_KEY") +GOOGLEAI_KEY = environ.get("GOOGLEAI_KEY") ## Config For AUtoForwarder # Forward From Chat ID