Browse Source

make error message start with <ERROR> so they get excluded from chat log

master
Hendrik Langer 2 years ago
parent
commit
eabc641320
  1. 2
      matrix_pygmalion_bot/ai/koboldcpp.py
  2. 16
      matrix_pygmalion_bot/ai/runpod_pygmalion.py
  3. 2
      matrix_pygmalion_bot/core.py

2
matrix_pygmalion_bot/ai/koboldcpp.py

@ -65,7 +65,7 @@ async def generate_sync(
try: try:
r = requests.post(endpoint, json=input_data, headers=headers, timeout=360) r = requests.post(endpoint, json=input_data, headers=headers, timeout=360)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
raise ValueError(f"<HTTP ERROR> {e}") raise ValueError(f"<ERROR> HTTP ERROR {e}")
r_json = r.json() r_json = r.json()
logger.info(r_json) logger.info(r_json)
if r.status_code == 200: if r.status_code == 200:

16
matrix_pygmalion_bot/ai/runpod_pygmalion.py

@ -95,8 +95,8 @@ async def generate_sync(
else: else:
err_msg = r_json["error"] if "error" in r_json else "" err_msg = r_json["error"] if "error" in r_json else ""
err_msg = err_msg.replace("\\n", "\n") err_msg = err_msg.replace("\\n", "\n")
raise ValueError(f"RETURN CODE {status}: {err_msg}") raise ValueError(f"<ERROR> RETURN CODE {status}: {err_msg}")
raise ValueError(f"<TIMEOUT>") raise ValueError(f"<ERROR> TIMEOUT")
else: else:
raise ValueError(f"<ERROR>") raise ValueError(f"<ERROR>")
@ -137,7 +137,7 @@ async def generate_image(input_prompt: str, negative_prompt: str, api_url: str,
try: try:
r = requests.post(endpoint, json=input_data, headers=headers) r = requests.post(endpoint, json=input_data, headers=headers)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
raise ValueError(f"<HTTP ERROR>") raise ValueError(f"<ERROR> HTTP ERROR")
r_json = r.json() r_json = r.json()
logger.debug(r_json) logger.debug(r_json)
@ -145,7 +145,7 @@ async def generate_image(input_prompt: str, negative_prompt: str, api_url: str,
status = r_json["status"] status = r_json["status"]
if status != 'IN_QUEUE': if status != 'IN_QUEUE':
err_msg = r_json["error"] if "error" in r_json else "" err_msg = r_json["error"] if "error" in r_json else ""
raise ValueError(f"RETURN CODE {status}: {err_msg}") raise ValueError(f"<ERROR> RETURN CODE {status}: {err_msg}")
job_id = r_json["id"] job_id = r_json["id"]
TIMEOUT = 360 TIMEOUT = 360
DELAY = 5 DELAY = 5
@ -167,7 +167,7 @@ async def generate_image(input_prompt: str, negative_prompt: str, api_url: str,
else: else:
err_msg = r_json["error"] if "error" in r_json else "" err_msg = r_json["error"] if "error" in r_json else ""
err_msg = err_msg.replace("\\n", "\n") err_msg = err_msg.replace("\\n", "\n")
raise ValueError(f"RETURN CODE {status}: {err_msg}") raise ValueError(f"<ERROR> RETURN CODE {status}: {err_msg}")
if not output: if not output:
raise ValueError(f"<ERROR>") raise ValueError(f"<ERROR>")
@ -238,7 +238,7 @@ async def serverless_automatic_request(payload, cmd, api_url: str, api_key: str,
try: try:
r = requests.post(endpoint, json=input_data, headers=headers) r = requests.post(endpoint, json=input_data, headers=headers)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
raise ValueError(f"<HTTP ERROR>") raise ValueError(f"<ERROR> HTTP ERROR")
r_json = r.json() r_json = r.json()
logger.debug(r_json) logger.debug(r_json)
@ -246,7 +246,7 @@ async def serverless_automatic_request(payload, cmd, api_url: str, api_key: str,
status = r_json["status"] status = r_json["status"]
if status != 'IN_QUEUE': if status != 'IN_QUEUE':
err_msg = r_json["error"] if "error" in r_json else "" err_msg = r_json["error"] if "error" in r_json else ""
raise ValueError(f"RETURN CODE {status}: {err_msg}") raise ValueError(f"<ERROR> RETURN CODE {status}: {err_msg}")
job_id = r_json["id"] job_id = r_json["id"]
TIMEOUT = 360 TIMEOUT = 360
DELAY = 5 DELAY = 5
@ -267,7 +267,7 @@ async def serverless_automatic_request(payload, cmd, api_url: str, api_key: str,
break break
else: else:
err_msg = r_json["error"] if "error" in r_json else "" err_msg = r_json["error"] if "error" in r_json else ""
raise ValueError(f"RETURN CODE {status}: {err_msg}") raise ValueError(f"<ERROR> RETURN CODE {status}: {err_msg}")
if not output: if not output:
raise ValueError(f"<ERROR> {status}") raise ValueError(f"<ERROR> {status}")

2
matrix_pygmalion_bot/core.py

@ -208,7 +208,7 @@ class Callbacks(object):
chat_message.updateText( event.body.removeprefix('!2').strip() ) chat_message.updateText( event.body.removeprefix('!2').strip() )
api_endpoint = "ynznznpn6qz6yh" api_endpoint = "ynznznpn6qz6yh"
elif event.body.startswith('!'): elif event.body.startswith('!'):
await self.bot.send_message(self.client, room.room_id, "UNKNOWN COMMAND") await self.bot.send_message(self.client, room.room_id, "<ERROR> UNKNOWN COMMAND")
return return
# Other commands # Other commands

Loading…
Cancel
Save