Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

fix: update azure model list, remove check for model type (#2347)

Wendong-Fanac4c8e6542e7
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index 21550740b..c96605a11 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -26,7 +26,7 @@ body:
attributes:
label: What version of camel are you using?
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
- placeholder: E.g., 0.2.54
+ placeholder: E.g., 0.2.55
validations:
required: true
diff --git a/camel/__init__.py b/camel/__init__.py
index d313cd91d..e29ad292e 100644
--- a/camel/__init__.py
+++ b/camel/__init__.py
@@ -14,7 +14,7 @@
from camel.logger import disable_logging, enable_logging, set_log_level
-__version__ = '0.2.54'
+__version__ = '0.2.55'
__all__ = [
'__version__',
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.py
index a0bd70076..57995b67f 100644
--- a/camel/agents/chat_agent.py
+++ b/camel/agents/chat_agent.py
@@ -752,7 +752,7 @@ class ChatAgent(BaseAgent):
try:
openai_messages, num_tokens = self.memory.get_context()
except RuntimeError as e:
- return self._step_token_exceed(
+ return self._step_terminate(
e.args[1], tool_call_records, "max_tokens_exceeded"
)
# Get response from model backend
@@ -765,8 +765,8 @@ class ChatAgent(BaseAgent):
# Terminate Agent if stop_event is set
if self.stop_event and self.stop_event.is_set():
- # Use the _step_token_exceed to terminate the agent with reason
- return self._step_token_exceed(
+ # Use the _step_terminate to terminate the agent with reason
+ return self._step_terminate(
num_tokens, tool_call_records, "termination_triggered"
)
@@ -851,7 +851,7 @@ class ChatAgent(BaseAgent):
try:
openai_messages, num_tokens = self.memory.get_context()
except RuntimeError as e:
- return self._step_token_exceed(
+ return self._step_terminate(
e.args[1], tool_call_records, "max_tokens_exceeded"
)
@@ -864,8 +864,8 @@ class ChatAgent(BaseAgent):
# Terminate Agent if stop_event is set
if self.stop_event and self.stop_event.is_set():
- # Use the _step_token_exceed to terminate the agent with reason
- return self._step_token_exceed(
+ # Use the _step_terminate to terminate the agent with reason
+ return self._step_terminate(
num_tokens, tool_call_records, "termination_triggered"
)
@@ -1396,24 +1396,30 @@ class ChatAgent(BaseAgent):
)
output_messages.append(chat_message)
- def _step_token_exceed(
+ def _step_terminate(
self,
num_tokens: int,
tool_calls: List[ToolCallingRecord],
termination_reason: str,
) -> ChatAgentResponse:
- r"""Return trivial response containing number of tokens and information
- of called functions when the number of tokens exceeds.
+ r"""Create a response when the agent execution is terminated.
+
+ This method is called when the agent needs to terminate its execution
+ due to various reasons such as token limit exceeded, or other
+ termination conditions. It creates a response with empty messages but
+ includes termination information in the info dictionary.
Args:
num_tokens (int): Number of tokens in the messages.
tool_calls (List[ToolCallingRecord]): List of information
objects of functions called in the current step.
- termination_reason (str): String of termination reason.
+ termination_reason (str): String describing the reason for
+ termination.
Returns:
- ChatAgentResponse: The struct containing trivial outputs and
- information about token number and called functions.
+ ChatAgentResponse: A response object with empty message list,
+ terminated flag set to True, and an info dictionary containing
+ termination details, token counts, and tool call information.
"""
self.terminated = True
diff --git a/camel/models/model_factory.py b/camel/models/model_factory.py
index b6869c3b4..8fae031b9 100644
--- a/camel/models/model_factory.py
+++ b/camel/models/model_factory.py
@@ -12,7 +12,7 @@
# limitations under the License.
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
import json
-from typing import Dict, Optional, Type, Union
+from typing import ClassVar, Dict, Optional, Type, Union
import yaml
@@ -62,6 +62,44 @@ class ModelFactory:
ValueError: in case the provided model type is unknown.
"""
+ _MODEL_PLATFORM_TO_CLASS_MAP: ClassVar[
+ Dict[ModelPlatformType, Type[BaseModelBackend]]
+ ] = {
+ ModelPlatformType.OLLAMA: OllamaModel,
+ ModelPlatformType.VLLM: VLLMModel,
+ ModelPlatformType.SGLANG: SGLangModel,
+ ModelPlatformType.OPENAI_COMPATIBLE_MODEL: OpenAICompatibleModel,
+ ModelPlatformType.SAMBA: SambaModel,
+ ModelPlatformType.TOGETHER: TogetherAIModel,
+ ModelPlatformType.LITELLM: LiteLLMModel,
+ ModelPlatformType.AWS_BEDROCK: AWSBedrockModel,
+ ModelPlatformType.NVIDIA: NvidiaModel,
+ ModelPlatformType.SILICONFLOW: SiliconFlowModel,
+ ModelPlatformType.AIML: AIMLModel,
+ ModelPlatformType.VOLCANO: VolcanoModel,
+ ModelPlatformType.NETMIND: NetmindModel,
+ ModelPlatformType.OPENAI: OpenAIModel,
+ ModelPlatformType.AZURE: AzureOpenAIModel,
+ ModelPlatformType.ANTHROPIC: AnthropicModel,
+ ModelPlatformType.GROQ: GroqModel,
+ ModelPlatformType.LMSTUDIO: LMStudioModel,
+ ModelPlatformType.OPENROUTER: OpenRouterModel,
+ ModelPlatformType.ZHIPU: ZhipuAIModel,
+ ModelPlatformType.GEMINI: GeminiModel,
+ ModelPlatformType.MISTRAL: MistralModel,
+ ModelPlatformType.REKA: RekaModel,
+ ModelPlatformType.COHERE: CohereModel,
+ ModelPlatformType.YI: YiModel,
+ ModelPlatformType.QWEN: QwenModel,
+ ModelPlatformType.DEEPSEEK: DeepSeekModel,
+ ModelPlatformType.PPIO: PPIOModel,
+ ModelPlatformType.INTERNLM: InternLMModel,
+ ModelPlatformType.MOONSHOT: MoonshotModel,
+ ModelPlatformType.MODELSCOPE: ModelScopeModel,
+ ModelPlatformType.NOVITA: NovitaModel,
+ ModelPlatformType.WATSONX: WatsonXModel,
+ }
+
@staticmethod
def create(
model_platform: Union[ModelPlatformType, str],
@@ -124,81 +162,15 @@ class ModelFactory:
model_class: Optional[Type[BaseModelBackend]] = None
model_type = UnifiedModelType(model_type)
- if model_platform.is_ollama:
- model_class = OllamaModel
- elif model_platform.is_vllm:
- model_class = VLLMModel
- elif model_platform.is_sglang:
- model_class = SGLangModel
- elif model_platform.is_openai_compatible_model:
- model_class = OpenAICompatibleModel
- elif model_platform.is_samba:
- model_class = SambaModel
- elif model_platform.is_together:
- model_class = TogetherAIModel
- elif model_platform.is_litellm:
- model_class = LiteLLMModel
- elif model_platform.is_aws_bedrock:
- model_class = AWSBedrockModel
- elif model_platform.is_nvidia:
- model_class = NvidiaModel
- elif model_platform.is_siliconflow:
- model_class = SiliconFlowModel
- elif model_platform.is_aiml:
- model_class = AIMLModel
- elif model_platform.is_volcano:
- model_class = VolcanoModel
- elif model_platform.is_netmind:
- model_class = NetmindModel
-
- elif model_platform.is_openai and model_type.is_openai:
- model_class = OpenAIModel
- elif model_platform.is_azure and model_type.is_azure_openai:
- model_class = AzureOpenAIModel
- elif model_platform.is_anthropic and model_type.is_anthropic:
- model_class = AnthropicModel
- elif model_platform.is_groq and model_type.is_groq:
- model_class = GroqModel
- elif model_platform.is_lmstudio and model_type.is_lmstudio:
- model_class = LMStudioModel
- elif model_platform.is_openrouter and model_type.is_openrouter:
- model_class = OpenRouterModel
- elif model_platform.is_zhipuai and model_type.is_zhipuai:
- model_class = ZhipuAIModel
- elif model_platform.is_gemini and model_type.is_gemini:
- model_class = GeminiModel
- elif model_platform.is_mistral and model_type.is_mistral:
- model_class = MistralModel
- elif model_platform.is_reka and model_type.is_reka:
- model_class = RekaModel
- elif model_platform.is_cohere and model_type.is_cohere:
- model_class = CohereModel
- elif model_platform.is_yi and model_type.is_yi:
- model_class = YiModel
- elif model_platform.is_qwen and model_type.is_qwen:
- model_class = QwenModel
- elif model_platform.is_deepseek:
- model_class = DeepSeekModel
- elif model_platform.is_ppio:
- model_class = PPIOModel
- elif model_platform.is_internlm and model_type.is_internlm:
- model_class = InternLMModel
- elif model_platform.is_moonshot and model_type.is_moonshot:
- model_class = MoonshotModel
- elif model_platform.is_modelscope:
- model_class = ModelScopeModel
- elif model_platform.is_novita:
- model_class = NovitaModel
- elif model_type == ModelType.STUB:
+ model_class = ModelFactory._MODEL_PLATFORM_TO_CLASS_MAP.get(
+ model_platform
+ )
+
+ if model_type == ModelType.STUB:
model_class = StubModel
- elif model_type.is_watsonx:
- model_class = WatsonXModel
if model_class is None:
- raise ValueError(
- f"Unknown pair of model platform `{model_platform}` "
- f"and model type `{model_type}`."
- )
+ raise ValueError(f"Unknown model platform `{model_platform}`")
return model_class(
model_type=model_type,
diff --git a/camel/toolkits/klavis_toolkit.py b/camel/toolkits/klavis_toolkit.py
index b05876824..e9a6b269a 100644
--- a/camel/toolkits/klavis_toolkit.py
+++ b/camel/toolkits/klavis_toolkit.py
@@ -13,6 +13,7 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
import os
+import urllib.parse
from typing import Any, Dict, List, Optional
import requests
@@ -208,7 +209,7 @@ class KlavisToolkit(BaseToolkit):
Dict[str, Any]: Response containing the list of tools or an error.
"""
- encoded_server_url = requests.utils.quote(server_url, safe='')
+ encoded_server_url = urllib.parse.quote(server_url, safe='')
endpoint = f"/mcp-server/list-tools/{encoded_server_url}"
return self._request('GET', endpoint)
@@ -218,7 +219,8 @@ class KlavisToolkit(BaseToolkit):
tool_name: str,
tool_args: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
- r"""Calls a remote MCP server tool directly using the provided server URL.
+ r"""Calls a remote MCP server tool directly using the provided server
+ URL.
Args:
server_url (str): The full URL for connecting to the MCP server
@@ -226,18 +228,19 @@ class KlavisToolkit(BaseToolkit):
tool_name (str): The name of the tool to call.
tool_args (Optional[Dict[str, Any]]): The input parameters for
the tool. Defaults to None, which might be treated as empty
- args by the server.
+ args by the server. (default: :obj:`None`)
Returns:
Dict[str, Any]: Response containing the result of the tool call
or an error.
"""
endpoint = "/mcp-server/call-tool"
- payload = {
+ payload: Dict[str, Any] = {
"serverUrl": server_url,
"toolName": tool_name,
}
- # Add toolArgs only if provided, otherwise server might expect empty dict
+ # Add toolArgs only if provided, otherwise server might expect empty
+ # dict
if tool_args is not None:
payload["toolArgs"] = tool_args
else:
diff --git a/camel/toolkits/mcp_toolkit.py b/camel/toolkits/mcp_toolkit.py
index 775a60d85..18e0ca4cb 100644
--- a/camel/toolkits/mcp_toolkit.py
+++ b/camel/toolkits/mcp_toolkit.py
@@ -71,7 +71,7 @@ class MCPClient(BaseToolkit):
command_or_url: str,
args: Optional[List[str]] = None,
env: Optional[Dict[str, str]] = None,
- timeout: float = 30,
+ timeout: Optional[float] = None,
headers: Optional[Dict[str, str]] = None,
strict: Optional[bool] = False,
):
@@ -142,7 +142,9 @@ class MCPClient(BaseToolkit):
self._session = await self._exit_stack.enter_async_context(
ClientSession(
- read_stream, write_stream, timedelta(seconds=self.timeout)
+ read_stream,
+ write_stream,
+ timedelta(seconds=self.timeout) if self.timeout else None,
)
)
await self._session.initialize()
diff --git a/camel/types/enums.py b/camel/types/enums.py
index 72e856209..ed2303c98 100644
--- a/camel/types/enums.py
+++ b/camel/types/enums.py
@@ -475,6 +475,16 @@ class ModelType(UnifiedModelType, Enum):
ModelType.GPT_4_TURBO,
ModelType.GPT_4O,
ModelType.GPT_4O_MINI,
+ ModelType.O1,
+ ModelType.O1_PREVIEW,
+ ModelType.O1_MINI,
+ ModelType.O3_MINI,
+ ModelType.GPT_4_5_PREVIEW,
+ ModelType.GPT_4_1,
+ ModelType.GPT_4_1_MINI,
+ ModelType.GPT_4_1_NANO,
+ ModelType.O4_MINI,
+ ModelType.O3,
}
@property
@@ -1389,6 +1399,7 @@ class ModelPlatformType(Enum):
MISTRAL = "mistral"
REKA = "reka"
TOGETHER = "together"
+ STUB = "stub"
OPENAI_COMPATIBLE_MODEL = "openai-compatible-model"
SAMBA = "samba-nova"
COHERE = "cohere"
@@ -1577,6 +1588,11 @@ class ModelPlatformType(Enum):
r"""Returns whether this platform is Novita."""
return self is ModelPlatformType.NOVITA
+ @property
+ def is_watsonx(self) -> bool:
+ r"""Returns whether this platform is WatsonX."""
+ return self is ModelPlatformType.WATSONX
+
class AudioModelType(Enum):
TTS_1 = "tts-1"
diff --git a/docs/conf.py b/docs/conf.py
index 94549a6f3..cba6b26d6 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -27,7 +27,7 @@ sys.path.insert(0, os.path.abspath('..'))
project = 'CAMEL'
copyright = '2024, CAMEL-AI.org'
author = 'CAMEL-AI.org'
-release = '0.2.54'
+release = '0.2.55'
html_favicon = (
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'
diff --git a/docs/key_modules/loaders.md b/docs/key_modules/loaders.md
index fbfa9c1eb..069271035 100644
--- a/docs/key_modules/loaders.md
+++ b/docs/key_modules/loaders.md
@@ -340,14 +340,14 @@ response = jina_reader.read_content("https://docs.camel-ai.org/")
print(response)
```
```markdown
->>>Welcome to CAMEL’s documentation! — CAMEL 0.2.54 documentation
+>>>Welcome to CAMEL’s documentation! — CAMEL 0.2.55 documentation
===============
[Skip to main content](https://docs.camel-ai.org/#main-content)
Back to top Ctrl+K
- [![Image 1](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png) ![Image 2](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png)CAMEL 0.2.54](https://docs.camel-ai.org/#)
+ [![Image 1](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png) ![Image 2](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png)CAMEL 0.2.55](https://docs.camel-ai.org/#)
Search Ctrl+K
diff --git a/examples/test/test_single_agent.py b/examples/test/test_single_agent.py
index 27a732541..f1532c61b 100644
--- a/examples/test/test_single_agent.py
+++ b/examples/test/test_single_agent.py
@@ -25,7 +25,7 @@ parametrize = pytest.mark.parametrize(
'model',
[
ModelFactory.create(
- ModelPlatformType.OPENAI,
+ ModelPlatformType.STUB,
model_type=ModelType.STUB,
),
pytest.param(None, marks=pytest.mark.model_backend),
@@ -42,7 +42,7 @@ def test_single_agent(model):
'model',
[
ModelFactory.create(
- ModelPlatformType.OPENAI,
+ ModelPlatformType.STUB,
model_type=ModelType.STUB,
)
],
diff --git a/misc/wechat.jpeg b/misc/wechat.jpeg
index 451f98353..b87f99c46 100644
Binary files a/misc/wechat.jpeg and b/misc/wechat.jpeg differ
diff --git a/pyproject.toml b/pyproject.toml
index 88301f2b8..a34859dd3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "camel-ai"
-version = "0.2.54"
+version = "0.2.55"
description = "Communicative Agents for AI Society Study"
authors = [{ name = "CAMEL-AI.org" }]
requires-python = ">=3.10,<3.13"
diff --git a/test/toolkits/test_klavis_toolkit.py b/test/toolkits/test_klavis_toolkit.py
index cc18b4c73..f50aeb318 100644
--- a/test/toolkits/test_klavis_toolkit.py
+++ b/test/toolkits/test_klavis_toolkit.py
@@ -218,7 +218,7 @@ def test_set_auth_token(mock_request, klavis_toolkit):
assert result == {"status": "token set"}
-@patch('requests.utils.quote', return_value='encoded_url')
+@patch('urllib.parse.quote', return_value='encoded_url')
@patch.object(KlavisToolkit, '_request')
def test_list_tools(mock_request, mock_quote, klavis_toolkit):
mock_request.return_value = {"tools": ["toolA", "toolB"]}
diff --git a/test/toolkits/test_mcp_toolkit.py b/test/toolkits/test_mcp_toolkit.py
index 6526f5f4b..dc251ade0 100644
--- a/test/toolkits/test_mcp_toolkit.py
+++ b/test/toolkits/test_mcp_toolkit.py
@@ -84,7 +84,7 @@ class TestMCPClient:
# Verify mocks were called correctly
mock_sse_client.assert_called_once_with(
- "https://example.com/api", headers={}
+ "https://example.com/api", headers={}, timeout=None
)
mock_session.assert_called_once()
mock_session_instance.initialize.assert_called_once()
@@ -376,7 +376,7 @@ class TestMCPClient:
# Verify mocks were called correctly
mock_sse_client.assert_called_once_with(
- "https://example.com/api", headers={}
+ "https://example.com/api", headers={}, timeout=None
)
mock_session.assert_called_once()
mock_session_instance.initialize.assert_called_once()
diff --git a/uv.lock b/uv.lock
index f58b954e0..31c6ddbaf 100644
--- a/uv.lock
+++ b/uv.lock
@@ -555,7 +555,7 @@ wheels = [
[[package]]
name = "camel-ai"
-version = "0.2.54"
+version = "0.2.55"
source = { editable = "." }
dependencies = [
{ name = "colorama" },