smoke_stages.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """M4 真实验收(省 Gemini 费):用 海狸 帖的富文本 body_text 当提取内容,
  2. 真调 claude-sonnet-4.5 跑 screen/split/deconstruct/assemble,打印结果。
  3. 只产生文本 LLM 费用,不调 Gemini。须在能联网调 OpenRouter 的云端跑。
  4. 用法:python scripts/smoke_stages.py [env_file] [content_id]
  5. """
  6. from __future__ import annotations
  7. import json
  8. import sys
  9. from pathlib import Path
  10. from creation_knowledge.integrations.crawler import parse_detail_response
  11. from creation_knowledge.integrations.llm import default_chat
  12. from creation_knowledge.models import ExtractedContent
  13. from creation_knowledge.stages import (
  14. build_ingest_payload,
  15. deconstruct_item,
  16. screen_post,
  17. split_post,
  18. )
  19. FIXTURES = Path(__file__).resolve().parent.parent / "tests" / "fixtures"
  20. def main() -> int:
  21. args = sys.argv[1:]
  22. env_file = args[0] if args and args[0].endswith(".env") else ".env"
  23. cid = next((a for a in args if not a.endswith(".env")), "67e4bdf50000000006028a59")
  24. resp = json.loads((FIXTURES / f"xhs_case_{cid}.json").read_text("utf-8"))
  25. post = parse_detail_response(resp, fallback_content_id=cid)
  26. # 用富文本 body_text 当已提取内容,避免再调 Gemini
  27. content = ExtractedContent(text=post.body_text, is_empty=not post.body_text.strip())
  28. chat = default_chat(env_file)
  29. print(f"==== {post.id} {post.title} ====\n")
  30. scr = screen_post(post, content, chat=chat)
  31. print(f"[screen] passed={scr.passed} score={scr.score} reason={scr.reason}")
  32. if not scr.passed:
  33. return 0
  34. items = split_post(post, content, chat=chat)
  35. print(f"[split] {len(items)} 个知识片段")
  36. for i, item in enumerate(items, 1):
  37. print(f"\n 片段{i}: {item.title} types={item.knowledge_types}")
  38. deco = deconstruct_item(item, chat=chat)
  39. print(f" stages={deco.stages} scopes={[(s.scope_type, s.value) for s in deco.scopes]}")
  40. payload = build_ingest_payload(post, item, deco)
  41. print(f" ingest.content={payload.content[:120]}")
  42. return 0
  43. if __name__ == "__main__":
  44. raise SystemExit(main())