feat(bot): screenshot OCR pipeline + ack delay 120s
D fix: screenshots were silently dropped (empty body + OOB url). - register xep_0066, capture msg['oob']['url'] when body empty - also handle body-as-URL messages (some clients put URL in body) - download from upload.yoin.fun, OCR via SenseNova (sensenova-6.7-flash-lite) - inject OCR text as context into LLM call - config at /home/hmo/.config/mofin/ocr_config.json (outside repo) - replaces dead node122 GLM-OCR path (host unreachable) A+B fix: ACK_DELAY 15s -> 120s. 15s fired on every normal LLM cold-start (20-100s), now only signals genuine hangs.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import ast, sys
|
||||
src = open('/home/hmo/MoFin/deploy/bot/xmpp_agent_core.py').read()
|
||||
try:
|
||||
ast.parse(src)
|
||||
print('SYNTAX OK, lines:', len(src.splitlines()))
|
||||
except SyntaxError as e:
|
||||
print('SYNTAX ERROR:', e)
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,23 @@
|
||||
import sys
|
||||
sys.argv = ['test', '--agent', 'zhiwei']
|
||||
# Prevent bot from actually connecting — just test the image functions
|
||||
src = open('/home/hmo/MoFin/deploy/bot/xmpp_agent_core.py').read()
|
||||
# Cut off at main entry to avoid starting the bot
|
||||
cut = src.find("if __name__ ==")
|
||||
if cut > 0:
|
||||
src = src[:cut]
|
||||
ns = {}
|
||||
exec(compile(src, 'xmpp_agent_core.py', 'exec'), ns)
|
||||
|
||||
url = "https://upload.yoin.fun/upload/d22cef590582300cc5580c722a19280054bf0d6a/brEbU8RxXwipU9VuhZqhhFOIAmQI4epG5dp5so6U/LBbTaPJdRfmzxjBg0uh21A.jpg"
|
||||
print("== _is_image_url ==", ns['_is_image_url'](url))
|
||||
print("== download ==")
|
||||
img = ns['_download_image'](url)
|
||||
print("bytes:", len(img) if img else None)
|
||||
if img:
|
||||
print("== OCR ==")
|
||||
ok, text = ns['_ocr_image'](img)
|
||||
print("ok:", ok)
|
||||
print("text:", text[:600])
|
||||
print("== full pipeline ==")
|
||||
print(ns['_process_image_message'](url)[:700])
|
||||
@@ -0,0 +1,29 @@
|
||||
import json, urllib.request, base64
|
||||
|
||||
KEY = "sk-aRNj3UwKSLPsDfh15QNTPwbHxahblfaO"
|
||||
BASE = "https://token.sensenova.cn/v1"
|
||||
MODEL = "sensenova-6.7-flash-lite"
|
||||
|
||||
img_b64 = base64.b64encode(open('/tmp/test_shot.jpg', 'rb').read()).decode()
|
||||
payload = json.dumps({
|
||||
"model": MODEL,
|
||||
"messages": [{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{img_b64}"}},
|
||||
{"type": "text", "text": "请识别这张图片中的所有文字内容,包括数字、股票名称、金额、日期。用中文回复。"}
|
||||
]
|
||||
}],
|
||||
"max_tokens": 1500,
|
||||
}).encode()
|
||||
req = urllib.request.Request(f"{BASE}/chat/completions", data=payload,
|
||||
headers={"Content-Type": "application/json", "Authorization": f"Bearer {KEY}"})
|
||||
try:
|
||||
resp = urllib.request.urlopen(req, timeout=90)
|
||||
data = json.loads(resp.read().decode())
|
||||
msg = data.get('choices', [{}])[0].get('message', {})
|
||||
text = msg.get('content', '') or msg.get('reasoning', '')
|
||||
print('OCR OK:')
|
||||
print(text[:1500])
|
||||
except Exception as e:
|
||||
print('OCR FAIL:', e)
|
||||
Reference in New Issue
Block a user