check if the backend crapped out, print some more stuff
This commit is contained in:
parent
79b1e01b61
commit
93a344f4c5
|
@ -23,7 +23,7 @@ class RedisWrapper:
|
|||
self.set('____', 1)
|
||||
except redis_pkg.exceptions.ConnectionError as e:
|
||||
print('Failed to connect to the Redis server:', e)
|
||||
print('Did you install and start Redis?')
|
||||
print('Did you install and start the Redis server?')
|
||||
sys.exit(1)
|
||||
|
||||
def _key(self, key):
|
||||
|
|
|
@ -5,14 +5,6 @@ from ..helpers.http import validate_json
|
|||
from ..openai_request_handler import OpenAIRequestHandler
|
||||
|
||||
|
||||
class FakeFlaskRequest():
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.data = kwargs.get('data')
|
||||
self.headers = kwargs.get('headers')
|
||||
self.json = kwargs.get('json')
|
||||
self.remote_addr = kwargs.get('remote_addr')
|
||||
|
||||
|
||||
@openai_bp.route('/chat/completions', methods=['POST'])
|
||||
def openai_chat_completions():
|
||||
# TODO: make this work with oobabooga
|
||||
|
@ -20,4 +12,8 @@ def openai_chat_completions():
|
|||
if not request_valid_json or not request_json_body.get('messages'):
|
||||
return jsonify({'code': 400, 'msg': 'invalid JSON'}), 400
|
||||
else:
|
||||
try:
|
||||
return OpenAIRequestHandler(request).handle_request()
|
||||
except Exception as e:
|
||||
print(f'EXCEPTION on {request.url}!!!', f'{e.__class__.__name__}: {e}')
|
||||
print(request.data)
|
||||
|
|
|
@ -122,9 +122,18 @@ class RequestHandler:
|
|||
# ===============================================
|
||||
|
||||
response_valid_json, response_json_body = validate_json(response)
|
||||
return_json_err = False
|
||||
|
||||
# The backend didn't send valid JSON
|
||||
if not response_valid_json:
|
||||
return_json_err = True
|
||||
|
||||
# Make sure the backend didn't crap out.
|
||||
results = response_json_body.get('results', [])
|
||||
if len(results) and not results[0].get('text'):
|
||||
return_json_err = True
|
||||
|
||||
if return_json_err:
|
||||
error_msg = 'The backend did not return valid JSON.'
|
||||
backend_response = format_sillytavern_err(error_msg, 'error')
|
||||
log_prompt(self.client_ip, self.token, prompt, backend_response, elapsed_time, self.parameters, dict(self.request.headers), response_status_code, self.request.url, is_error=True)
|
||||
|
|
|
@ -3,7 +3,6 @@ from flask import jsonify, request
|
|||
from . import bp
|
||||
from ..helpers.http import validate_json
|
||||
from ..ooba_request_handler import OobaRequestHandler
|
||||
from ... import opts
|
||||
|
||||
|
||||
@bp.route('/generate', methods=['POST'])
|
||||
|
@ -12,5 +11,8 @@ def generate():
|
|||
if not request_valid_json or not request_json_body.get('prompt'):
|
||||
return jsonify({'code': 400, 'msg': 'Invalid JSON'}), 400
|
||||
else:
|
||||
handler = OobaRequestHandler(request)
|
||||
return handler.handle_request()
|
||||
try:
|
||||
return OobaRequestHandler(request).handle_request()
|
||||
except Exception as e:
|
||||
print(f'EXCEPTION on {request.url}!!!', f'{e.__class__.__name__}: {e}')
|
||||
print(request.data)
|
||||
|
|
Reference in New Issue