fraudTech commited on
Commit
7ec9540
·
1 Parent(s): 068a29f

ultamate prolog ai

Browse files
Files changed (1) hide show
  1. app.py +122 -0
app.py CHANGED
@@ -325,6 +325,128 @@ def proxy_kb_metadata():
325
  return jsonify(data), resp.status_code
326
 
327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  # ============================================================
329
  # HEALTH CHECK
330
  # ============================================================
 
325
  return jsonify(data), resp.status_code
326
 
327
 
328
+ # ============================================================
329
+ # MATH DISCOVERY (HYBRID)
330
+ # ============================================================
331
+ @app.route("/math/discover", methods=["POST"])
332
+ @jwt_required()
333
+ def proxy_math_discover():
334
+ if HF_TOKEN is None:
335
+ return jsonify({"ok": False, "error": "HF_TOKEN not configured"}), 500
336
+
337
+ try:
338
+ payload = request.get_json(force=True) or {}
339
+ except Exception:
340
+ return jsonify({"ok": False, "error": "Invalid JSON"}), 400
341
+
342
+ try:
343
+ resp = requests.post(
344
+ f"{BACKEND_BASE}/math/discover",
345
+ json=payload,
346
+ headers={"Authorization": f"Bearer {HF_TOKEN}"},
347
+ timeout=120,
348
+ )
349
+ except Exception as e:
350
+ return jsonify({"ok": False, "error": f"Gateway request failed: {e}"}), 502
351
+
352
+ try:
353
+ data = resp.json()
354
+ except ValueError:
355
+ return jsonify({"ok": False, "error": f"Backend returned non-JSON: {resp.text[:200]}"}), 502
356
+
357
+ return jsonify(data), resp.status_code
358
+
359
+
360
+ # ============================================================
361
+ # SESSION LEMMAS (LIST/CLEAR)
362
+ # ============================================================
363
+ @app.route("/session/lemmas", methods=["POST"])
364
+ @jwt_required()
365
+ def proxy_session_lemmas():
366
+ if HF_TOKEN is None:
367
+ return jsonify({"ok": False, "error": "HF_TOKEN not configured"}), 500
368
+
369
+ try:
370
+ payload = request.get_json(force=True) or {}
371
+ except Exception:
372
+ return jsonify({"ok": False, "error": "Invalid JSON"}), 400
373
+
374
+ try:
375
+ resp = requests.post(
376
+ f"{BACKEND_BASE}/session/lemmas",
377
+ json=payload,
378
+ headers={"Authorization": f"Bearer {HF_TOKEN}"},
379
+ timeout=30,
380
+ )
381
+ except Exception as e:
382
+ return jsonify({"ok": False, "error": f"Gateway request failed: {e}"}), 502
383
+
384
+ try:
385
+ data = resp.json()
386
+ except ValueError:
387
+ return jsonify({"ok": False, "error": f"Backend returned non-JSON: {resp.text[:200]}"}), 502
388
+
389
+ return jsonify(data), resp.status_code
390
+
391
+
392
+ @app.route("/session/clear", methods=["POST"])
393
+ @jwt_required()
394
+ def proxy_session_clear():
395
+ if HF_TOKEN is None:
396
+ return jsonify({"ok": False, "error": "HF_TOKEN not configured"}), 500
397
+
398
+ try:
399
+ payload = request.get_json(force=True) or {}
400
+ except Exception:
401
+ return jsonify({"ok": False, "error": "Invalid JSON"}), 400
402
+
403
+ try:
404
+ resp = requests.post(
405
+ f"{BACKEND_BASE}/session/clear",
406
+ json=payload,
407
+ headers={"Authorization": f"Bearer {HF_TOKEN}"},
408
+ timeout=30,
409
+ )
410
+ except Exception as e:
411
+ return jsonify({"ok": False, "error": f"Gateway request failed: {e}"}), 502
412
+
413
+ try:
414
+ data = resp.json()
415
+ except ValueError:
416
+ return jsonify({"ok": False, "error": f"Backend returned non-JSON: {resp.text[:200]}"}), 502
417
+
418
+ return jsonify(data), resp.status_code
419
+
420
+
421
+ @app.route("/session/export", methods=["POST"])
422
+ @jwt_required()
423
+ def proxy_session_export():
424
+ if HF_TOKEN is None:
425
+ return jsonify({"ok": False, "error": "HF_TOKEN not configured"}), 500
426
+
427
+ try:
428
+ payload = request.get_json(force=True) or {}
429
+ except Exception:
430
+ return jsonify({"ok": False, "error": "Invalid JSON"}), 400
431
+
432
+ try:
433
+ resp = requests.post(
434
+ f"{BACKEND_BASE}/session/export",
435
+ json=payload,
436
+ headers={"Authorization": f"Bearer {HF_TOKEN}"},
437
+ timeout=60,
438
+ )
439
+ except Exception as e:
440
+ return jsonify({"ok": False, "error": f"Gateway request failed: {e}"}), 502
441
+
442
+ try:
443
+ data = resp.json()
444
+ except ValueError:
445
+ return jsonify({"ok": False, "error": f"Backend returned non-JSON: {resp.text[:200]}"}), 502
446
+
447
+ return jsonify(data), resp.status_code
448
+
449
+
450
  # ============================================================
451
  # HEALTH CHECK
452
  # ============================================================