aigc_decode_server.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from typing import Dict, List
  2. from app.infra.shared import AsyncHttpClient
  3. class AigcDecodeServer:
  4. base_url: str = "https://aigc-api.aiddit.com"
  5. async def submit_decode(
  6. self, config_id: int, posts: List[Dict], skip_completed: bool = False
  7. ) -> Dict:
  8. """批量提交帖子解构
  9. POST /aigc/api/task/decode
  10. """
  11. url = f"{self.base_url}/aigc/api/task/decode"
  12. headers = {"Content-Type": "application/json"}
  13. payload = {
  14. "params": {
  15. "configId": config_id,
  16. "skipCompleted": skip_completed,
  17. "posts": posts,
  18. }
  19. }
  20. async with AsyncHttpClient() as client:
  21. return await client.post(url, json=payload, headers=headers)
  22. async def query_decode_results(
  23. self, config_id: int, channel_content_ids: List[str]
  24. ) -> Dict:
  25. """批量查询解构结果
  26. POST /aigc/api/task/decode/result
  27. """
  28. url = f"{self.base_url}/aigc/api/task/decode/result"
  29. headers = {"Content-Type": "application/json"}
  30. payload = {
  31. "params": {"configId": config_id, "channelContentIds": channel_content_ids}
  32. }
  33. async with AsyncHttpClient() as client:
  34. return await client.post(url, json=payload, headers=headers)
  35. async def cancel_decode_tasks(
  36. self, config_id: int, channel_content_ids: List[str]
  37. ) -> Dict:
  38. """取消待执行解构任务
  39. POST /aigc/api/task/decode/cancel
  40. """
  41. url = f"{self.base_url}/aigc/api/task/decode/cancel"
  42. headers = {"Content-Type": "application/json"}
  43. payload = {
  44. "params": {"configId": config_id, "channelContentIds": channel_content_ids}
  45. }
  46. async with AsyncHttpClient() as client:
  47. return await client.post(url, json=payload, headers=headers)
  48. __all__ = ["AigcDecodeServer"]