Check request limit in demo only in API

Stop recognition in UI on enter request
Fix Ratelimt for Ping in GUI
Use OpenaiTemplate for OIVSCode
Support Reasoning in Blackbox
Add error reporting in UI
Support Custom Provider in Demo
This commit is contained in:
hlohaus
2025-01-27 17:37:25 +01:00
parent 0bdfd990bd
commit c18f10243e
9 changed files with 121 additions and 139 deletions

View File

@@ -68,6 +68,7 @@ class Backend_Api(Api):
app=app,
default_limits=["200 per day", "50 per hour"],
storage_uri="memory://",
auto_check=False
)
if has_flask_limiter and app.demo:
@@ -133,7 +134,7 @@ class Backend_Api(Api):
else:
json_data = request.json
if app.demo:
if app.demo and json_data.get("provider") != "Custom":
model = json_data.get("model")
if model != "default" and model in models.demo_models:
json_data["provider"] = random.choice(models.demo_models[model][1])
@@ -156,6 +157,7 @@ class Backend_Api(Api):
@app.route('/backend-api/v2/conversation', methods=['POST'])
@limiter.limit("4 per minute") # 1 request in 15 seconds
def _handle_conversation():
limiter.check()
return handle_conversation()
else:
@app.route('/backend-api/v2/conversation', methods=['POST'])
@@ -171,6 +173,15 @@ class Backend_Api(Api):
f.write(f"{json.dumps(request.json)}\n")
return {}
@app.route('/backend-api/v2/log', methods=['POST'])
def add_log():
cache_dir = Path(get_cookies_dir()) / ".logging"
cache_file = cache_dir / f"{datetime.date.today()}.jsonl"
cache_dir.mkdir(parents=True, exist_ok=True)
with cache_file.open("a" if cache_file.exists() else "w") as f:
f.write(f"{json.dumps(request.json)}\n")
return {}
@app.route('/backend-api/v2/memory/<user_id>', methods=['POST'])
def add_memory(user_id: str):
api_key = request.headers.get("x_api_key")