Skip to content

Commit aea5b86

Browse files
Fix mypy error in utils and prompts (camel-ai#193)
Co-authored-by: Bo Liu <[email protected]>
1 parent d363bdf commit aea5b86

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

camel/prompts/ai_society.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class AISocietyPromptTemplateDict(TextPromptDict):
5858
Please reply with the specified task in {word_limit} words or less. Do not add anything else."""
5959
)
6060

61-
ASSISTANT_PROMPT = TextPrompt(
61+
ASSISTANT_PROMPT: TextPrompt = TextPrompt(
6262
"""Never forget you are a {assistant_role} and I am a {user_role}. Never flip roles! Never instruct me!
6363
We share a common interest in collaborating to successfully complete a task.
6464
You must help me to complete the task.
@@ -75,7 +75,7 @@ class AISocietyPromptTemplateDict(TextPromptDict):
7575
<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.
7676
Always end <YOUR_SOLUTION> with: Next request.""")
7777

78-
USER_PROMPT = TextPrompt(
78+
USER_PROMPT: TextPrompt = TextPrompt(
7979
"""Never forget you are a {user_role} and I am a {assistant_role}. Never flip roles! You will always instruct me.
8080
We share a common interest in collaborating to successfully complete a task.
8181
I must help you to complete the task.

camel/prompts/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@
2020

2121

2222
def return_prompt_wrapper(
23-
cls: T,
23+
cls: Any,
2424
func: Callable,
25-
) -> Callable[..., Union[T, tuple]]:
25+
) -> Callable[..., Union[Any, tuple]]:
2626
r"""Wrapper that converts the return value of a function to an input
2727
class instance if it's a string.
2828
2929
Args:
30-
cls (type): The class to convert to.
30+
cls (Any): The class to convert to.
3131
func (Callable): The function to decorate.
3232
3333
Returns:
34-
Callable[..., Union[T, tuple]]: Decorated function that
34+
Callable[..., Union[Any, str]]: Decorated function that
3535
returns the decorated class instance if the return value is a
3636
string.
3737
"""
3838

39-
def wrapper(*args: Any, **kwargs: Any) -> Union[T, tuple]:
39+
def wrapper(*args: Any, **kwargs: Any) -> Union[Any, str]:
4040
r"""Wrapper function that performs the conversion to :obj:`TextPrompt`
4141
instance.
4242
@@ -45,7 +45,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Union[T, tuple]:
4545
**kwargs (Any): Arbitrary keyword arguments.
4646
4747
Returns:
48-
Union[TextPrompt, tuple]: The converted return value.
48+
Union[Any, str]: The converted return value.
4949
"""
5050
result = func(*args, **kwargs)
5151
if isinstance(result, str) and not isinstance(result, cls):
@@ -185,7 +185,7 @@ def execute(
185185
sys.stdout = output_str
186186

187187
global_vars = global_vars or globals()
188-
local_vars = {}
188+
local_vars: Dict[str, Any] = {}
189189
exec(
190190
self,
191191
global_vars,

camel/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import time
1717
import zipfile
1818
from functools import wraps
19-
from typing import Any, Callable, List, Optional, Set, TypeVar
19+
from typing import Any, Callable, List, Optional, Set, TypeVar, cast
2020

2121
import requests
2222
import tiktoken
@@ -167,7 +167,7 @@ def wrapper(self, *args, **kwargs):
167167
else:
168168
raise ValueError('OpenAI API key not found.')
169169

170-
return wrapper
170+
return cast(F, wrapper)
171171

172172

173173
def print_text_animated(text, delay: float = 0.02, end: str = ""):

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ openai = "^0"
3131
tenacity = "^8"
3232
tiktoken = "^0"
3333
colorama = "^0"
34+
types-colorama = "^0"
35+
types-requests = "^2"
3436
yapf = "^0"
3537
isort = "^5"
3638
flake8 = "^6"

0 commit comments

Comments
 (0)