Files
AiDA_Python/app/api/api_fashion_agent.py
zcr b9163f0b46 重构图像生成和搜索工具;更新主代理来处理输入图像
- 更新了“generate_image.py”以接受输入图像以增强图像生成。
- 修改了`pexels_search.py​​`和`unsplash_search.py​​`以将日志记录和上传路径从“explorer”更改为“explore”。
- 调整了“print_graph”和“sketch_graph”以提取最新的用户输入并处理输入图像以生成打印和草图图像。
- 重构“generate_print_tool”和“generate_sketch_tool”以接受输入图像。
- 更新了“main_agent.py”以包含状态中的输入图像并调整了图形构建过程。
- 增强了“service.py”来管理输入图像并改进了流媒体期间的事件处理。
- 更新了新软件包和版本的“pyproject.toml”和“uv.lock”中的依赖项。
2026-06-17 11:56:53 +08:00

48 lines
1.9 KiB
Python

import json
import logging
from fastapi import APIRouter, HTTPException
from fastapi.responses import StreamingResponse
from app.schemas.fashion_agent import FashionAgentRequest
from app.service.fashion_agent.service import FashionAgentService
router = APIRouter()
logger = logging.getLogger()
@router.post("/agent/stream")
async def fashion_agent_stream(request_item: FashionAgentRequest):
"""
服装设计 Agent(流式输出)
- **message**: 用户输入的消息(必填)
- **user_id**: 用户ID,默认 "agent"
- **enable_thinking**: 是否开启思考模式
- **call_print**: 是否直接调用 print 生成印花
- **print_need_prompt_generation**: print 是否需要 LLM 生成 prompt
- **call_logo**: 是否直接调用 logo 生成装饰图案
- **call_sketch**: 是否直接调用 sketch 生成草图
- **sketch_need_prompt_generation**: sketch 是否需要 LLM 生成 prompt
- **call_design**: 是否直接调用 design 生成设计系列
- **design_request_data**: design 请求参数(objects, process_id, requestId, callback_url)
- **call_trending**: 是否直接调用 trending 趋势分析
- **call_explore**: 是否直接调用 explore 灵感探索
- **provider**: 图片源 (pexels/unsplash),默认 unsplash
返回 SSE 事件流:
- **tools** 事件:工具调用的 started/finished 状态
- **custom** 事件:design 工具的逐个生成结果
- **Done** 事件:流结束标记
"""
try:
logger.info(f"fashion_agent stream request: {json.dumps(request_item.model_dump(), indent=4, ensure_ascii=False)}")
service = FashionAgentService()
return StreamingResponse(
service.run_stream(request_item),
media_type="text/event-stream",
)
except Exception as e:
logger.warning(f"fashion_agent stream exception: {e}")
raise HTTPException(status_code=500, detail=str(e))