mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2025-12-29 17:44:50 +00:00
[MissKaty] Replace Bard With Gemini AI and Change ENV Name
This commit is contained in:
parent
40edaae63a
commit
e7f5492496
3 changed files with 36 additions and 18 deletions
|
|
@ -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
|
* `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`
|
* `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
|
* `SUDO`: User ID that have access to bot, split by space
|
||||||
* `OPENAI_API`: Get it from OpenAI Web
|
* `OPENAI_KEY`: Get api key from https://platform.openai.com/account/api-keys
|
||||||
* `BARD_API`: Learn from this https://github.com/dsdanielpark/Bard-API to get cookies and set it as api key.
|
* `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
|
* `CURRENCY_API`: Get API Key from https://app.exchangerate-api.com/sign-up
|
||||||
|
|
||||||
## [7] Tutorial Deploy (Recommended using Docker/Docker Compose)
|
## [7] Tutorial Deploy (Recommended using Docker/Docker Compose)
|
||||||
|
|
|
||||||
|
|
@ -14,30 +14,48 @@ from pyrogram.types import Message
|
||||||
from misskaty import app
|
from misskaty import app
|
||||||
from misskaty.core import pyro_cooldown
|
from misskaty.core import pyro_cooldown
|
||||||
from misskaty.helper import check_time_gap, fetch, post_to_telegraph, use_chat_lang
|
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
|
__MODULE__ = "ChatBot"
|
||||||
@app.on_message(filters.command("bard", COMMAND_HANDLER) & pyro_cooldown.wait(10))
|
__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()
|
@use_chat_lang()
|
||||||
async def bard_chatbot(_, ctx: Message, strings):
|
async def gemini_chatbot(_, ctx: Message, strings):
|
||||||
if len(ctx.command) == 1:
|
if len(ctx.command) == 1:
|
||||||
return await ctx.reply_msg(
|
return await ctx.reply_msg(
|
||||||
strings("no_question").format(cmd=ctx.command[0]), quote=True, del_in=5
|
strings("no_question").format(cmd=ctx.command[0]), quote=True, del_in=5
|
||||||
)
|
)
|
||||||
if not BARD_API:
|
if not GOOGLEAI_KEY:
|
||||||
return await ctx.reply_msg("BARD_API env is missing!!!")
|
return await ctx.reply_msg("GOOGLEAI_KEY env is missing!!!")
|
||||||
msg = await ctx.reply_msg(strings("find_answers_str"), quote=True)
|
msg = await ctx.reply_msg(strings("find_answers_str"), quote=True)
|
||||||
try:
|
try:
|
||||||
req = await fetch.get(
|
params = {
|
||||||
f"https://yasirapi.eu.org/bard?input={ctx.text.split(maxsplit=1)[1]}&key={BARD_API}"
|
'key': GOOGLEAI_KEY,
|
||||||
)
|
}
|
||||||
random_choice = random.choice(req.json().get("choices"))
|
json_data = {
|
||||||
await msg.edit_msg(
|
'contents': [
|
||||||
html.escape(random_choice["content"][0])
|
{
|
||||||
if req.json().get("content") != ""
|
'parts': [
|
||||||
else "Failed getting data from Bard"
|
{
|
||||||
|
'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:
|
except Exception as e:
|
||||||
await msg.edit_msg(str(e))
|
await msg.edit_msg(str(e))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ SUDO = list(
|
||||||
)
|
)
|
||||||
SUPPORT_CHAT = environ.get("SUPPORT_CHAT", "YasirPediaChannel")
|
SUPPORT_CHAT = environ.get("SUPPORT_CHAT", "YasirPediaChannel")
|
||||||
AUTO_RESTART = environ.get("AUTO_RESTART", False)
|
AUTO_RESTART = environ.get("AUTO_RESTART", False)
|
||||||
OPENAI_API = environ.get("OPENAI_API")
|
OPENAI_KEY = environ.get("OPENAI_KEY")
|
||||||
BARD_API = environ.get("BARD_API")
|
GOOGLEAI_KEY = environ.get("GOOGLEAI_KEY")
|
||||||
|
|
||||||
## Config For AUtoForwarder
|
## Config For AUtoForwarder
|
||||||
# Forward From Chat ID
|
# Forward From Chat ID
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue