douyin_search.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """搜索一页抖音视频并自动保存。"""
  2. from __future__ import annotations
  3. import asyncio
  4. from typing import Optional
  5. import httpx as httpx
  6. from agents.find_agent.support.douyin_search import (
  7. DEFAULT_MIN_DURATION_SECONDS,
  8. DOUYIN_ACCOUNT_ID,
  9. _build_search_results as _build_search_results,
  10. _douyin_search_raw,
  11. _error_result as _error_result,
  12. _success_result as _success_result,
  13. )
  14. from agents.find_agent.support.search_persistence import persist_search_payload
  15. from supply_agent.tools import tool
  16. @tool
  17. async def douyin_search(
  18. run_id: str,
  19. keyword: str,
  20. query_reason: str,
  21. source_type: str,
  22. source_value: str | None = None,
  23. parent_search_id: int | None = None,
  24. page_no: int = 1,
  25. content_type: str = "视频",
  26. sort_type: str = "综合排序",
  27. publish_time: str = "不限",
  28. cursor: str = "0",
  29. account_id: str = DOUYIN_ACCOUNT_ID,
  30. min_duration_seconds: int = DEFAULT_MIN_DURATION_SECONDS,
  31. timeout: Optional[float] = None,
  32. ) -> str:
  33. """搜索一页抖音视频,创建搜索记录和候选记录,返回基础信息及数据库 ID。"""
  34. result = await _douyin_search_raw(
  35. keyword=keyword,
  36. content_type=content_type,
  37. sort_type=sort_type,
  38. publish_time=publish_time,
  39. cursor=cursor,
  40. account_id=account_id,
  41. min_duration_seconds=min_duration_seconds,
  42. timeout=timeout,
  43. )
  44. return await asyncio.to_thread(
  45. persist_search_payload,
  46. result,
  47. run_id=run_id,
  48. keyword=keyword,
  49. query_reason=query_reason,
  50. source_type=source_type,
  51. source_value=source_value,
  52. parent_search_id=parent_search_id,
  53. cursor=cursor,
  54. page_no=page_no,
  55. provider="internal_keyword",
  56. content_type=content_type,
  57. sort_type=sort_type,
  58. publish_time=publish_time,
  59. )