Skip to content

Commit

Permalink
fix: revert change to ChatAgent and test for example (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendong-Fan committed Jun 20, 2024
1 parent 896c4c4 commit 4286bc2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
10 changes: 1 addition & 9 deletions camel/agents/chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,19 +522,11 @@ def handle_batch_response(
"""
output_messages: List[BaseMessage] = []
for choice in response.choices:
if isinstance(choice.message, list):
# If choice.message is a list, handle accordingly
# It's a check to fit with Nemotron model integration.
content = "".join(
[msg.content for msg in choice.message if msg.content]
)
else:
content = choice.message.content or ""
chat_message = BaseMessage(
role_name=self.role_name,
role_type=self.role_type,
meta_dict=dict(),
content=content,
content=choice.message.content or "",
)
output_messages.append(chat_message)
finish_reasons = [
Expand Down
12 changes: 9 additions & 3 deletions examples/test/test_role_description_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType

model = ModelFactory.create(
model_gpt = ModelFactory.create(
ModelPlatformType.OPENAI,
model_type=ModelType.GPT_3_5_TURBO,
model_config_dict={},
)

model_stub = ModelFactory.create(
ModelPlatformType.OPENAI,
model_type=ModelType.STUB,
model_config_dict={},
)


def test_role_generation_example():
with patch('time.sleep', return_value=None):
examples.role_description.role_generation.main(model)
examples.role_description.role_generation.main(model_gpt)


def test_role_playing_with_role_description_example():
with patch('time.sleep', return_value=None):
examples.role_description.role_playing_with_role_description.main(
model, model, chat_turn_limit=2
model_gpt, model_stub, chat_turn_limit=2
)
22 changes: 20 additions & 2 deletions examples/test/test_single_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ def test_single_agent(model):
examples.single_agent.main(model=model)


@parametrize
@pytest.mark.parametrize(
'model',
[
ModelFactory.create(
ModelPlatformType.OPENAI,
model_type=ModelType.STUB,
model_config_dict={},
)
],
)
def test_misalignment_single_agent(model):
examples.misalignment.single_agent.main(model=model)

Expand All @@ -54,6 +63,15 @@ def test_code_generate_metadata(model):
examples.code.generate_meta_data.main(model=model)


@parametrize
@pytest.mark.parametrize(
'model',
[
ModelFactory.create(
ModelPlatformType.OPENAI,
model_type=ModelType.STUB,
model_config_dict={},
)
],
)
def test_code_task_generation(model):
examples.code.task_generation.main(model=model)

0 comments on commit 4286bc2

Please sign in to comment.