add canvas mode for deploy#919
Conversation
…into merge_website
…into merge_website
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求为部署服务引入了全新的“画布模式”,旨在通过一个直观的拖放式界面,使用户能够轻松构建和执行复杂的 AI 工作流。它不仅增加了完整的 React/TypeScript 前端应用,还对后端进行了大量修改,以支持工作流的生命周期管理、数据存储和与多种 AI 模型的集成。 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
这个 PR 为服务化部署引入了一个新的画布(canvas)模式,包含了全新的前端应用和为工作流提供支持的大量后端 API。这些改动体量很大,但大部分结构良好。后端为工作流管理添加了许多新 API,前端则是一个功能完整的 React 应用。我的审查主要关注于提升代码的正确性、可维护性和健壮性。我提供了一些关于潜在 bug、类型提示不匹配以及重构机会的具体建议。另外,新的前端主组件 App.tsx 文件非常庞大,如果能将其拆分为更小的组件,将有助于提高可维护性。
Note: Security Review did not run due to the size of the PR.
lightx2v/deploy/server/__main__.py
Outdated
| body = await request.json() | ||
| except Exception as e: | ||
| raise HTTPException(status_code=400, detail=f"Invalid JSON body: {e}") | ||
| api_key = os.environ.get("VOLCENGINE_LLM_API_KEY").strip() |
There was a problem hiding this comment.
lightx2v/deploy/server/__main__.py
Outdated
| page = int(request.query_params.get("page", 1)) | ||
| page_size = int(request.query_params.get("page_size", 10)) |
There was a problem hiding this comment.
如果查询参数 page 或 page_size 的值不是有效的整数(例如 "abc"),int() 转换会引发 ValueError,导致未处理的异常和 500 错误。建议将这些转换放在 try-except 块中,以优雅地处理无效输入。
| page = int(request.query_params.get("page", 1)) | |
| page_size = int(request.query_params.get("page_size", 10)) | |
| try: | |
| page = int(request.query_params.get("page", 1)) | |
| page_size = int(request.query_params.get("page_size", 10)) | |
| except ValueError: | |
| return error_response("Invalid 'page' or 'page_size' parameter. Must be an integer.", 400) |
lightx2v/deploy/server/__main__.py
Outdated
| task_id = request.query_params.get("task_id", "") | ||
| try: | ||
| entries = await query_output_entries(user["user_id"], workflow_id, node_id, port_id, file_id, task_id, task_manager) | ||
| assert len(entries) == 1, f"should be one entry, but got {len(entries)}, {entries}" |
There was a problem hiding this comment.
assert 语句在 Python 以 -O(优化)标志运行时会被移除,而这在生产环境中很常见。如果这个检查对于保证代码正确性很重要,最好使用显式的 if 判断并抛出适当的异常,例如 ValueError。
| assert len(entries) == 1, f"should be one entry, but got {len(entries)}, {entries}" | |
| if len(entries) != 1: | |
| raise ValueError(f"should be one entry, but got {len(entries)}, {entries}") |
| RUN pip uninstall pyannote.audio -y \ | ||
| && pip install pyannote.audio==4.0.4 pydub |
| port_id: str, | ||
| files_tasks: dict, | ||
| data_manager: BaseDataManager, | ||
| ) -> list[dict]: |
| entry: dict, | ||
| task_manager: BaseTaskManager, | ||
| data_manager: BaseDataManager, | ||
| ) -> bytes | None: |
| } | ||
| proxy = os.environ.get("HTTPS_PROXY") or None | ||
|
|
||
| session = aiohttp.ClientSession() |
| except Exception: | ||
| traceback.print_exc() | ||
| return error_response("Failed to create workflow", 500) |
There was a problem hiding this comment.
在生产环境中使用 traceback.print_exc() 会将堆栈跟踪打印到标准错误流,这不利于日志管理。建议改用 logger.exception(),它能更好地与日志系统集成,并提供更丰富的上下文信息。此建议适用于该文件中所有类似的 except Exception 块。
| except Exception: | |
| traceback.print_exc() | |
| return error_response("Failed to create workflow", 500) | |
| except Exception as e: | |
| logger.exception(f"Failed to create workflow: {e}") | |
| return error_response("Failed to create workflow", 500) |
|
|
||
| // --- Main App --- | ||
|
|
||
| const App: React.FC = () => { |
服务化部署增加画布操作模式 --------- Co-authored-by: qinxinyi <qxy118045534@163.com>
服务化部署增加画布操作模式