Skip to content

Commit bb93ffb

Browse files
author
nightcityblade
committed
fix: retain second conversation message
1 parent 7f1703c commit bb93ffb

2 files changed

Lines changed: 10 additions & 24 deletions

File tree

swarms/structs/conversation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ def return_all_except_first(self):
13031303
Returns:
13041304
list: List of messages except the first one.
13051305
"""
1306-
return self.conversation_history[2:]
1306+
return self.conversation_history[1:]
13071307

13081308
def return_all_except_first_string(self):
13091309
"""Return all messages except the first one as a string.
@@ -1314,7 +1314,7 @@ def return_all_except_first_string(self):
13141314
return "\n".join(
13151315
[
13161316
f"{msg['content']}"
1317-
for msg in self.conversation_history[2:]
1317+
for msg in self.conversation_history[1:]
13181318
]
13191319
)
13201320

tests/structs/test_conversation.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -442,16 +442,10 @@ def test_return_all_except_first():
442442
conv.add("system", "System")
443443
conv.add("user", "Hello")
444444
conv.add("assistant", "Hi")
445-
try:
446-
result = conv.return_all_except_first()
447-
assert len(result) == 2
448-
assert result[0]["role"] == "user"
449-
assert result[1]["role"] == "assistant"
450-
logger.success("test_return_all_except_first passed")
451-
return True
452-
except AssertionError as e:
453-
logger.error(f"test_return_all_except_first failed: {str(e)}")
454-
return False
445+
result = conv.return_all_except_first()
446+
assert len(result) == 2
447+
assert result[0]["role"] == "user"
448+
assert result[1]["role"] == "assistant"
455449

456450

457451
def test_return_all_except_first_string():
@@ -460,18 +454,10 @@ def test_return_all_except_first_string():
460454
conv.add("system", "System")
461455
conv.add("user", "Hello")
462456
conv.add("assistant", "Hi")
463-
try:
464-
result = conv.return_all_except_first_string()
465-
assert "Hello" in result
466-
assert "Hi" in result
467-
assert "System" not in result
468-
logger.success("test_return_all_except_first_string passed")
469-
return True
470-
except AssertionError as e:
471-
logger.error(
472-
f"test_return_all_except_first_string failed: {str(e)}"
473-
)
474-
return False
457+
result = conv.return_all_except_first_string()
458+
assert "Hello" in result
459+
assert "Hi" in result
460+
assert "System" not in result
475461

476462

477463
def test_batch_add():

0 commit comments

Comments
 (0)