🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
Fix `mypy` error in `utils` and `prompts` (#193)
Guohao Liaea5b8653962
diff --git a/camel/prompts/ai_society.py b/camel/prompts/ai_society.pyindex c9e253f9b..d9e1d3137 100644--- a/camel/prompts/ai_society.py+++ b/camel/prompts/ai_society.py@@ -58,7 +58,7 @@ Please make it more specific. Be creative and imaginative.Please reply with the specified task in {word_limit} words or less. Do not add anything else.""")- ASSISTANT_PROMPT = TextPrompt(+ ASSISTANT_PROMPT: TextPrompt = TextPrompt("""Never forget you are a {assistant_role} and I am a {user_role}. Never flip roles! Never instruct me!We share a common interest in collaborating to successfully complete a task.You must help me to complete the task.@@ -75,7 +75,7 @@ Solution: <YOUR_SOLUTION><YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.Always end <YOUR_SOLUTION> with: Next request.""")- USER_PROMPT = TextPrompt(+ USER_PROMPT: TextPrompt = TextPrompt("""Never forget you are a {user_role} and I am a {assistant_role}. Never flip roles! You will always instruct me.We share a common interest in collaborating to successfully complete a task.I must help you to complete the task.diff --git a/camel/prompts/base.py b/camel/prompts/base.pyindex 6b0aec105..a4bc72dce 100644--- a/camel/prompts/base.py+++ b/camel/prompts/base.py@@ -20,23 +20,23 @@ T = TypeVar('T')def return_prompt_wrapper(- cls: T,+ cls: Any,func: Callable,-) -> Callable[..., Union[T, tuple]]:+) -> Callable[..., Union[Any, tuple]]:r"""Wrapper that converts the return value of a function to an inputclass instance if it's a string.Args:- cls (type): The class to convert to.+ cls (Any): The class to convert to.func (Callable): The function to decorate.Returns:- Callable[..., Union[T, tuple]]: Decorated function that+ Callable[..., Union[Any, str]]: Decorated function thatreturns the decorated class instance if the return value is astring."""- def wrapper(*args: Any, **kwargs: Any) -> Union[T, tuple]:+ def wrapper(*args: Any, **kwargs: Any) -> Union[Any, str]:r"""Wrapper function that performs the conversion to :obj:`TextPrompt`instance.@@ -45,7 +45,7 @@ def return_prompt_wrapper(**kwargs (Any): Arbitrary keyword arguments.Returns:- Union[TextPrompt, tuple]: The converted return value.+ Union[Any, str]: The converted return value."""result = func(*args, **kwargs)if isinstance(result, str) and not isinstance(result, cls):@@ -185,7 +185,7 @@ class CodePrompt(TextPrompt):sys.stdout = output_strglobal_vars = global_vars or globals()- local_vars = {}+ local_vars: Dict[str, Any] = {}exec(self,global_vars,diff --git a/camel/utils.py b/camel/utils.pyindex 169fde3a9..0b4d6f84b 100644--- a/camel/utils.py+++ b/camel/utils.py@@ -16,7 +16,7 @@ import reimport timeimport zipfilefrom functools import wraps-from typing import Any, Callable, List, Optional, Set, TypeVar+from typing import Any, Callable, List, Optional, Set, TypeVar, castimport requestsimport tiktoken@@ -167,7 +167,7 @@ def openai_api_key_required(func: F) -> F:else:raise ValueError('OpenAI API key not found.')- return wrapper+ return cast(F, wrapper)def print_text_animated(text, delay: float = 0.02, end: str = ""):diff --git a/pyproject.toml b/pyproject.tomlindex e7e57f2cf..f11cfdf8c 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -31,6 +31,8 @@ openai = "^0"tenacity = "^8"tiktoken = "^0"colorama = "^0"+types-colorama = "^0"+types-requests = "^2"yapf = "^0"isort = "^5"flake8 = "^6"