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.
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
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) |