douyin_search.py 1.7 KB

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