horde error handling

This commit is contained in:
Divided by Zer0 2022-09-10 10:03:46 +02:00
parent 4851c1dd46
commit 13ca465980
1 changed files with 21 additions and 9 deletions

View File

@ -5175,21 +5175,33 @@ def sendtocluster(txt, min, max):
'api_key': vars.apikey, 'api_key': vars.apikey,
'models': vars.cluster_requested_models, 'models': vars.cluster_requested_models,
} }
try:
# Create request # Create request
req = requests.post( req = requests.post(
vars.colaburl[:-8] + "/generate/sync", vars.colaburl[:-8] + "/generate/sync",
json=cluster_metadata, json=cluster_metadata,
) )
js = req.json() js = req.json()
except requests.exceptions.ConnectionError:
errmsg ="Horde unavailable. Please try again later"
print("{0}{1}{2}".format(colors.RED, json.dumps(js, indent=2), colors.END))
emit('from_server', {'cmd': 'errmsg', 'data': errmsg}, broadcast=True)
set_aibusy(0)
return
except requests.exceptions.JSONDecodeError:
errmsg ="Unexpected message received from the Horde: '{req.text}'"
print("{0}{1}{2}".format(colors.RED, json.dumps(js, indent=2), colors.END))
emit('from_server', {'cmd': 'errmsg', 'data': errmsg}, broadcast=True)
set_aibusy(0)
return
if(req.status_code == 503): if(req.status_code == 503):
errmsg = "KoboldAI API Error: No available KoboldAI servers found in cluster to fulfil this request using the selected models and requested lengths." errmsg = "KoboldAI API Error: No available KoboldAI servers found in Horde to fulfil this request using the selected models or other properties."
print("{0}{1}{2}".format(colors.RED, json.dumps(js, indent=2), colors.END)) print("{0}{1}{2}".format(colors.RED, json.dumps(js, indent=2), colors.END))
emit('from_server', {'cmd': 'errmsg', 'data': errmsg}, broadcast=True) emit('from_server', {'cmd': 'errmsg', 'data': errmsg}, broadcast=True)
set_aibusy(0) set_aibusy(0)
return return
if(req.status_code != 200): if(req.status_code != 200):
errmsg = "KoboldAI API Error: Failed to get a reply from the server. Please check the console." errmsg = "KoboldAI API Error: Failed to get a standard from the Horde. Please check the console."
print("{0}{1}{2}".format(colors.RED, json.dumps(js, indent=2), colors.END)) print("{0}{1}{2}".format(colors.RED, json.dumps(js, indent=2), colors.END))
emit('from_server', {'cmd': 'errmsg', 'data': errmsg}, broadcast=True) emit('from_server', {'cmd': 'errmsg', 'data': errmsg}, broadcast=True)
set_aibusy(0) set_aibusy(0)