Skip to content
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

refactor: 处理多张图片的HumanMessage #1657

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

shaohuzhang1
Copy link
Contributor

refactor: 处理多张图片的HumanMessage

Copy link

f2c-ci-robot bot commented Nov 19, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Nov 19, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

messages = [HumanMessage(
content=[
{'type': 'text', 'text': self.workflow_manage.generate_prompt(prompt)},
{'type': 'image_url', 'image_url': {'url': f'data:image/jpeg;base64,{base64_image}'}},
*images
])]
else:
messages = [HumanMessage(self.workflow_manage.generate_prompt(prompt))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是一个代码样例,用于在对话系统中生成自定义问题和答案。以下提到了几个可能的问题点:

  1. QuerySet 可能需要使用其内置方法(例如 .get() 或者 .order_by())来获取字节数据,并且错误地将 base64.encode() 替换为 base 64.decode。

  2. 在处理多张图片时,您正在创建两个额外的消息:一个针对包含文件ID并链接到 JPEG 格式图片的大写 URL 的消息(假设是第一个图像),以及一个针对没有提供任何特定指示的单幅图像的消息;如果确实有多个图像,请根据实际需求调整代码以适应更多图像情况。

  3. 对于一些文本提示或系统指令等输出项类型的选择,在不同的任务场景下可能会有不同的最佳实践或偏好。确保在具体情况下选择最合适的语言模型输出结构至关重要。

  4. 如果输入/输出的数据格式经常变化或者需要灵活处理,可以考虑采用更通用化的处理方式,比如通过传递参数给函数内部变量的方式直接引用这些内容而不是依赖外部函数调用。

  5. 元素列表(如 images 是用来存储不同类型的元组列表中的对象)。由于你在这里只是添加了一个字典到这个列表,因此没有必要这样做。

基于以上发现,我会给出以下修改意见或优化建议:

  • 增强代码健壮性:确保利用Python标准库中的合适方法(如.dict().items(), .list(), 等),以便正确工作在所有运行环境中。此外,还可以避免不必要的嵌套,减少复杂度。
  • 统一代码风格与可读性:保持编码一致性和整洁清晰度是非常重要的。这有助于更好地阅读并维护你的程序源码。
  • 动态编程实现:根据业务逻辑的不同,逐步扩展代码功能是一个明智的做法。对于未来更多的需求,提前规划解决方案会更有成效。

希望上述建议对您有所帮助!如果您想详细了解如何提高您的代码质量和稳定性请告诉我。

@liuruibin liuruibin merged commit b91d9fd into main Nov 19, 2024
4 of 5 checks passed
@liuruibin liuruibin deleted the pr@main@refactor_multi_images branch November 19, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants