add message for /v1/

This commit is contained in:
Cyberes 2023-09-30 21:07:12 -06:00
parent 166b2316e8
commit 592eb08cb1
4 changed files with 16 additions and 9 deletions

View File

@ -2,8 +2,11 @@ from llm_server.cluster.cluster_config import cluster_config
from llm_server.custom_redis import redis
def format_sillytavern_err(msg: str, backend_url: str = 'none', error_type: str = 'info'):
def format_sillytavern_err(msg: str, backend_url: str = None, error_type: str = 'info'):
if backend_url:
cluster_backend_hash = cluster_config.get_backend(backend_url)['hash']
else:
cluster_backend_hash = 'none'
http_host = redis.get('http_host', dtype=str)
return f"""```
=== MESSAGE FROM LLM MIDDLEWARE AT {http_host} ===

View File

@ -3,15 +3,16 @@ from flask import Blueprint, jsonify
from llm_server.custom_redis import redis
from llm_server.routes.helpers.client import format_sillytavern_err
bp = Blueprint('old_v1', __name__)
old_v1_bp = Blueprint('v1', __name__)
@bp.route('/<first>')
@bp.route('/<first>/<path:rest>')
def fallback(first=None, rest=None):
@old_v1_bp.route('/', defaults={'path': ''}, methods=['GET', 'POST'])
@old_v1_bp.route('/<path:path>', methods=['GET', 'POST'])
def fallback(path):
base_client_api = redis.get('base_client_api', dtype=str)
error_msg = f'The /v1/ endpoint has been depreciated. Please see [{base_client_api}]({base_client_api}) for the new endpoint.'
error_msg = f'The /v1/ endpoint has been depreciated. Please visit {base_client_api} for more information.'
response_msg = format_sillytavern_err(error_msg, error_type='API')
return jsonify({
'results': [{'text': response_msg}]
'results': [{'text': response_msg}],
'result': base_client_api
}), 200 # return 200 so we don't trigger an error message in the client's ST

View File

@ -3,7 +3,7 @@ from flask import Blueprint
from ..request_handler import before_request
from ..server_error import handle_server_error
bp = Blueprint('v1', __name__)
bp = Blueprint('v2', __name__)
@bp.before_request

View File

@ -1,3 +1,5 @@
from llm_server.routes.v1 import old_v1_bp
try:
import gevent.monkey
@ -70,6 +72,7 @@ from llm_server.routes.v2.generate_stats import generate_stats
app = Flask(__name__)
init_socketio(app)
app.register_blueprint(bp, url_prefix='/api/v2/')
app.register_blueprint(old_v1_bp, url_prefix='/api/v1/')
app.register_blueprint(openai_bp, url_prefix='/api/openai/v1/')
flask_cache.init_app(app)
flask_cache.clear()