fix: bug which causes unrecoverable state if previous message was an image (#6486)
* trying tout gpt-5.1-codex * add unit test for message content * try to support multimodal
This commit is contained in:
32
tests/test_message_serialization.py
Normal file
32
tests/test_message_serialization.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from letta.llm_api.openai_client import fill_image_content_in_responses_input
|
||||
from letta.schemas.enums import MessageRole
|
||||
from letta.schemas.letta_message_content import Base64Image, ImageContent, TextContent
|
||||
from letta.schemas.message import Message
|
||||
|
||||
|
||||
def _user_message_with_image_first(text: str) -> Message:
|
||||
image = ImageContent(source=Base64Image(media_type="image/png", data="dGVzdA=="))
|
||||
return Message(role=MessageRole.user, content=[image, TextContent(text=text)])
|
||||
|
||||
|
||||
def test_to_openai_responses_dicts_handles_image_first_content():
|
||||
message = _user_message_with_image_first("hello world")
|
||||
serialized = Message.to_openai_responses_dicts_from_list([message])
|
||||
parts = serialized[0]["content"]
|
||||
assert any(part["type"] == "input_text" and part["text"] == "hello world" for part in parts)
|
||||
assert any(part["type"] == "input_image" for part in parts)
|
||||
|
||||
|
||||
def test_fill_image_content_in_responses_input_includes_image_parts():
|
||||
message = _user_message_with_image_first("describe image")
|
||||
serialized = Message.to_openai_responses_dicts_from_list([message])
|
||||
rewritten = fill_image_content_in_responses_input(serialized, [message])
|
||||
assert rewritten == serialized
|
||||
|
||||
|
||||
def test_to_openai_responses_dicts_handles_image_only_content():
|
||||
image = ImageContent(source=Base64Image(media_type="image/png", data="dGVzdA=="))
|
||||
message = Message(role=MessageRole.user, content=[image])
|
||||
serialized = Message.to_openai_responses_dicts_from_list([message])
|
||||
parts = serialized[0]["content"]
|
||||
assert parts[0]["type"] == "input_image"
|
||||
Reference in New Issue
Block a user