douyin_user_videos.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """获取一页作者作品并自动保存。"""
  2. from __future__ import annotations
  3. import asyncio
  4. import httpx as httpx
  5. from agents.find_agent.support.douyin_user_videos import (
  6. DEFAULT_MIN_DURATION_SECONDS,
  7. _douyin_user_videos_raw,
  8. _wait_rate_limit as _wait_rate_limit,
  9. )
  10. from agents.find_agent.support.search_persistence import persist_search_payload
  11. from supply_agent.tools import tool
  12. @tool
  13. async def douyin_user_videos(
  14. run_id: str,
  15. account_id: str,
  16. query_reason: str,
  17. source_value: str | None = None,
  18. parent_search_id: int | None = None,
  19. page_no: int = 1,
  20. sort_type: str = "最热",
  21. cursor: str = "",
  22. min_duration_seconds: int = DEFAULT_MIN_DURATION_SECONDS,
  23. timeout: float | None = None,
  24. ) -> str:
  25. """获取一页作者作品,创建搜索记录和候选记录并返回对应数据库 ID。"""
  26. result = await _douyin_user_videos_raw(
  27. account_id=account_id,
  28. sort_type=sort_type,
  29. cursor=cursor,
  30. min_duration_seconds=min_duration_seconds,
  31. timeout=timeout,
  32. )
  33. return await asyncio.to_thread(
  34. persist_search_payload,
  35. result,
  36. run_id=run_id,
  37. keyword=f"author:{account_id}",
  38. query_reason=query_reason,
  39. source_type="author",
  40. source_value=source_value or account_id,
  41. parent_search_id=parent_search_id,
  42. cursor=cursor,
  43. page_no=page_no,
  44. provider="internal_blogger",
  45. sort_type=sort_type,
  46. )