AI plugins updated, now html formatted

This commit is contained in:
Hash Borgir 2024-02-17 18:37:09 -07:00
parent eb81f7aa67
commit 5962eb53ad
3 changed files with 20 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import requests
import json import json
import simplematrixbotlib as botlib import simplematrixbotlib as botlib
import re import re
import markdown2
async def handle_command(room, message, bot, prefix, config): async def handle_command(room, message, bot, prefix, config):
""" """
@ -56,9 +57,10 @@ async def handle_command(room, message, bot, prefix, config):
response.raise_for_status() # Raise HTTPError for bad responses response.raise_for_status() # Raise HTTPError for bad responses
payload = response.json() payload = response.json()
new_text = payload['choices'][0]['text'] new_text = payload['choices'][0]['text']
if new_text.count('\n') > 1: # Check if new_text has more than one paragraph new_text = markdown_to_html(new_text)
new_text = new_text.replace("\n", '<br>') if new_text.count('<p>') > 2: # Check if new_text has more than one paragraph
new_text = re.sub(r"\*\*(.*?)\*\*", r"<strong>\1</strong>", new_text) #new_text = new_text.replace("\n", '<br>')
#new_text = re.sub(r"\*\*(.*?)\*\*", r"<strong>\1</strong>", new_text)
new_text = "<details><summary><strong>🎵Funguy Music GPT🎵<br>⤵Click Here To See Funguy's Response⤵</strong></summary>" + new_text + "</details>" new_text = "<details><summary><strong>🎵Funguy Music GPT🎵<br>⤵Click Here To See Funguy's Response⤵</strong></summary>" + new_text + "</details>"
await bot.api.send_markdown_message(room.room_id, new_text) await bot.api.send_markdown_message(room.room_id, new_text)
else: else:
@ -67,3 +69,8 @@ async def handle_command(room, message, bot, prefix, config):
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
logging.error(f"HTTP request failed for '{prompt}': {e}") logging.error(f"HTTP request failed for '{prompt}': {e}")
await bot.api.send_text_message(room.room_id, f"Error generating text: {e}") await bot.api.send_text_message(room.room_id, f"Error generating text: {e}")
def markdown_to_html(markdown_text):
html_content = markdown2.markdown(markdown_text)
return html_content

View File

@ -9,6 +9,7 @@ import requests
import json import json
import simplematrixbotlib as botlib import simplematrixbotlib as botlib
import re import re
import markdown2
async def handle_command(room, message, bot, prefix, config): async def handle_command(room, message, bot, prefix, config):
""" """
@ -57,9 +58,10 @@ async def handle_command(room, message, bot, prefix, config):
response.raise_for_status() # Raise HTTPError for bad responses response.raise_for_status() # Raise HTTPError for bad responses
payload = response.json() payload = response.json()
new_text = payload['choices'][0]['text'] new_text = payload['choices'][0]['text']
if new_text.count('\n') > 2: # Check if new_text has more than one paragraph new_text = markdown_to_html(new_text)
new_text = new_text.replace("\n", '<br>') if new_text.count('<p>') > 2: # Check if new_text has more than one paragraph
new_text = re.sub(r"\*\*(.*?)\*\*", r"<strong>\1</strong>", new_text) #new_text = new_text.replace("\n", '<br>')
#new_text = re.sub(r"\*\*(.*?)\*\*", r"<strong>\1</strong>", new_text)
new_text = "<details><summary><strong>🍄Funguy Tech GPT🍄<br>⤵Click Here To See Funguy's Response⤵</strong></summary>" + new_text + "</details>" new_text = "<details><summary><strong>🍄Funguy Tech GPT🍄<br>⤵Click Here To See Funguy's Response⤵</strong></summary>" + new_text + "</details>"
await bot.api.send_markdown_message(room.room_id, new_text) await bot.api.send_markdown_message(room.room_id, new_text)
else: else:
@ -68,3 +70,7 @@ async def handle_command(room, message, bot, prefix, config):
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
logging.error(f"HTTP request failed for '{prompt}': {e}") logging.error(f"HTTP request failed for '{prompt}': {e}")
await bot.api.send_text_message(room.room_id, f"Error generating text: {e}") await bot.api.send_text_message(room.room_id, f"Error generating text: {e}")
def markdown_to_html(markdown_text):
html_content = markdown2.markdown(markdown_text)
return html_content

View File

@ -3,3 +3,4 @@ requests
pytube pytube
duckduckgo_search duckduckgo_search
nio nio
markdown2