-
Notifications
You must be signed in to change notification settings - Fork 638
Fix: Tongyi Qianwen model temporary file leak issue. #2076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Tongyi Qianwen model temporary file leak issue. #2076
Conversation
- 添加临时文件追踪机制,在类初始化时创建 _temp_files 列表 - 在 _save_base64_to_file 方法中记录创建的临时文件 - 添加 _cleanup_temp_files 方法用于清理临时文件 - 在 _handle_generate_response 和 _handle_generate_stream_response 中使用 try-finally 确保临时文件被清理 - 修复 _upload_file_to_tongyi 方法中的临时文件泄漏问题 这个修复解决了处理 base64 编码的图片/视频和文档上传时临时文件累积的问题,避免长期运行服务时磁盘空间被占用。
Summary of ChangesHello @WzzP, 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! 此拉取请求旨在解决通义千问模型在处理多模态输入(如 base64 编码的图片/视频和文档)时产生的临时文件泄漏问题。通过引入一套全面的临时文件追踪和清理机制,确保在模型响应生成和文件上传操作完成后,所有创建的临时文件都能被及时删除,从而有效防止服务长期运行导致磁盘空间被不必要地占用。 Highlights
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次 PR 旨在修复通义千问模型中的临时文件泄漏问题,做得很好。通过引入 _temp_files 列表来追踪临时文件,并在 _save_base64_to_file 中记录,最后通过 try...finally 结构调用新的 _cleanup_temp_files 方法来确保清理,这个方案是正确且可靠的。
我在代码中发现了一个严重问题和一些可以改进的地方:
- 在
_upload_file_to_tongyi方法中,client.files.create尝试使用一个已经关闭的临时文件对象,这将导致ValueError。此外,在上传前文件指针没有被重置,可能导致上传空文件。我提供了一个代码建议来修复此问题。 - 在
_cleanup_temp_files和_upload_file_to_tongyi的finally块中,异常被静默地忽略了。虽然注释说明要记录错误,但代码中并没有实现,这可能会掩盖潜在的文件清理失败问题。建议添加日志记录。
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- 添加 logging 模块导入和 logger 实例 - 在 _cleanup_temp_files 方法中添加日志记录,记录删除失败的文件 - 在 _upload_file_to_tongyi 的 finally 块中添加日志记录 - 在 _cleanup_temp_files 结束时清空 _temp_files 列表 这些改进解决了 code review 中提到的异常被静默忽略的问题,便于调试和监控。
|
Please bump the version in the manifest as well. |
It has been changed, please check it |
这个修复解决了处理 base64 编码的图片/视频和文档上传时临时文件累积的问题,避免长期运行服务时磁盘空间被占用。
Related Issues or Context
This PR contains Changes to Non-Plugin
This PR contains Changes to Non-LLM Models Plugin
This PR contains Changes to LLM Models Plugin
Version Control (Any Changes to the Plugin Will Require Bumping the Version)
VersionField, Not in Meta Section)Dify Plugin SDK Version
dify_plugin>=0.3.0,<0.6.0is in requirements.txt (SDK docs)Environment Verification (If Any Code Changes)
Local Deployment Environment
SaaS Environment