Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mypy errors #185

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ def role_playing_chat_init(state) -> \
session: RolePlaying = state.session

try:
init_assistant_msg, _ = session.init_chat()
init_assistant_msg: BaseMessage
init_assistant_msg, _ = session.init_chat()
except (openai.error.RateLimitError, tenacity.RetryError,
RuntimeError) as ex:
print("OpenAI API exception 1 " + str(ex))
Expand Down
5 changes: 3 additions & 2 deletions apps/data_explorer/data_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def parse_arguments():
return args


def construct_ui(blocks, datasets: Datasets, default_dataset: str = None):
def construct_ui(blocks, datasets: Datasets,
default_dataset: Optional[str] = None):
""" Build Gradio UI and populate with chat data from JSONs.

Args:
Expand Down Expand Up @@ -226,7 +227,7 @@ def build_chat_history(messages: Dict[int, Dict]) -> List[Tuple]:
Returns:
List[Tuple]: Chat history in chatbot UI element format.
"""
history = []
history: List[Tuple] = []
curr_qa = (None, None)
for k in sorted(messages.keys()):
msg = messages[k]
Expand Down
18 changes: 9 additions & 9 deletions apps/data_explorer/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import glob
import os
import re
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, Optional, Tuple, Union

from tqdm import tqdm

Expand Down Expand Up @@ -111,17 +111,17 @@ def load_zip(zip_path: str) -> AllChats:
continue
parsed_list.append(parsed)

assistant_roles = set()
user_roles = set()
assistant_roles_set = set()
user_roles_set = set()
for parsed in parsed_list:
assistant_roles.add(parsed['assistant_role'])
user_roles.add(parsed['user_role'])
assistant_roles = list(sorted(assistant_roles))
user_roles = list(sorted(user_roles))
matrix: Dict[Tuple[str, str], List[Dict]] = dict()
assistant_roles_set.add(parsed['assistant_role'])
user_roles_set.add(parsed['user_role'])
assistant_roles = list(sorted(assistant_roles_set))
user_roles = list(sorted(user_roles_set))
matrix: Dict[Tuple[str, str], Dict[str, Dict]] = dict()
for parsed in parsed_list:
key = (parsed['assistant_role'], parsed['user_role'])
original_task = parsed['original_task']
original_task: str = parsed['original_task']
new_item = {
k: v
for k, v in parsed.items()
Expand Down
6 changes: 5 additions & 1 deletion camel/societies/role_playing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from typing import Dict, List, Optional, Sequence, Tuple
from typing import Dict, List, Optional, Sequence, Tuple, Union

from camel.agents import (
ChatAgent,
Expand All @@ -23,6 +23,7 @@
from camel.generators import SystemMessageGenerator
from camel.human import Human
from camel.messages import BaseMessage
from camel.prompts import TextPrompt
from camel.typing import ModelType, RoleType, TaskType


Expand Down Expand Up @@ -95,6 +96,7 @@ def __init__(
self.model_type = model_type
self.task_type = task_type

self.specified_task_prompt: Optional[TextPrompt]
if with_task_specify:
task_specify_meta_dict = dict()
if self.task_type in [TaskType.AI_SOCIETY, TaskType.MISALIGNMENT]:
Expand All @@ -118,6 +120,7 @@ def __init__(
else:
self.specified_task_prompt = None

self.planned_task_prompt: Optional[TextPrompt]
if with_task_planner:
task_planner_agent = TaskPlannerAgent(
self.model_type,
Expand Down Expand Up @@ -173,6 +176,7 @@ def __init__(
)
self.user_sys_msg = self.user_agent.system_message

self.critic: Union[CriticAgent, Human, None]
if with_critic_in_the_loop:
if critic_role_name.lower() == "human":
self.critic = Human(**(critic_kwargs or {}))
Expand Down
2 changes: 1 addition & 1 deletion examples/misalignment/role_playing_with_human.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main() -> None:
"CAMEL AGI",
task_prompt=task_prompt,
with_task_specify=True,
with_human_in_the_loop=True,
with_critic_in_the_loop=True,
task_type=TaskType.MISALIGNMENT,
task_specify_agent_kwargs=dict(model_config=ChatGPTConfig(
temperature=1.4)),
Expand Down
8 changes: 4 additions & 4 deletions examples/summarization/gpt_solution_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def flatten_conversation(conversation: Dict) -> str:

def format_combination(combination: Tuple[int, int, int]):
assistant_role, user_role, task = combination
assistant_role = str(assistant_role).zfill(3)
user_role = str(user_role).zfill(3)
task = str(task).zfill(3)
return f"{assistant_role}_{user_role}_{task}"
assistant_role_str = str(assistant_role).zfill(3)
user_role_str = str(user_role).zfill(3)
task_str = str(task).zfill(3)
return f"{assistant_role_str}_{user_role_str}_{task_str}"


def solution_extraction(conversation: Dict, flattened_conversation: str,
Expand Down