feat(shipping-notice): 新增货代发货通知全流程业务功能
- 新增后端完整业务支持:数据库模型、API接口、核心服务与RPA对接逻辑 - 新增前端工作台页面、路由适配与多语言国际化 - 新增Dify自定义工具OpenAPI规范、Agent配置脚本与部署文档 - 新增发货Excel模板生成脚本与默认模板 - 修复测试配置文件中的环境变量命名错误 - 更新本地开发环境变量配置
This commit is contained in:
1 parent
93e99793d8
commit
2d7bdecc43
46 files changed
+3462
-7
No files matched your search
@@ -0,0 +1,77 @@
|
||||
"""Seed agents for freight shipping notice Chatflow orchestration."""
|
||||
from app import create_app, db
|
||||
from app.models import Agent
|
||||
from app.services.shipping_notice.agent_resolver import CHAT_AGENT_NAME, EXTRACT_AGENT_NAME
|
||||
|
||||
app = create_app()
|
||||
|
||||
CHAT_DESCRIPTION = "货代发货通知智能体:自然语言驱动解析、库存匹配、Excel 生成与货代上传(Tool 编排)"
|
||||
EXTRACT_DESCRIPTION = "后台专用:从邮件/PDF 文本抽取结构化发货通知字段(Workflow,供 Tool 内部调用)"
|
||||
|
||||
|
||||
def _upsert_agent(
|
||||
*,
|
||||
name: str,
|
||||
description: str,
|
||||
dify_app_type: str,
|
||||
dify_app_id: str | None = None,
|
||||
dify_api_key: str | None = None,
|
||||
api_base_url: str | None = None,
|
||||
):
|
||||
agent = Agent.query.filter_by(name=name).first()
|
||||
extra_config = {"dify_app_type": dify_app_type}
|
||||
if not agent:
|
||||
agent = Agent(
|
||||
name=name,
|
||||
description=description,
|
||||
type="api",
|
||||
dify_app_id=dify_app_id,
|
||||
dify_api_key=dify_api_key,
|
||||
api_base_url=api_base_url,
|
||||
extra_config=extra_config,
|
||||
is_active=True,
|
||||
)
|
||||
db.session.add(agent)
|
||||
print(f"Created agent: {name}")
|
||||
else:
|
||||
agent.description = description
|
||||
agent.type = "api"
|
||||
agent.extra_config = extra_config
|
||||
if dify_app_id:
|
||||
agent.dify_app_id = dify_app_id
|
||||
if dify_api_key:
|
||||
agent.dify_api_key = dify_api_key
|
||||
if api_base_url:
|
||||
agent.api_base_url = api_base_url
|
||||
agent.is_active = True
|
||||
print(f"Updated agent: {name}")
|
||||
return agent
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import os
|
||||
|
||||
with app.app_context():
|
||||
chat_key = os.getenv("SHIPPING_NOTICE_CHAT_DIFY_API_KEY") or os.getenv("DIFY_API_KEY")
|
||||
chat_base = os.getenv("SHIPPING_NOTICE_CHAT_DIFY_BASE") or os.getenv("DIFY_API_BASE")
|
||||
extract_key = os.getenv("SHIPPING_NOTICE_EXTRACT_DIFY_API_KEY")
|
||||
extract_base = os.getenv("SHIPPING_NOTICE_EXTRACT_DIFY_BASE") or chat_base
|
||||
|
||||
_upsert_agent(
|
||||
name=CHAT_AGENT_NAME,
|
||||
description=CHAT_DESCRIPTION,
|
||||
dify_app_type="chatflow",
|
||||
dify_app_id=os.getenv("SHIPPING_NOTICE_CHAT_DIFY_APP_ID"),
|
||||
dify_api_key=chat_key,
|
||||
api_base_url=chat_base,
|
||||
)
|
||||
_upsert_agent(
|
||||
name=EXTRACT_AGENT_NAME,
|
||||
description=EXTRACT_DESCRIPTION,
|
||||
dify_app_type="workflow",
|
||||
dify_app_id=os.getenv("SHIPPING_NOTICE_EXTRACT_DIFY_APP_ID"),
|
||||
dify_api_key=extract_key,
|
||||
api_base_url=extract_base,
|
||||
)
|
||||
db.session.commit()
|
||||
print("Shipping notice agents seeded.")
|
||||
Reference in new issue
Block a user