2023-09-14 14:36:22 -06:00
|
|
|
import traceback
|
|
|
|
|
2023-08-21 21:28:52 -06:00
|
|
|
from flask import jsonify, request
|
|
|
|
|
2023-08-22 20:28:41 -06:00
|
|
|
from . import bp
|
2023-08-30 20:19:23 -06:00
|
|
|
from ..helpers.http import validate_json
|
2023-09-12 16:40:09 -06:00
|
|
|
from ..ooba_request_handler import OobaRequestHandler
|
2023-08-21 21:28:52 -06:00
|
|
|
|
|
|
|
|
2023-09-30 19:41:50 -06:00
|
|
|
@bp.route('/v1/generate', methods=['POST'])
|
|
|
|
@bp.route('/<model_name>/v1/generate', methods=['POST'])
|
|
|
|
def generate(model_name=None):
|
2023-09-12 16:40:09 -06:00
|
|
|
request_valid_json, request_json_body = validate_json(request)
|
2023-09-12 10:30:45 -06:00
|
|
|
if not request_valid_json or not request_json_body.get('prompt'):
|
2023-08-30 20:19:23 -06:00
|
|
|
return jsonify({'code': 400, 'msg': 'Invalid JSON'}), 400
|
|
|
|
else:
|
2023-10-09 23:51:26 -06:00
|
|
|
handler = OobaRequestHandler(request, selected_model=model_name)
|
2023-09-14 14:26:25 -06:00
|
|
|
try:
|
2023-09-27 14:48:47 -06:00
|
|
|
return handler.handle_request()
|
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
return handler.handle_error('Server encountered exception.', 'exception')[0], 500
|