出现了 unexpected keyword argument "refusal"
请问如何解决:
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
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
同问,我也出现了这个bug
我也是,请问下如何解决,谢谢
ChatMessage加一个refusal属性即可
class ChatMessage(BaseMessage):
role_name: str
role_type: RoleType
meta_dict: Optional[Dict[str, str]]
role: str
content: str = ""
refusal: str = None
ChatMessage加一个refusal属性即可
class ChatMessage(BaseMessage): role_name: str role_type: RoleType meta_dict: Optional[Dict[str, str]] role: str content: str = "" refusal: str = None
问题解决了,谢谢
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
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
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
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.
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
Solved in https://github.com/OpenBMB/ChatDev/pull/419