| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- """
- 内容导入工具
- 将文章链接批量导入 AIGC CMS 系统。
- """
- import json
- from typing import Any, Dict, List
- import httpx
- from agent.tools import tool, ToolResult
- AIGC_BASE_URL = "http://aigc-channel.aiddit.com/aigc/channel"
- DEFAULT_TIMEOUT = 60.0
- @tool(groups=["content"])
- async def import_content(plan_name: str, content_data: List[Dict[str, Any]]) -> ToolResult:
- """
- 导入长文内容到 CMS(微信公众号、小红书、抖音等通用链接)。
- Args:
- plan_name: 计划名称
- content_data: 内容数据列表,每项包含 channel、content_link、title 等字段
- """
- try:
- async with httpx.AsyncClient(timeout=DEFAULT_TIMEOUT) as client:
- response = await client.post(
- f"{AIGC_BASE_URL}/weixin/auto_insert",
- json={"plan_name": plan_name, "data": content_data},
- )
- response.raise_for_status()
- data = response.json()
- if data.get("code") == 0:
- result_data = data.get("data", {})
- return ToolResult(
- title=f"内容导入: {plan_name}",
- output=json.dumps(result_data, ensure_ascii=False, indent=2),
- long_term_memory=f"Imported {len(content_data)} items to plan '{plan_name}'",
- )
- return ToolResult(title="导入失败", output="", error=f"导入失败: {data.get('msg', '未知错误')}")
- except Exception as e:
- return ToolResult(title="内容导入异常", output="", error=str(e))
|