mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
* add image feature * fix-linting * check model support for images * add comment * Add image support to other models * Add images to chat * fix linting * fix test issues * refactor variable names and import * fix tests * fix chat message tests * fix linting * add pydantic class message * use message * remove redundant comments * remove redundant comments * change Message class * remove unintended change * fix integration tests using regenerate.sh * rename image_bas64 to images_url, fix tests * rename Message.py to message, change reminder append logic, add unit tests * remove comment, fix error to merge * codeact_swe_agent * fix f string * update eventstream integration tests * add missing if check in codeact_swe_agent * update integration tests * Update frontend/src/components/chat/ChatInput.tsx * Update frontend/src/components/chat/ChatInput.tsx * Update frontend/src/components/chat/ChatInput.tsx * Update frontend/src/components/chat/ChatInput.tsx * Update frontend/src/components/chat/ChatMessage.tsx --------- Co-authored-by: tobitege <tobitege@gmx.de> Co-authored-by: Xingyao Wang <xingyao6@illinois.edu> Co-authored-by: sp.wack <83104063+amanape@users.noreply.github.com>
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
from opendevin.core.message import ImageContent, Message, TextContent
|
|
|
|
|
|
def test_message_serialization():
|
|
text_content1 = TextContent(text='This is a text message')
|
|
image_content1 = ImageContent(
|
|
image_urls=['http://example.com/image1.png', 'http://example.com/image2.png']
|
|
)
|
|
text_content2 = TextContent(text='This is another text message')
|
|
image_content2 = ImageContent(
|
|
image_urls=['http://example.com/image3.png', 'http://example.com/image4.png']
|
|
)
|
|
|
|
message = Message(
|
|
role='user',
|
|
content=[text_content1, image_content1, text_content2, image_content2],
|
|
)
|
|
serialized_message = message.serialize_model()
|
|
|
|
expected_serialized_message = {
|
|
'role': 'user',
|
|
'content': [
|
|
{'type': 'text', 'text': 'This is a text message'},
|
|
{
|
|
'type': 'image_url',
|
|
'image_url': {'url': 'http://example.com/image1.png'},
|
|
},
|
|
{
|
|
'type': 'image_url',
|
|
'image_url': {'url': 'http://example.com/image2.png'},
|
|
},
|
|
{'type': 'text', 'text': 'This is another text message'},
|
|
{
|
|
'type': 'image_url',
|
|
'image_url': {'url': 'http://example.com/image3.png'},
|
|
},
|
|
{
|
|
'type': 'image_url',
|
|
'image_url': {'url': 'http://example.com/image4.png'},
|
|
},
|
|
],
|
|
}
|
|
|
|
assert serialized_message == expected_serialized_message
|
|
assert message.contains_image is True
|
|
|
|
|
|
def test_message_with_only_text_content():
|
|
text_content1 = TextContent(text='This is a text message')
|
|
text_content2 = TextContent(text='This is another text message')
|
|
|
|
message = Message(role='user', content=[text_content1, text_content2])
|
|
serialized_message = message.serialize_model()
|
|
|
|
expected_serialized_message = {
|
|
'role': 'user',
|
|
'content': [
|
|
{'type': 'text', 'text': 'This is a text message'},
|
|
{'type': 'text', 'text': 'This is another text message'},
|
|
],
|
|
}
|
|
|
|
assert serialized_message == expected_serialized_message
|
|
assert message.contains_image is False
|