移植自 mac-agent-os 的 mediacrawler_adapter:不起子进程、不开页面,用浏览器里那份
登录态直接调抖音 Web 接口。产物键名照抄 store/douyin,所以 ingest 那条链路一个字不用改。
**目前能用的(真环境实测,非推断)**:
profile/other : 200, 7075 字节 —— 博主主页指标(粉丝/获赞/作品数/昵称)
aweme/detail : 200, 45425 字节 —— 单条作品详情(含点赞/评论/收藏/分享)
**目前不能用的:作品列表 `aweme/post`。** 两个互相独立的原因:
1. 这个接口被抖音单独升级成了真校验:不带 x-tt-argus 回 403「Uifid Not Found」,
带上 dummy 值回 200 + **空 body**。也就是说「头在不在」骗得过,「真校验」过不了。
同一套头打 profile/other 和 aweme/detail 都是通的 —— 抖音是挑着接口加保护的,
挑中的恰好是「批量拉作品列表」这个最敏感的动作。
2. 改走页面截获也不行:CDP 浏览器打开博主主页会落到「验证码中间页」(当天大量探测的
代价,过几小时要重测)。
所以现在的边界是:**已知作品的指标刷新能做,自动发现新作品做不了**。
**排查中控住变量后得到的两条事实**(都写进注释了):
· `Accept` / `Accept-Language` / `Referer` 才是主页接口能返回真数据的原因 —— 只有
UA+client hints+Cookie 时是 200 但仅 121 字节的空壳,补上这三个头变 7074 字节。
(我先前猜的 sec-ch-ua 不是关键。)
· 因此 UA 与 client hints 必须**成套地取自同一个浏览器**,所以 BrowserIdentity 一次
从 CDP 取齐 cookie + UA + hints,而不是各自写死。
「200 + 空 body 必须当场报错」也是刻意写死的:放过去它会在下游变成「这个博主没作品」,
把一次失败伪装成一条正常结果 —— 爬虫那条路正是这么栽的,还被翻译成「账号被封」。
测试 +11:cookie 解析、请求头成套性(含 uifid 缺失/回退)、产物键名与 store 对齐、
以及 _get 的三条失败路径(空 body / 403 带网关原话 / 正常返回)。
158 lines
5.3 KiB
Python
158 lines
5.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试 oMLX embedding API 是否在自动化环境中正常工作
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
import sys
|
|
|
|
def test_embedding_api():
|
|
"""测试 embedding API"""
|
|
url = "http://localhost:8000/v1/embeddings"
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"Authorization": "Bearer omlx"
|
|
}
|
|
data = {
|
|
"model": "Qwen3-Embedding-0.6B",
|
|
"input": ["测试文本:这是用于验证 oMLX embedding API 是否正常工作的测试文本。"]
|
|
}
|
|
|
|
try:
|
|
print("测试 oMLX embedding API...")
|
|
print(f"URL: {url}")
|
|
print(f"Headers: {headers}")
|
|
print(f"Data: {json.dumps(data, ensure_ascii=False)}")
|
|
|
|
response = requests.post(url, headers=headers, json=data, timeout=30)
|
|
|
|
print(f"状态码: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
print("✅ API 调用成功!")
|
|
print(f"返回数据: {json.dumps(result, ensure_ascii=False)[:200]}...")
|
|
|
|
# 检查向量维度
|
|
if "data" in result and len(result["data"]) > 0:
|
|
embedding = result["data"][0]["embedding"]
|
|
print(f"向量维度: {len(embedding)} (应为 1024)")
|
|
if len(embedding) == 1024:
|
|
print("✅ 向量维度正确!")
|
|
else:
|
|
print(f"⚠️ 向量维度异常: {len(embedding)}")
|
|
|
|
return True
|
|
else:
|
|
print(f"❌ API 调用失败: {response.status_code}")
|
|
print(f"响应内容: {response.text}")
|
|
return False
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print("❌ 无法连接到 oMLX API (ConnectionError)")
|
|
print("请确保 oMLX 应用正在运行,端口 8000 可访问")
|
|
return False
|
|
except requests.exceptions.Timeout:
|
|
print("❌ API 请求超时")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ 未知错误: {type(e).__name__}: {e}")
|
|
return False
|
|
|
|
def test_chat_api():
|
|
"""测试 chat completions API"""
|
|
url = "http://localhost:8000/v1/chat/completions"
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"Authorization": "Bearer omlx"
|
|
}
|
|
data = {
|
|
"model": "Qwen3-8B-MLX-4bit",
|
|
"messages": [{"role": "user", "content": "你好,请回复'测试成功'"}],
|
|
"stream": False,
|
|
"temperature": 0.1
|
|
}
|
|
|
|
try:
|
|
print("\n测试 oMLX chat completions API...")
|
|
response = requests.post(url, headers=headers, json=data, timeout=60)
|
|
|
|
print(f"状态码: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
print("✅ Chat API 调用成功!")
|
|
if "choices" in result and len(result["choices"]) > 0:
|
|
message = result["choices"][0]["message"]["content"]
|
|
print(f"回复内容: {message}")
|
|
return True
|
|
else:
|
|
print(f"❌ Chat API 调用失败: {response.status_code}")
|
|
print(f"响应内容: {response.text}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Chat API 错误: {type(e).__name__}: {e}")
|
|
return False
|
|
|
|
def test_models_api():
|
|
"""测试 models API"""
|
|
url = "http://localhost:8000/v1/models"
|
|
headers = {"Authorization": "Bearer omlx"}
|
|
|
|
try:
|
|
print("\n测试 oMLX models API...")
|
|
response = requests.get(url, headers=headers, timeout=10)
|
|
|
|
print(f"状态码: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
print("✅ Models API 调用成功!")
|
|
print(f"可用模型: {json.dumps(result, ensure_ascii=False)}")
|
|
return True
|
|
else:
|
|
print(f"❌ Models API 调用失败: {response.status_code}")
|
|
print(f"响应内容: {response.text}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Models API 错误: {type(e).__name__}: {e}")
|
|
return False
|
|
|
|
def main():
|
|
print("=" * 60)
|
|
print("oMLX API 测试脚本")
|
|
print("=" * 60)
|
|
|
|
# 测试 models API
|
|
models_ok = test_models_api()
|
|
|
|
# 测试 embedding API
|
|
embedding_ok = test_embedding_api()
|
|
|
|
# 测试 chat API
|
|
chat_ok = test_chat_api()
|
|
|
|
print("\n" + "=" * 60)
|
|
print("测试结果汇总:")
|
|
print(f" Models API: {'✅ 正常' if models_ok else '❌ 异常'}")
|
|
print(f" Embedding API: {'✅ 正常' if embedding_ok else '❌ 异常'}")
|
|
print(f" Chat API: {'✅ 正常' if chat_ok else '❌ 异常'}")
|
|
print("=" * 60)
|
|
|
|
# 关键检查:embedding API 是否正常
|
|
if embedding_ok:
|
|
print("\n✅ 关键依赖:embedding API 正常,向量化功能可用")
|
|
print(" 这意味着 daily_digest.py 的向量化步骤可以正常工作")
|
|
else:
|
|
print("\n❌ 关键依赖:embedding API 异常,向量化功能不可用")
|
|
print(" 这会影响记忆系统的语义检索能力")
|
|
|
|
if not chat_ok:
|
|
print("\n⚠️ Chat API 异常,但这不是关键依赖")
|
|
print(" inbox_refine.py 的智能分类功能会降级到启发式规则")
|
|
|
|
if __name__ == "__main__":
|
|
main() |