Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

Added color print and optional window size (#20)

Guohao Lid446e99caf26
diff --git a/camel/agent.py b/camel/agent.py
index 7e8379fd1..f8bf30e15 100644
--- a/camel/agent.py
+++ b/camel/agent.py
@@ -5,8 +5,13 @@ from tenacity import retry, stop_after_attempt, wait_exponential
from camel.configs import ChatGPTConfig
from camel.generator import SystemMessageGenerator
-from camel.message import (AssistantChatMessage, ChatMessage, MessageType,
- SystemMessage, UserChatMessage)
+from camel.message import (
+ AssistantChatMessage,
+ ChatMessage,
+ MessageType,
+ SystemMessage,
+ UserChatMessage,
+)
from camel.typing import ModeType, RoleType
from camel.utils import get_model_token_limit, num_tokens_from_messages
@@ -18,7 +23,7 @@ class ChatAgent:
system_message: SystemMessage,
model: ModeType,
model_config: Any = None,
- message_window_size: int = 4,
+ message_window_size: Optional[int] = None,
) -> None:
self.system_message = system_message
self.role_name = system_message.role_name
@@ -64,7 +69,8 @@ class ChatAgent:
input_message: ChatMessage,
) -> Tuple[List[ChatMessage], bool, Dict[str, Any]]:
messages = self.update_messages(input_message)
- if len(messages) > self.message_window_size:
+ if self.message_window_size is not None and len(
+ messages) > self.message_window_size:
messages = [self.system_message
] + messages[-self.message_window_size:]
openai_messages = [message.to_openai_message() for message in messages]
@@ -164,7 +170,8 @@ class RolePlaying:
if with_task_specify:
task_specify_agent = TaskSpecifyAgent(
ModeType.GPT_3_5_TURBO, ChatGPTConfig(temperature=1.4))
- self.task_prompt = task_specify_agent.specify_task(task_prompt)
+ task_prompt = task_specify_agent.specify_task(task_prompt)
+ self.task_prompt = task_prompt
sys_msg_generator = SystemMessageGenerator(with_task=with_task)
self.assistant_sys_msg, self.user_sys_msg = (
diff --git a/examples/role_playing.py b/examples/role_playing.py
index b64ee12c8..52b2f1234 100644
--- a/examples/role_playing.py
+++ b/examples/role_playing.py
@@ -1,5 +1,7 @@
import time
+from colorama import Fore
+
from camel.agent import RolePlaying
@@ -11,18 +13,20 @@ def print_text_animated(text):
def main() -> None:
task_prompt = "Design a custom game using PyGame"
- print(f"Original task prompt:\n{task_prompt}\n")
+ print(Fore.YELLOW + f"Original task prompt:\n{task_prompt}\n")
role_play_session = RolePlaying("Computer Programer", "Gamer", task_prompt)
- print(f"Specified task prompt:\n{role_play_session.task_prompt}\n")
+ print(Fore.CYAN +
+ f"Specified task prompt:\n{role_play_session.task_prompt}\n")
chat_turn_limit, n = 10, 0
assistant_msg, _ = role_play_session.init_chat()
while n < chat_turn_limit:
n += 1
assistant_msg, user_msg = role_play_session.step(assistant_msg)
- print_text_animated(f"AI User:\n\n{user_msg.content}\n\n")
+ print_text_animated(Fore.BLUE + f"AI User:\n\n{user_msg.content}\n\n")
time.sleep(0.5)
- print_text_animated(f"AI Assistant:\n\n{assistant_msg.content}\n\n")
+ print_text_animated(Fore.GREEN +
+ f"AI Assistant:\n\n{assistant_msg.content}\n\n")
if "<CAMEL_TASK_DONE>" in assistant_msg.content:
break
diff --git a/requirements.txt b/requirements.txt
index 97abf6e89..c78c54d31 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,4 +9,5 @@ isort
flake8
pre-commit
pytest
-pytest-cov
\ No newline at end of file
+pytest-cov
+colorama
\ No newline at end of file