ChatDev icon indicating copy to clipboard operation
ChatDev copied to clipboard

出现了 unexpected keyword argument "refusal"

Open 522315428 opened this issue 1 year ago • 8 comments

请问如何解决: Traceback (most recent call last): File "/root/miniconda3/envs/ChatDev_conda_env/lib/python3.9/site-packages/tenacity/init.py", line 382, in call result = fn(*args, **kwargs) File "/code/chatdev/ChatDev/camel/utils.py", line 154, in wrapper return func(self, *args, **kwargs) File "/code/chatdev/ChatDev/camel/agents/chat_agent.py", line 243, in step output_messages = [ File "/code/chatdev/ChatDev/camel/agents/chat_agent.py", line 244, in ChatMessage(role_name=self.role_name, role_type=self.role_type, TypeError: init() got an unexpected keyword argument 'refusal'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/code/chatdev/ChatDev/run.py", line 134, in chat_chain.execute_chain() File "/code/chatdev/ChatDev/chatdev/chat_chain.py", line 168, in execute_chain self.execute_step(phase_item) File "/code/chatdev/ChatDev/chatdev/chat_chain.py", line 138, in execute_step self.chat_env = self.phases[phase].execute(self.chat_env, File "/code/chatdev/ChatDev/chatdev/phase.py", line 295, in execute self.chatting(chat_env=chat_env, File "/code/chatdev/ChatDev/chatdev/utils.py", line 79, in wrapper return func(*args, **kwargs) File "/code/chatdev/ChatDev/chatdev/phase.py", line 133, in chatting assistant_response, user_response = role_play_session.step(input_user_msg, chat_turn_limit == 1) File "/code/chatdev/ChatDev/camel/agents/role_playing.py", line 247, in step assistant_response = self.assistant_agent.step(user_msg_rst) File "/root/miniconda3/envs/ChatDev_conda_env/lib/python3.9/site-packages/tenacity/init.py", line 289, in wrapped_f return self(f, *args, **kw) File "/root/miniconda3/envs/ChatDev_conda_env/lib/python3.9/site-packages/tenacity/init.py", line 379, in call do = self.iter(retry_state=retry_state) File "/root/miniconda3/envs/ChatDev_conda_env/lib/python3.9/site-packages/tenacity/init.py", line 326, in iter raise retry_exc from fut.exception() tenacity.RetryError: RetryError[<Future at 0x7f0049d10c40 state=finished raised TypeError>]

image

522315428 avatar Aug 09 '24 02:08 522315428

同问,我也出现了这个bug

Dingxiangxiang avatar Aug 09 '24 02:08 Dingxiangxiang

我也是,请问下如何解决,谢谢

AaronLearn avatar Aug 09 '24 07:08 AaronLearn

ChatMessage加一个refusal属性即可

class ChatMessage(BaseMessage):
    role_name: str
    role_type: RoleType
    meta_dict: Optional[Dict[str, str]]
    role: str
    content: str = ""
    refusal: str = None

szbuua avatar Aug 09 '24 08:08 szbuua

ChatMessage加一个refusal属性即可

class ChatMessage(BaseMessage):
    role_name: str
    role_type: RoleType
    meta_dict: Optional[Dict[str, str]]
    role: str
    content: str = ""
    refusal: str = None

问题解决了,谢谢

AaronLearn avatar Aug 12 '24 07:08 AaronLearn

hank you so much! How can I get them to continue working on the project and suggest changes to how what they developed looks like? so that from what they delivered they can make improvements

Situsupieras avatar Aug 16 '24 16:08 Situsupieras

Thank you for your solutions! This problem occurs because OpenAI has updated its latest version and added a ‘refusal’ field. If you use the OpenAI version recommended in requirements.txt, similar problems will not occur. If you want to be compatible with the latest version of OpenAI, it is best to change lines 27-57 of the 'messages/base.py' file:

try:
    from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall
    from openai.types.chat.chat_completion_message import FunctionCall
    from openai.types.chat.chat_completion_content_part_refusal_param import ChatCompletionContentPartRefusalParam

    openai_new_api = True  # new openai api version
except ImportError:
    openai_new_api = False  # old openai api version


@dataclass
class BaseMessage:
    r"""Base class for message objects used in CAMEL chat system.

    Args:
        role_name (str): The name of the user or assistant role.
        role_type (RoleType): The type of role, either
            :obj:`RoleType.ASSISTANT` or :obj:`RoleType.USER`.
        meta_dict (Optional[Dict[str, str]]): Additional metadata dictionary
            for the message.
        role (str): The role of the message in OpenAI chat system, either
            :obj:`"system"`, :obj:`"user"`, or :obj:`"assistant"`.
        content (str): The content of the message.
    """
    role_name: str
    role_type: RoleType
    meta_dict: Optional[Dict[str, str]]
    role: str
    content: str
    if openai_new_api:
        function_call: Optional[FunctionCall] = None
        tool_calls: Optional[ChatCompletionMessageToolCall] = None
        refusal: Optional[ChatCompletionContentPartRefusalParam] = None

zhanghb18 avatar Aug 17 '24 04:08 zhanghb18

Thank you for your solutions! This problem occurs because OpenAI has updated its latest version and added a ‘refusal’ field. If you use the OpenAI version recommended in requirements.txt, similar problems will not occur. If you want to be compatible with the latest version of OpenAI, it is best to change lines 27-57 of the 'messages/base.py' file:

try:
    from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall
    from openai.types.chat.chat_completion_message import FunctionCall
    from openai.types.chat.chat_completion_content_part_refusal_param import ChatCompletionContentPartRefusalParam

    openai_new_api = True  # new openai api version
except ImportError:
    openai_new_api = False  # old openai api version


@dataclass
class BaseMessage:
    r"""Base class for message objects used in CAMEL chat system.

    Args:
        role_name (str): The name of the user or assistant role.
        role_type (RoleType): The type of role, either
            :obj:`RoleType.ASSISTANT` or :obj:`RoleType.USER`.
        meta_dict (Optional[Dict[str, str]]): Additional metadata dictionary
            for the message.
        role (str): The role of the message in OpenAI chat system, either
            :obj:`"system"`, :obj:`"user"`, or :obj:`"assistant"`.
        content (str): The content of the message.
    """
    role_name: str
    role_type: RoleType
    meta_dict: Optional[Dict[str, str]]
    role: str
    content: str
    if openai_new_api:
        function_call: Optional[FunctionCall] = None
        tool_calls: Optional[ChatCompletionMessageToolCall] = None
        refusal: Optional[ChatCompletionContentPartRefusalParam] = None

try to apply this fix, but it doesn't not work 30d29 <     from openai.types.chat.chat_completion_content_part_refusal_param import ChatCompletionContentPartRefusalParam 59d57 <         refusal: Optional[ChatCompletionContentPartRefusalParam] = None

liu-yong avatar Aug 17 '24 15:08 liu-yong

Thank you for your solutions! This problem occurs because OpenAI has updated its latest version and added a ‘refusal’ field. If you use the OpenAI version recommended in requirements.txt, similar problems will not occur. If you want to be compatible with the latest version of OpenAI, it is best to change lines 27-57 of the 'messages/base.py' file:

try:
    from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall
    from openai.types.chat.chat_completion_message import FunctionCall
    from openai.types.chat.chat_completion_content_part_refusal_param import ChatCompletionContentPartRefusalParam

    openai_new_api = True  # new openai api version
except ImportError:
    openai_new_api = False  # old openai api version


@dataclass
class BaseMessage:
    r"""Base class for message objects used in CAMEL chat system.

    Args:
        role_name (str): The name of the user or assistant role.
        role_type (RoleType): The type of role, either
            :obj:`RoleType.ASSISTANT` or :obj:`RoleType.USER`.
        meta_dict (Optional[Dict[str, str]]): Additional metadata dictionary
            for the message.
        role (str): The role of the message in OpenAI chat system, either
            :obj:`"system"`, :obj:`"user"`, or :obj:`"assistant"`.
        content (str): The content of the message.
    """
    role_name: str
    role_type: RoleType
    meta_dict: Optional[Dict[str, str]]
    role: str
    content: str
    if openai_new_api:
        function_call: Optional[FunctionCall] = None
        tool_calls: Optional[ChatCompletionMessageToolCall] = None
        refusal: Optional[ChatCompletionContentPartRefusalParam] = None

This fix worked for me.

lodr74 avatar Aug 21 '24 00:08 lodr74

Just add a refusal attribute to ChatMessage

class ChatMessage(BaseMessage):
    role_name: str
    role_type: RoleType
    meta_dict: Optional[Dict[str, str]]
    role: str
    content: str = ""
    refusal: str = None

For anyone wondering where the file to be edited is, it is located /Chatdev/camel/agents/messages/chat_messages.py

KennethKim7611 avatar Aug 24 '24 19:08 KennethKim7611

Solved in https://github.com/OpenBMB/ChatDev/pull/419

thinkwee avatar Aug 28 '24 03:08 thinkwee