diff --git a/llm_server/routes/helpers/client.py b/llm_server/routes/helpers/client.py index 040a129..5031b8b 100644 --- a/llm_server/routes/helpers/client.py +++ b/llm_server/routes/helpers/client.py @@ -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'): - cluster_backend_hash = cluster_config.get_backend(backend_url)['hash'] +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} === diff --git a/llm_server/routes/v1/__init__.py b/llm_server/routes/v1/__init__.py index 2e02d4c..c812f85 100644 --- a/llm_server/routes/v1/__init__.py +++ b/llm_server/routes/v1/__init__.py @@ -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('/') -@bp.route('//') -def fallback(first=None, rest=None): +@old_v1_bp.route('/', defaults={'path': ''}, methods=['GET', 'POST']) +@old_v1_bp.route('/', 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 diff --git a/llm_server/routes/v2/__init__.py b/llm_server/routes/v2/__init__.py index 123683d..1860473 100644 --- a/llm_server/routes/v2/__init__.py +++ b/llm_server/routes/v2/__init__.py @@ -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 diff --git a/server.py b/server.py index 4a896af..dd508cc 100644 --- a/server.py +++ b/server.py @@ -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()