🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
fix: Base model handle image type (#1633)
Wendong-Fan5af4abad1cea
diff --git a/camel/models/base_model.py b/camel/models/base_model.pyindex 97955caed..1339902bc 100644--- a/camel/models/base_model.py+++ b/camel/models/base_model.py@@ -103,7 +103,7 @@ class BaseModelBackend(ABC, metaclass=ModelBackendMeta):self, messages: List[OpenAIMessage]) -> List[OpenAIMessage]:r"""Preprocess messages before sending to model API.- Removes thinking content and other model-specific preprocessing.+ Removes thinking content from assistant and user messages.Args:messages (List[OpenAIMessage]): Original messages@@ -111,18 +111,32 @@ class BaseModelBackend(ABC, metaclass=ModelBackendMeta):Returns:List[OpenAIMessage]: Preprocessed messages"""- # Remove thinking content from messages before sending to API- # This ensures only the final response is sent, excluding- # intermediate thought processes- return [- { # type: ignore[misc]- **msg,- 'content': re.sub(++ def should_process_thinking(msg: OpenAIMessage) -> bool:+ # Only process thinking content for assistant and user messages+ return msg['role'] in ['assistant', 'user'] and isinstance(+ msg['content'], str+ )++ def remove_thinking(content: str) -> str:+ # Only remove thinking content if the tags are present+ if '<think>' in content and '</think>' in content:+ return re.sub(r'<think>.*?</think>','',- msg['content'], # type: ignore[arg-type]+ content,flags=re.DOTALL,- ).strip(),+ ).strip()+ return content++ return [+ { # type: ignore[misc]+ **msg,+ 'content': (+ remove_thinking(msg['content']) # type: ignore[arg-type]+ if should_process_thinking(msg)+ else msg['content']+ ),}for msg in messages]diff --git a/camel/utils/commons.py b/camel/utils/commons.pyindex d6e211b9e..a2d05e1f9 100644--- a/camel/utils/commons.py+++ b/camel/utils/commons.py@@ -306,49 +306,51 @@ def api_keys_required(value = os.environ.get(env_var_name)if not value or value.strip() == "":missing_keys.append(env_var_name)-+key_way = "the official website"- if env_var_name=='ANTHROPIC_API_KEY':- key_way = "https://docs.anthropic.com/zh-CN/api/getting-started"- elif env_var_name=='AIML_API_KEY':+ if env_var_name == 'ANTHROPIC_API_KEY':+ key_way = (+ "https://docs.anthropic.com/zh-CN/api/getting-started"+ )+ elif env_var_name == 'AIML_API_KEY':key_way = "https://aimlapi.com/"- elif env_var_name=='COHERE_API_KEY':+ elif env_var_name == 'COHERE_API_KEY':key_way = "https://cohere.com/"- elif env_var_name=='DEEPSEEK_API_KEY':+ elif env_var_name == 'DEEPSEEK_API_KEY':key_way = "https://www.deepseek.com/"- elif env_var_name=='AZURE_OPENAI_API_KEY':+ elif env_var_name == 'AZURE_OPENAI_API_KEY':key_way = "https://portal.azure.com/"- elif env_var_name=='OPENAI_API_KEY':+ elif env_var_name == 'OPENAI_API_KEY':key_way = "https://platform.openai.com/docs/overview"- elif env_var_name=='FISHAUDIO_API_KEY':+ elif env_var_name == 'FISHAUDIO_API_KEY':key_way = "https://fish.audio/"- elif env_var_name=='GEMINI_API_KEY':+ elif env_var_name == 'GEMINI_API_KEY':key_way = "https://gemini.google.com/"- elif env_var_name=='INTERNLM_API_KEY':+ elif env_var_name == 'INTERNLM_API_KEY':key_way = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1"- elif env_var_name=='GROQ_API_KEY':+ elif env_var_name == 'GROQ_API_KEY':key_way = "https://api.groq.com/openai/v1"- elif env_var_name=='MISTRAL_API_KEY':+ elif env_var_name == 'MISTRAL_API_KEY':key_way = "https://mistral.ai/"- elif env_var_name=='MOONSHOT_API_KEY':+ elif env_var_name == 'MOONSHOT_API_KEY':key_way = "https://api.moonshot.cn/v1"- elif env_var_name=='NVIDIA_API_KEY':+ elif env_var_name == 'NVIDIA_API_KEY':key_way = "https://integrate.api.nvidia.com/"- elif env_var_name=='OPENAI_COMPATIBILIY_API_KEY':+ elif env_var_name == 'OPENAI_COMPATIBILIY_API_KEY':key_way = "https://platform.openai.com/docs/overview"- elif env_var_name=='QWEN_API_KEY':+ elif env_var_name == 'QWEN_API_KEY':key_way = "https://tongyi.aliyun.com/"- elif env_var_name=='REKA_API_KEY':+ elif env_var_name == 'REKA_API_KEY':key_way = "https://docs.reka.ai/quick-start"- elif env_var_name=='SAMBA_API_KEY':+ elif env_var_name == 'SAMBA_API_KEY':key_way = "https://community.sambanova.ai/t/looking-for-api-key-and-url-for-sambanova/576"- elif env_var_name=='TOGETHER_API_KEY':+ elif env_var_name == 'TOGETHER_API_KEY':key_way = "https://docs.together.ai/docs/quickstart"- elif env_var_name=='YI_API_KEY':+ elif env_var_name == 'YI_API_KEY':key_way = "https://platform.lingyiwanwu.com/docs"- elif env_var_name=='ZHIPUAI_API_KEY':+ elif env_var_name == 'ZHIPUAI_API_KEY':key_way = "https://www.zhipuai.cn/"-+if missing_keys:raise ValueError("Missing or empty required API keys in "diff --git a/test/models/test_base_model.py b/test/models/test_base_model.pyindex 06e6688d3..aaa326c0b 100644--- a/test/models/test_base_model.py+++ b/test/models/test_base_model.py@@ -66,6 +66,32 @@ class TestBaseModelBackend:processed = model.preprocess_messages(messages)assert processed[0]['content'] == 'plain message'+ # Test normal thinking sections+ messages = [+ {'role': 'user', 'content': 'Start <think>Think</think>End'}+ ]+ processed = model.preprocess_messages(messages)+ assert processed[0]['content'] == 'Start End'++ # Test system messages (should not be processed)+ messages = [+ {+ 'role': 'system',+ 'content': 'System <think>thinking</think> message',+ }+ ]+ processed = model.preprocess_messages(messages)+ assert (+ processed[0]['content'] == 'System <think>thinking</think> message'+ )++ # Test empty thinking tags+ messages = [+ {'role': 'assistant', 'content': 'Before<think></think>After'}+ ]+ processed = model.preprocess_messages(messages)+ assert processed[0]['content'] == 'BeforeAfter'+def test_metaclass_preprocessing(self):r"""Test that metaclass automatically preprocesses messages in runmethod."""