Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gemini function call #110

Draft
wants to merge 7 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions BotHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async def send_message_async(
messages: List[Dict],
request_response: RequestResponseContainer.RequestResponseContainer,
end=False,
plain_text=False,
):
"""
Prepare message and send
Expand All @@ -154,7 +155,9 @@ async def send_message_async(
if response_len == 0 and len(request_response.response_images) == 0:
request_response.response = messages["empty_message"]

await _send_prepared_message_async(config, messages, request_response, end)
await _send_prepared_message_async(
config, messages, request_response, end, plain_text
)

# Error?
except Exception as e:
Expand All @@ -169,6 +172,7 @@ async def _send_prepared_message_async(
messages: Dict,
request_response: RequestResponseContainer.RequestResponseContainer,
end=False,
plain_text=False,
):
"""
Sends new message or edits current one
Expand All @@ -181,7 +185,7 @@ async def _send_prepared_message_async(
if not should_send_message(config, request_response, end):
return

markup = build_markup(messages, request_response, end)
markup = build_markup(messages, request_response, end, plain_text)
if markup is not None:
request_response.reply_markup = markup

Expand Down Expand Up @@ -226,6 +230,7 @@ def build_markup(
messages: Dict,
request_response: RequestResponseContainer.RequestResponseContainer,
end=False,
plain_text=False,
) -> InlineKeyboardMarkup:
"""
Build markup for the response
Expand All @@ -234,6 +239,9 @@ def build_markup(
:param end:
:return: InlineKeyboardMarkup
"""
if plain_text:
return None

if not end:
# Generate stop button if it's the first message
if request_response.message_id is None or request_response.message_id < 0:
Expand Down Expand Up @@ -310,15 +318,19 @@ async def parse_img(img_source: str):
:return:
"""
try:
res = requests.head(
img_source,
timeout=10,
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/91.4472.114 Safari/537.36"
},
allow_redirects=True,
loop = asyncio.get_event_loop()
res = await loop.run_in_executor(
None,
lambda: requests.head(
img_source,
timeout=10,
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/91.4472.114 Safari/537.36"
},
allow_redirects=True,
),
)
content_type = res.headers.get("content-type")
if not content_type.startswith("image"):
Expand Down
Loading