piaoquan_decode_server.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from typing import Optional, Dict, List
  2. from app.infra.shared import AsyncHttpClient
  3. class DecodeServer:
  4. base_url: str = "http://supply-content-deconstruction-api.piaoquantv.com"
  5. # 创建解构任务
  6. async def create_decode_task(self, data: Dict) -> Dict:
  7. """
  8. scene: 业务场景:0 选题; 1 创作; 2 制作;
  9. content_type: 内容类型: 1 长文; 2 图文; 3 视频;
  10. content:
  11. channel_content_id:
  12. video_url:
  13. images: [ image_url_1, image_url_2, ...]
  14. body_text: 长文内容
  15. title: 文章标题
  16. channel_account_id: 作者 id
  17. channel_account_name: 作者名称
  18. output_type: {
  19. }
  20. """
  21. url = f"{self.base_url}/api/v1/content/tasks/decode"
  22. headers = {
  23. "User-Agent": "PQSpeed/486 CFNetwork/1410.1 Darwin/22.6.0",
  24. "Content-Type": "application/json",
  25. }
  26. async with AsyncHttpClient() as client:
  27. response = await client.post(url, json=data, headers=headers)
  28. return response
  29. # 获取解构结果
  30. async def fetch_result(self, task_id: str) -> Dict:
  31. """
  32. INPUT: TaskId
  33. OUTPUT: Dict
  34. {
  35. code: 0 | 404(task not exist),
  36. msg: 'ok',
  37. data: {
  38. "taskId": "123",
  39. "status": 3, 0 PENDING, 1 RUNNING, 2 SUCCESS, 3 FAILED
  40. "result": None | JSON,
  41. "reason": "" | 失败原因,
  42. "url": {
  43. "pointUrl": "", 选题点结构结果页地址(仅解构任务有
  44. "weightUrl": "", 权重页地址(解构聚类都有)
  45. "patternUrl": "" 选题点聚类结果页地址(仅聚类任务有)
  46. }
  47. },
  48. }
  49. """
  50. url = f"{self.base_url}/api/v1/content/tasks/{task_id}"
  51. headers = {
  52. "User-Agent": "PQSpeed/486 CFNetwork/1410.1 Darwin/22.6.0",
  53. "Content-Type": "application/json",
  54. }
  55. async with AsyncHttpClient() as client:
  56. response = await client.get(url, headers=headers)
  57. return response