Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions swarms/structs/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ def return_all_except_first(self):
Returns:
list: List of messages except the first one.
"""
return self.conversation_history[2:]
return self.conversation_history[1:]

def return_all_except_first_string(self):
"""Return all messages except the first one as a string.
Expand All @@ -1314,7 +1314,7 @@ def return_all_except_first_string(self):
return "\n".join(
[
f"{msg['content']}"
for msg in self.conversation_history[2:]
for msg in self.conversation_history[1:]
]
)

Expand Down
30 changes: 8 additions & 22 deletions tests/structs/test_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,10 @@ def test_return_all_except_first():
conv.add("system", "System")
conv.add("user", "Hello")
conv.add("assistant", "Hi")
try:
result = conv.return_all_except_first()
assert len(result) == 2
assert result[0]["role"] == "user"
assert result[1]["role"] == "assistant"
logger.success("test_return_all_except_first passed")
return True
except AssertionError as e:
logger.error(f"test_return_all_except_first failed: {str(e)}")
return False
result = conv.return_all_except_first()
assert len(result) == 2
assert result[0]["role"] == "user"
assert result[1]["role"] == "assistant"


def test_return_all_except_first_string():
Expand All @@ -460,18 +454,10 @@ def test_return_all_except_first_string():
conv.add("system", "System")
conv.add("user", "Hello")
conv.add("assistant", "Hi")
try:
result = conv.return_all_except_first_string()
assert "Hello" in result
assert "Hi" in result
assert "System" not in result
logger.success("test_return_all_except_first_string passed")
return True
except AssertionError as e:
logger.error(
f"test_return_all_except_first_string failed: {str(e)}"
)
return False
result = conv.return_all_except_first_string()
assert "Hello" in result
assert "Hi" in result
assert "System" not in result


def test_batch_add():
Expand Down