matrix-gptbot/commands/calculate.py
Kumi bf23771989
Added support for DALL-E and WolframAlpha
New "imagine" and "calculate" commands
Implemented image sending
Moved OpenAI specific code to OpenAI class
Abstracted away OpenAI API in bot class
Minor fixes
2023-04-28 10:01:27 +00:00

34 lines
No EOL
988 B
Python

from nio.events.room_events import RoomMessageText
from nio.rooms import MatrixRoom
async def command_calculate(room: MatrixRoom, event: RoomMessageText, bot):
prompt = event.body.split()[2:]
text = False
results_only = True
if "--text" in prompt:
text = True
delete = prompt.index("--text")
del prompt[delete]
if "--details" in prompt:
results_only = False
delete = prompt.index("--details")
del prompt[delete]
prompt = " ".join(prompt)
if prompt:
bot.logger.log("Querying WolframAlpha")
for subpod in bot.calculation_api.generate_calculation_response(prompt, text, results_only):
bot.logger.log(f"Sending subpod...")
if isinstance(subpod, bytes):
await bot.send_image(room, subpod)
else:
await bot.send_message(room, subpod, True)
return
await bot.send_message(room, "You need to provide a prompt.", True)