Spaces:
Restarting
Restarting
v124: vaszalo fixed entrypoint
Browse files- entrypoint_contextpatch.py +11 -11
entrypoint_contextpatch.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""v124 entrypoint - natural intent detection without overriding app.py v123 fixes.
|
| 2 |
- Keeps v1032 natural intent detection (before_request, detect, rank, reply)
|
| 3 |
- Does NOT monkey-patch accessory/search functions (app.py v123 already has fix_ke_gia_vi)
|
| 4 |
- Delegates to entrypoint_staticimg.py after patching
|
|
@@ -12,7 +12,7 @@ if not APP.exists():
|
|
| 12 |
|
| 13 |
PATCH = r'''
|
| 14 |
|
| 15 |
-
# ===== VAI HARD NATURAL NEED SYNONYM FIX v124 =====
|
| 16 |
# NOTE: _fix_patch_ke_gia_vi() monkey-patch REMOVED - app.py v123+ has it built-in
|
| 17 |
# Only keeping natural intent detection that intercepts before_request
|
| 18 |
|
|
@@ -227,9 +227,9 @@ def _v1032_before_request():
|
|
| 227 |
cid=str((msg.get('chat') or {}).get('id') or (msg.get('from') or {}).get('id') or msg.get('chat_id') or '')
|
| 228 |
raw=str(msg.get('text') or msg.get('caption') or '').strip()
|
| 229 |
if not raw or cid==str(ADMIN_CID): return None
|
| 230 |
-
if _v1032_handle_natural(cid,raw,msg): return jsonify({'ok':True,'handled':'
|
| 231 |
except Exception:
|
| 232 |
-
try: log('⚠️ v124 before_request: '+traceback.format_exc()[-1200:])
|
| 233 |
except Exception: pass
|
| 234 |
return None
|
| 235 |
try:
|
|
@@ -237,7 +237,7 @@ try:
|
|
| 237 |
funcs=app.before_request_funcs.get(None,[])
|
| 238 |
if _v1032_before_request in funcs:
|
| 239 |
funcs.insert(0, funcs.pop(funcs.index(_v1032_before_request)))
|
| 240 |
-
except Exception as e: print('v124 before_request install failed',e)
|
| 241 |
|
| 242 |
def _v1032_wrap_func(fname):
|
| 243 |
try:
|
|
@@ -256,7 +256,7 @@ def _v1032_wrap_func(fname):
|
|
| 256 |
raw=str(kwargs.get('text') or raw)
|
| 257 |
if cid and cid!=str(ADMIN_CID) and raw and _v1032_handle_natural(cid,raw,msg): return True
|
| 258 |
except Exception:
|
| 259 |
-
try: log('⚠️ v124 wrap '+fname+': '+traceback.format_exc()[-800:])
|
| 260 |
except Exception: pass
|
| 261 |
return old(*args,**kwargs)
|
| 262 |
globals()[fname]=wrapped
|
|
@@ -264,13 +264,13 @@ def _v1032_wrap_func(fname):
|
|
| 264 |
except Exception:return False
|
| 265 |
for _fn in ['handle_msg','handle_message','handle_text','process_message','on_message']:
|
| 266 |
_v1032_wrap_func(_fn)
|
| 267 |
-
print('v124: natural intent detection installed (no monkey-patch override)')
|
| 268 |
-
# ===== END VAI HARD NATURAL NEED SYNONYM FIX v124 =====
|
| 269 |
'''
|
| 270 |
|
| 271 |
try:
|
| 272 |
s=APP.read_text(encoding='utf-8')
|
| 273 |
-
if 'VAI HARD NATURAL NEED SYNONYM FIX v124' not in s:
|
| 274 |
pos=-1
|
| 275 |
for mk in ['if __name__=="__main__"',"if __name__=='__main__'",'app.run(']:
|
| 276 |
pos=s.rfind(mk)
|
|
@@ -278,9 +278,9 @@ try:
|
|
| 278 |
s=s+PATCH if pos==-1 else s[:pos]+PATCH+'\n'+s[pos:]
|
| 279 |
APP.write_text(s,encoding='utf-8')
|
| 280 |
py_compile.compile(str(APP),doraise=True)
|
| 281 |
-
print('entrypoint_contextpatch: app.py patched v124 compile ok',flush=True)
|
| 282 |
else:
|
| 283 |
-
print('entrypoint_contextpatch: v124 already present',flush=True)
|
| 284 |
except Exception:
|
| 285 |
print('entrypoint_contextpatch: non-fatal patch error',flush=True)
|
| 286 |
traceback.print_exc()
|
|
|
|
| 1 |
+
"""v124-vaszalo entrypoint - natural intent detection without overriding app.py v123 fixes.
|
| 2 |
- Keeps v1032 natural intent detection (before_request, detect, rank, reply)
|
| 3 |
- Does NOT monkey-patch accessory/search functions (app.py v123 already has fix_ke_gia_vi)
|
| 4 |
- Delegates to entrypoint_staticimg.py after patching
|
|
|
|
| 12 |
|
| 13 |
PATCH = r'''
|
| 14 |
|
| 15 |
+
# ===== VAI HARD NATURAL NEED SYNONYM FIX v124-vaszalo =====
|
| 16 |
# NOTE: _fix_patch_ke_gia_vi() monkey-patch REMOVED - app.py v123+ has it built-in
|
| 17 |
# Only keeping natural intent detection that intercepts before_request
|
| 18 |
|
|
|
|
| 227 |
cid=str((msg.get('chat') or {}).get('id') or (msg.get('from') or {}).get('id') or msg.get('chat_id') or '')
|
| 228 |
raw=str(msg.get('text') or msg.get('caption') or '').strip()
|
| 229 |
if not raw or cid==str(ADMIN_CID): return None
|
| 230 |
+
if _v1032_handle_natural(cid,raw,msg): return jsonify({'ok':True,'handled':'v124-vaszalo_natural_need'})
|
| 231 |
except Exception:
|
| 232 |
+
try: log('⚠️ v124-vaszalo before_request: '+traceback.format_exc()[-1200:])
|
| 233 |
except Exception: pass
|
| 234 |
return None
|
| 235 |
try:
|
|
|
|
| 237 |
funcs=app.before_request_funcs.get(None,[])
|
| 238 |
if _v1032_before_request in funcs:
|
| 239 |
funcs.insert(0, funcs.pop(funcs.index(_v1032_before_request)))
|
| 240 |
+
except Exception as e: print('v124-vaszalo before_request install failed',e)
|
| 241 |
|
| 242 |
def _v1032_wrap_func(fname):
|
| 243 |
try:
|
|
|
|
| 256 |
raw=str(kwargs.get('text') or raw)
|
| 257 |
if cid and cid!=str(ADMIN_CID) and raw and _v1032_handle_natural(cid,raw,msg): return True
|
| 258 |
except Exception:
|
| 259 |
+
try: log('⚠️ v124-vaszalo wrap '+fname+': '+traceback.format_exc()[-800:])
|
| 260 |
except Exception: pass
|
| 261 |
return old(*args,**kwargs)
|
| 262 |
globals()[fname]=wrapped
|
|
|
|
| 264 |
except Exception:return False
|
| 265 |
for _fn in ['handle_msg','handle_message','handle_text','process_message','on_message']:
|
| 266 |
_v1032_wrap_func(_fn)
|
| 267 |
+
print('v124-vaszalo: natural intent detection installed (no monkey-patch override)')
|
| 268 |
+
# ===== END VAI HARD NATURAL NEED SYNONYM FIX v124-vaszalo =====
|
| 269 |
'''
|
| 270 |
|
| 271 |
try:
|
| 272 |
s=APP.read_text(encoding='utf-8')
|
| 273 |
+
if 'VAI HARD NATURAL NEED SYNONYM FIX v124-vaszalo' not in s:
|
| 274 |
pos=-1
|
| 275 |
for mk in ['if __name__=="__main__"',"if __name__=='__main__'",'app.run(']:
|
| 276 |
pos=s.rfind(mk)
|
|
|
|
| 278 |
s=s+PATCH if pos==-1 else s[:pos]+PATCH+'\n'+s[pos:]
|
| 279 |
APP.write_text(s,encoding='utf-8')
|
| 280 |
py_compile.compile(str(APP),doraise=True)
|
| 281 |
+
print('entrypoint_contextpatch: app.py patched v124-vaszalo compile ok',flush=True)
|
| 282 |
else:
|
| 283 |
+
print('entrypoint_contextpatch: v124-vaszalo already present',flush=True)
|
| 284 |
except Exception:
|
| 285 |
print('entrypoint_contextpatch: non-fatal patch error',flush=True)
|
| 286 |
traceback.print_exc()
|