20 lines
731 B
Python
20 lines
731 B
Python
from flask import jsonify, request
|
|
|
|
from . import openai_bp
|
|
from ..helpers.http import validate_json
|
|
from ..openai_request_handler import OpenAIRequestHandler
|
|
|
|
|
|
@openai_bp.route('/chat/completions', methods=['POST'])
|
|
def openai_chat_completions():
|
|
# TODO: make this work with oobabooga
|
|
request_valid_json, request_json_body = validate_json(request)
|
|
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)
|