Skip to content

Commit

Permalink
refactor(llamabot/components)🔧: Refactor type hinting and update llam…
Browse files Browse the repository at this point in the history
…abot version

- Correct the type hinting in process_messages function to include ellipsis for variable length tuples.
- Update llamabot version from 0.9.21 to 0.10.0 in pixi.lock.
- Add process_messages to the import in test_messages.py to ensure it is available for testing.
- Extend test_process_messages_with_nested_types to verify handling of various input types.
  • Loading branch information
ericmjl committed Dec 11, 2024
1 parent 669f188 commit 440a6af
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion llamabot/components/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def retrieve_messages_up_to_budget(


def process_messages(
messages: tuple[Union[str, BaseMessage, list[Union[str, BaseMessage]], ...]]
messages: tuple[Union[str, BaseMessage, list[Union[str, BaseMessage]]], ...]
) -> list[BaseMessage]:
"""Process a tuple of messages into a list of BaseMessage objects.
Expand Down
4 changes: 2 additions & 2 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions tests/components/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
HumanMessage,
AIMessage,
ToolMessage,
process_messages,
)


Expand Down Expand Up @@ -42,3 +43,30 @@ def test_tool_message_slicing():
assert msg[5:].content == "Output"
assert msg[-6:].content == "Output"
assert msg[:-7].content == "Tool"


def test_process_messages_with_nested_types():
"""Test that process_messages handles various input types correctly."""
from llamabot.components.messages import (
HumanMessage,
SystemMessage,
)

# Test with a mix of types
test_message = SystemMessage(content="system message")
messages = (
"human message",
test_message,
["nested message 1", "nested message 2"],
)

result = process_messages(messages)

assert len(result) == 4
assert isinstance(result[0], HumanMessage)
assert result[0].content == "human message"
assert result[1] == test_message
assert isinstance(result[2], HumanMessage)
assert result[2].content == "nested message 1"
assert isinstance(result[3], HumanMessage)
assert result[3].content == "nested message 2"

0 comments on commit 440a6af

Please sign in to comment.