Closed 522315428 closed 2 months ago
同问,我也出现了这个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
请问如何解决: 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>]