40 lines
1.9 KiB
Python
40 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
# probe_stream.py — стрим-путь: приходят ли tool_calls дельты от :48000 (grok-4.7).
|
|
import json, sys, urllib.request
|
|
sys.path.insert(0, "/opt/grok-bot")
|
|
import iishko.legacy as L
|
|
|
|
body = {"model": "grok-4.7",
|
|
"messages": [{"role": "user", "content": "ОБЯЗАТЕЛЬНО вызови run_code: print('SANDBOX_OK', 2**64). Не отвечай по памяти."}],
|
|
"tools": L.BOT_TOOLS, "tool_choice": "auto", "max_tokens": 300, "stream": True}
|
|
|
|
for base in ("http://127.0.0.1:48000/v1", "http://127.0.0.1:48005/v1"):
|
|
req = urllib.request.Request(base + "/chat/completions", data=json.dumps(body).encode(),
|
|
headers={"Authorization": "Bearer " + L.GW_KEY,
|
|
"Content-Type": "application/json"}, method="POST")
|
|
names, txt, fr = [], [], None
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=90) as r:
|
|
for raw in r:
|
|
line = raw.decode("utf-8", "replace").strip()
|
|
if not line.startswith("data:"):
|
|
continue
|
|
data = line[5:].strip()
|
|
if data == "[DONE]":
|
|
break
|
|
try:
|
|
ch = json.loads(data)
|
|
except ValueError:
|
|
continue
|
|
c0 = (ch.get("choices") or [{}])[0]
|
|
if c0.get("finish_reason"):
|
|
fr = c0["finish_reason"]
|
|
d = c0.get("delta") or {}
|
|
if d.get("content"):
|
|
txt.append(d["content"])
|
|
for tc in (d.get("tool_calls") or []):
|
|
fn = tc.get("function") or {}
|
|
names.append((tc.get("index"), fn.get("name")))
|
|
print(base, "| tool_chunks:", names[:6], "| finish:", fr, "| text:", "".join(txt)[:100].replace("\n", " "))
|
|
except Exception as e:
|
|
print(base, "ERR", type(e).__name__, str(e)[:150]) |