Skip to content

Commit f4de3ff

Browse files
Fix mypy errors (camel-ai#185)
1 parent 16c1ac3 commit f4de3ff

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

apps/agents/agents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ def role_playing_chat_init(state) -> \
214214
session: RolePlaying = state.session
215215

216216
try:
217-
init_assistant_msg, _ = session.init_chat()
218217
init_assistant_msg: BaseMessage
218+
init_assistant_msg, _ = session.init_chat()
219219
except (openai.error.RateLimitError, tenacity.RetryError,
220220
RuntimeError) as ex:
221221
print("OpenAI API exception 1 " + str(ex))

apps/data_explorer/data_explorer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def parse_arguments():
5252
return args
5353

5454

55-
def construct_ui(blocks, datasets: Datasets, default_dataset: str = None):
55+
def construct_ui(blocks, datasets: Datasets,
56+
default_dataset: Optional[str] = None):
5657
""" Build Gradio UI and populate with chat data from JSONs.
5758
5859
Args:
@@ -226,7 +227,7 @@ def build_chat_history(messages: Dict[int, Dict]) -> List[Tuple]:
226227
Returns:
227228
List[Tuple]: Chat history in chatbot UI element format.
228229
"""
229-
history = []
230+
history: List[Tuple] = []
230231
curr_qa = (None, None)
231232
for k in sorted(messages.keys()):
232233
msg = messages[k]

apps/data_explorer/loader.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import glob
1919
import os
2020
import re
21-
from typing import Any, Dict, List, Optional, Tuple, Union
21+
from typing import Any, Dict, Optional, Tuple, Union
2222

2323
from tqdm import tqdm
2424

@@ -111,17 +111,17 @@ def load_zip(zip_path: str) -> AllChats:
111111
continue
112112
parsed_list.append(parsed)
113113

114-
assistant_roles = set()
115-
user_roles = set()
114+
assistant_roles_set = set()
115+
user_roles_set = set()
116116
for parsed in parsed_list:
117-
assistant_roles.add(parsed['assistant_role'])
118-
user_roles.add(parsed['user_role'])
119-
assistant_roles = list(sorted(assistant_roles))
120-
user_roles = list(sorted(user_roles))
121-
matrix: Dict[Tuple[str, str], List[Dict]] = dict()
117+
assistant_roles_set.add(parsed['assistant_role'])
118+
user_roles_set.add(parsed['user_role'])
119+
assistant_roles = list(sorted(assistant_roles_set))
120+
user_roles = list(sorted(user_roles_set))
121+
matrix: Dict[Tuple[str, str], Dict[str, Dict]] = dict()
122122
for parsed in parsed_list:
123123
key = (parsed['assistant_role'], parsed['user_role'])
124-
original_task = parsed['original_task']
124+
original_task: str = parsed['original_task']
125125
new_item = {
126126
k: v
127127
for k, v in parsed.items()

camel/societies/role_playing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
14-
from typing import Dict, List, Optional, Sequence, Tuple
14+
from typing import Dict, List, Optional, Sequence, Tuple, Union
1515

1616
from camel.agents import (
1717
ChatAgent,
@@ -23,6 +23,7 @@
2323
from camel.generators import SystemMessageGenerator
2424
from camel.human import Human
2525
from camel.messages import BaseMessage
26+
from camel.prompts import TextPrompt
2627
from camel.typing import ModelType, RoleType, TaskType
2728

2829

@@ -95,6 +96,7 @@ def __init__(
9596
self.model_type = model_type
9697
self.task_type = task_type
9798

99+
self.specified_task_prompt: Optional[TextPrompt]
98100
if with_task_specify:
99101
task_specify_meta_dict = dict()
100102
if self.task_type in [TaskType.AI_SOCIETY, TaskType.MISALIGNMENT]:
@@ -118,6 +120,7 @@ def __init__(
118120
else:
119121
self.specified_task_prompt = None
120122

123+
self.planned_task_prompt: Optional[TextPrompt]
121124
if with_task_planner:
122125
task_planner_agent = TaskPlannerAgent(
123126
self.model_type,
@@ -173,6 +176,7 @@ def __init__(
173176
)
174177
self.user_sys_msg = self.user_agent.system_message
175178

179+
self.critic: Union[CriticAgent, Human, None]
176180
if with_critic_in_the_loop:
177181
if critic_role_name.lower() == "human":
178182
self.critic = Human(**(critic_kwargs or {}))

examples/misalignment/role_playing_with_human.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def main() -> None:
2929
"CAMEL AGI",
3030
task_prompt=task_prompt,
3131
with_task_specify=True,
32-
with_human_in_the_loop=True,
32+
with_critic_in_the_loop=True,
3333
task_type=TaskType.MISALIGNMENT,
3434
task_specify_agent_kwargs=dict(model_config=ChatGPTConfig(
3535
temperature=1.4)),

examples/summarization/gpt_solution_extraction.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ def flatten_conversation(conversation: Dict) -> str:
102102

103103
def format_combination(combination: Tuple[int, int, int]):
104104
assistant_role, user_role, task = combination
105-
assistant_role = str(assistant_role).zfill(3)
106-
user_role = str(user_role).zfill(3)
107-
task = str(task).zfill(3)
108-
return f"{assistant_role}_{user_role}_{task}"
105+
assistant_role_str = str(assistant_role).zfill(3)
106+
user_role_str = str(user_role).zfill(3)
107+
task_str = str(task).zfill(3)
108+
return f"{assistant_role_str}_{user_role_str}_{task_str}"
109109

110110

111111
def solution_extraction(conversation: Dict, flattened_conversation: str,

0 commit comments

Comments
 (0)