Files
doubao-clone/scripts/probe-seed-link-msg.py

63 lines
2.2 KiB
Python

"""给会话塞一条带链接的助手回复,用来测「打开网页」按钮。
★ 为什么要造数据而不是真让模型回一条:
真回一条要配 API key、要等流式、还有网络不确定性 —— 而我们这里要测的是
**界面上那个按钮在不在、点了对不对**,跟回复怎么来的无关。
直接写一条一样的消息,测起来快且稳定。
"""
import json
import sys
import urllib.request
try:
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
URL = "http://127.0.0.1:15199"
def call(path, payload=None, method="POST", timeout=60):
data = json.dumps(payload, ensure_ascii=False).encode("utf-8") if payload is not None else None
req = urllib.request.Request(
URL + path, data=data, method=method,
headers={"Content-Type": "application/json; charset=utf-8"},
)
with urllib.request.urlopen(req, timeout=timeout) as r:
return json.loads(r.read().decode("utf-8"))
convs = call("/api/conversations", method="GET").get("conversations") or []
print("会话数:", len(convs))
for c in convs[:5]:
print(" ", c.get("id"), "|", c.get("title"), "| 消息", c.get("messageCount"))
if not convs:
print("!! 没有会话")
sys.exit(1)
cid = convs[0]["id"]
print(f"\n往 {cid} 里塞一条带链接的回复…")
content = (
"我查到了几个可能有用的页面:\n\n"
"- [Example 官网](https://example.com)\n"
"- [Example 中文](https://example.com/index-zh)\n\n"
"**说明**:这两个是示例域名,用来验证「打开网页」按钮。\n"
"还有一个没有链接的说法:这是个普通段落。"
)
res = call(f"/api/conversations/{cid}", {
"messages": [
{"role": "user", "content": "帮我找几个网页"},
{"role": "assistant", "content": content},
],
}, method="PATCH")
print("写入结果:", json.dumps(res, ensure_ascii=False)[:200])
full = call(f"/api/conversations/{cid}", method="GET").get("conversation") or {}
msgs = full.get("messages") or []
print("现在有", len(msgs), "条消息")
for m in msgs:
print(" ", m.get("role"), "|", (m.get("content") or "")[:50].replace("\n", " "))