🐫 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
feat:add Netmind platform (#2268)
Yifeng Wang(正经人王同学)a422dfd83e07
diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.ymlindex c1b7189da..5e0c57a1b 100644--- a/.github/workflows/build_package.yml+++ b/.github/workflows/build_package.yml@@ -106,6 +106,7 @@ jobs:PPIO_API_KEY: "${{ secrets.PPIO_API_KEY }}"BEDROCK_API_KEY: "${{ secrets.BEDROCK_API_KEY }}"BEDROCK_API_BASE_URL: "${{ secrets.BEDROCK_API_BASE_URL }}"+ NETMIND_API_KEY: "${{ secrets.NETMIND_API_KEY }}"run: |source test_venv/bin/activatepytest --fast-test-mode ./testdiff --git a/.github/workflows/pytest_package.yml b/.github/workflows/pytest_package.ymlindex fddf2e711..f872c4d0d 100644--- a/.github/workflows/pytest_package.yml+++ b/.github/workflows/pytest_package.yml@@ -71,6 +71,7 @@ jobs:PPIO_API_KEY: "${{ secrets.PPIO_API_KEY }}"BEDROCK_API_KEY: "${{ secrets.BEDROCK_API_KEY }}"BEDROCK_API_BASE_URL: "${{ secrets.BEDROCK_API_BASE_URL }}"+ NETMIND_API_KEY: "${{ secrets.NETMIND_API_KEY }}"run: |source .venv/bin/activateuv pip install -e ".[all, dev, docs]"@@ -134,6 +135,7 @@ jobs:PPIO_API_KEY: "${{ secrets.PPIO_API_KEY }}"BEDROCK_API_KEY: "${{ secrets.BEDROCK_API_KEY }}"BEDROCK_API_BASE_URL: "${{ secrets.BEDROCK_API_BASE_URL }}"+ NETMIND_API_KEY: "${{ secrets.NETMIND_API_KEY }}"run: |source .venv/bin/activateuv pip install -e ".[all, dev, docs]"@@ -195,6 +197,7 @@ jobs:PPIO_API_KEY: "${{ secrets.PPIO_API_KEY }}"BEDROCK_API_KEY: "${{ secrets.BEDROCK_API_KEY }}"BEDROCK_API_BASE_URL: "${{ secrets.BEDROCK_API_BASE_URL }}"+ NETMIND_API_KEY: "${{ secrets.NETMIND_API_KEY }}"run: |source .venv/bin/activateuv pip install -e ".[all, dev, docs]"diff --git a/camel/configs/__init__.py b/camel/configs/__init__.pyindex 44a1b0260..45fd107a2 100644--- a/camel/configs/__init__.py+++ b/camel/configs/__init__.py@@ -25,6 +25,7 @@ from .lmstudio_config import LMSTUDIO_API_PARAMS, LMStudioConfigfrom .mistral_config import MISTRAL_API_PARAMS, MistralConfigfrom .modelscope_config import MODELSCOPE_API_PARAMS, ModelScopeConfigfrom .moonshot_config import MOONSHOT_API_PARAMS, MoonshotConfig+from .netmind_config import NETMIND_API_PARAMS, NetmindConfigfrom .nvidia_config import NVIDIA_API_PARAMS, NvidiaConfigfrom .ollama_config import OLLAMA_API_PARAMS, OllamaConfigfrom .openai_config import OPENAI_API_PARAMS, ChatGPTConfig@@ -55,6 +56,8 @@ __all__ = ['GroqConfig','LiteLLMConfig','LITELLM_API_PARAMS',+ 'NetmindConfig',+ 'NETMIND_API_PARAMS','NvidiaConfig','NVIDIA_API_PARAMS','OllamaConfig',diff --git a/camel/configs/netmind_config.py b/camel/configs/netmind_config.pynew file mode 100644index 000000000..847120436--- /dev/null+++ b/camel/configs/netmind_config.py@@ -0,0 +1,82 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+from __future__ import annotations++from typing import Dict, List, Optional, Union++from pydantic import Field++from camel.configs.base_config import BaseConfig+from camel.types import NotGiven+++class NetmindConfig(BaseConfig):+ r"""Defines the parameters for generating chat completions using OpenAI+ compatibility.++ Reference: https://netmind-power.gitbook.io/netmind-power-documentation/+ api/inference/chat++ Args:+ presence_penalty (float, optional): Number between :obj:`-2.0` and+ :obj:`2.0`. Positive values penalize new tokens based on whether+ they appear in the text so far, increasing the model's likelihood+ to talk about new topics. See more information about frequency and+ presence penalties. (default: :obj:`None`)+ frequency_penalty (float, optional): Number between :obj:`-2.0` and+ :obj:`2.0`. Positive values penalize new tokens based on their+ existing frequency in the text so far, decreasing the model's+ likelihood to repeat the same line verbatim. See more information+ about frequency and presence penalties. (default: :obj:`None`)+ repetition_penalty (float, optional): Penalizes new tokens based on+ their appearance in the prompt and generated text.+ (default: :obj:`None`)+ stream (bool, optional): Whether to stream the response.+ (default: :obj:`None`)+ temperature (float, optional): Controls randomness in the response.+ Higher values make output more random, lower values make it more+ deterministic. Range: [0.0, 2.0]. (default: :obj:`None`)+ top_p (float, optional): Controls diversity via nucleus sampling.+ Range: [0.0, 1.0]. (default: :obj:`None`)+ logit_bias (dict, optional): Modify the likelihood of specified tokens+ appearing in the completion. Accepts a json object that maps tokens+ (specified by their token ID in the tokenizer) to an associated+ bias value from :obj:`-100` to :obj:`100`. Mathematically, the bias+ is added to the logits generated by the model prior to sampling.+ The exact effect will vary per model, but values between:obj:` -1`+ and :obj:`1` should decrease or increase likelihood of selection;+ values like :obj:`-100` or :obj:`100` should result in a ban or+ exclusive selection of the relevant token. (default: :obj:`None`)+ max_tokens (Union[int, NotGiven], optional): Maximum number of tokens+ to generate. If not provided, model will use its default maximum.+ (default: :obj:`None`)+ stop (Optional[List[str]], optional): List of stop sequences.+ (default: :obj:`None`)+ n (Optional[int], optional): Number of chat completion choices to+ generate for each input message. (default: :obj:`None`)+ """++ stream: Optional[bool] = Field(default=None)+ temperature: Optional[float] = Field(default=None)+ top_p: Optional[float] = Field(default=None)+ presence_penalty: Optional[float] = Field(default=None)+ frequency_penalty: Optional[float] = Field(default=None)+ repetition_penalty: Optional[float] = Field(default=None)+ max_tokens: Optional[Union[int, NotGiven]] = Field(default=None)+ stop: Optional[List[str]] = Field(default=None)+ n: Optional[int] = Field(default=None)+ logit_bias: Optional[Dict[str, float]] = Field(default=None)+++NETMIND_API_PARAMS = {param for param in NetmindConfig.model_fields.keys()}diff --git a/camel/models/__init__.py b/camel/models/__init__.pyindex aa5b71402..6e3a2b1bb 100644--- a/camel/models/__init__.py+++ b/camel/models/__init__.py@@ -31,6 +31,7 @@ from .model_manager import ModelManager, ModelProcessingErrorfrom .modelscope_model import ModelScopeModelfrom .moonshot_model import MoonshotModelfrom .nemotron_model import NemotronModel+from .netmind_model import NetmindModelfrom .nvidia_model import NvidiaModelfrom .ollama_model import OllamaModelfrom .openai_audio_models import OpenAIAudioModels@@ -65,6 +66,7 @@ __all__ = ['ModelManager','LiteLLMModel','OpenAIAudioModels',+ 'NetmindModel','NemotronModel','NvidiaModel','OllamaModel',diff --git a/camel/models/model_factory.py b/camel/models/model_factory.pyindex 2f40e769d..fac2836d3 100644--- a/camel/models/model_factory.py+++ b/camel/models/model_factory.py@@ -31,6 +31,7 @@ from camel.models.lmstudio_model import LMStudioModelfrom camel.models.mistral_model import MistralModelfrom camel.models.modelscope_model import ModelScopeModelfrom camel.models.moonshot_model import MoonshotModel+from camel.models.netmind_model import NetmindModelfrom camel.models.nvidia_model import NvidiaModelfrom camel.models.ollama_model import OllamaModelfrom camel.models.openai_compatible_model import OpenAICompatibleModel@@ -123,6 +124,8 @@ class ModelFactory:model_class = AIMLModelelif model_platform.is_volcano:model_class = VolcanoModel+ elif model_platform.is_netmind:+ model_class = NetmindModelelif model_platform.is_openai and model_type.is_openai:model_class = OpenAIModeldiff --git a/camel/models/netmind_model.py b/camel/models/netmind_model.pynew file mode 100644index 000000000..36b33c291--- /dev/null+++ b/camel/models/netmind_model.py@@ -0,0 +1,96 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++import os+from typing import Any, Dict, Optional, Union++from camel.configs import NETMIND_API_PARAMS, NetmindConfig+from camel.models.openai_compatible_model import OpenAICompatibleModel+from camel.types import ModelType+from camel.utils import (+ BaseTokenCounter,+ api_keys_required,+)+++class NetmindModel(OpenAICompatibleModel):+ r"""Constructor for Netmind backend with OpenAI compatibility.++ Args:+ model_type (Union[ModelType, str]): Model for which a backend is+ created, supported model can be found here:+ https://www.netmind.ai/modelsLibrary?expandList=Chat+ model_config_dict (Optional[Dict[str, Any]], optional): A dictionary+ that will be fed into:obj:`openai.ChatCompletion.create()`. If+ :obj:`None`, :obj:`NetmindConfig().as_dict()` will be used.+ (default: :obj:`None`)+ api_key (Optional[str], optional): The API key for authenticating with+ the Netmind service. (default: :obj:`None`)+ url (Optional[str], optional): The url to the Netmind service.+ If not provided, "https://api.netmind.ai/inference-api/openai/v1"+ will be used.(default: :obj:`None`)+ token_counter (Optional[BaseTokenCounter], optional): Token counter to+ use for the model. If not provided, :obj:`OpenAITokenCounter(+ ModelType.GPT_4O_MINI)` will be used.+ timeout (Optional[float], optional): The timeout value in seconds for+ API calls. If not provided, will fall back to the MODEL_TIMEOUT+ environment variable or default to 180 seconds.+ (default: :obj:`None`)+ """++ @api_keys_required(+ [+ ("api_key", 'NETMIND_API_KEY'),+ ]+ )+ def __init__(+ self,+ model_type: Union[ModelType, str],+ model_config_dict: Optional[Dict[str, Any]] = None,+ api_key: Optional[str] = None,+ url: Optional[str] = None,+ token_counter: Optional[BaseTokenCounter] = None,+ timeout: Optional[float] = None,+ ) -> None:+ if model_config_dict is None:+ model_config_dict = NetmindConfig().as_dict()+ api_key = api_key or os.environ.get("NETMIND_API_KEY")+ url = url or os.environ.get(+ "NETMIND_API_BASE_URL",+ "https://api.netmind.ai/inference-api/openai/v1",+ )+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))+ super().__init__(+ model_type=model_type,+ model_config_dict=model_config_dict,+ api_key=api_key,+ url=url,+ token_counter=token_counter,+ timeout=timeout,+ )++ def check_model_config(self):+ r"""Check whether the model configuration contains any+ unexpected arguments to NETMIND API.++ Raises:+ ValueError: If the model configuration dictionary contains any+ unexpected arguments to NETMIND API.+ """+ for param in self.model_config_dict:+ if param not in NETMIND_API_PARAMS:+ raise ValueError(+ f"Unexpected argument `{param}` is "+ "input into NETMIND model backend."+ )diff --git a/camel/types/enums.py b/camel/types/enums.pyindex 7d5b5bdfe..f36754d5b 100644--- a/camel/types/enums.py+++ b/camel/types/enums.py@@ -149,6 +149,18 @@ class ModelType(UnifiedModelType, Enum):CLAUDE_3_5_HAIKU = "claude-3-5-haiku-latest"CLAUDE_3_7_SONNET = "claude-3-7-sonnet-latest"+ # Netmind models+ NETMIND_LLAMA_4_MAVERICK_17B_128E_INSTRUCT = (+ "meta-llama/Llama-4-Maverick-17B-128E-Instruct"+ )+ NETMIND_LLAMA_4_SCOUT_17B_16E_INSTRUCT = (+ "meta-llama/Llama-4-Scout-17B-16E-Instruct"+ )+ NETMIND_DEEPSEEK_R1 = "deepseek-ai/DeepSeek-R1"+ NETMIND_DEEPSEEK_V3 = "deepseek-ai/DeepSeek-V3-0324"+ NETMIND_DOUBAO_1_5_PRO = "doubao/Doubao-1.5-pro"+ NETMIND_QWQ_32B = "Qwen/QwQ-32B"+# Nvidia modelsNVIDIA_NEMOTRON_340B_INSTRUCT = "nvidia/nemotron-4-340b-instruct"NVIDIA_NEMOTRON_340B_REWARD = "nvidia/nemotron-4-340b-reward"@@ -606,6 +618,17 @@ class ModelType(UnifiedModelType, Enum):ModelType.DEEPSEEK_REASONER,}+ @property+ def is_netmind(self) -> bool:+ return self in {+ ModelType.NETMIND_LLAMA_4_MAVERICK_17B_128E_INSTRUCT,+ ModelType.NETMIND_LLAMA_4_SCOUT_17B_16E_INSTRUCT,+ ModelType.NETMIND_DEEPSEEK_R1,+ ModelType.NETMIND_DEEPSEEK_V3,+ ModelType.NETMIND_DOUBAO_1_5_PRO,+ ModelType.NETMIND_QWQ_32B,+ }+@propertydef is_ppio(self) -> bool:return self in {@@ -759,6 +782,11 @@ class ModelType(UnifiedModelType, Enum):ModelType.PPIO_YI_1_5_34B_CHAT,}:return 16_384++ elif self in {+ ModelType.NETMIND_DOUBAO_1_5_PRO,+ }:+ return 32_000elif self in {ModelType.MISTRAL_CODESTRAL,ModelType.MISTRAL_7B,@@ -814,6 +842,7 @@ class ModelType(UnifiedModelType, Enum):ModelType.PPIO_DEEPSEEK_R1,ModelType.PPIO_DEEPSEEK_V3,ModelType.AWS_DEEPSEEK_R1,+ ModelType.NETMIND_QWQ_32B,}:return 64_000elif self in {@@ -863,6 +892,8 @@ class ModelType(UnifiedModelType, Enum):ModelType.AWS_LLAMA_3_3_70B_INSTRUCT,ModelType.AWS_LLAMA_3_2_90B_INSTRUCT,ModelType.AWS_LLAMA_3_2_11B_INSTRUCT,+ ModelType.NETMIND_DEEPSEEK_R1,+ ModelType.NETMIND_DEEPSEEK_V3,}:return 128_000elif self in {@@ -906,8 +937,14 @@ class ModelType(UnifiedModelType, Enum):ModelType.OPENROUTER_LLAMA_4_MAVERICK_FREE,}:return 256_000++ elif self in {+ ModelType.NETMIND_LLAMA_4_SCOUT_17B_16E_INSTRUCT,+ }:+ return 320_000elif self in {ModelType.OPENROUTER_LLAMA_4_SCOUT_FREE,+ ModelType.NETMIND_LLAMA_4_MAVERICK_17B_128E_INSTRUCT,}:return 512_000elif self in {@@ -1121,6 +1158,7 @@ class ModelPlatformType(Enum):SILICONFLOW = "siliconflow"AIML = "aiml"VOLCANO = "volcano"+ NETMIND = "netmind"@classmethoddef from_name(cls, name):@@ -1246,6 +1284,11 @@ class ModelPlatformType(Enum):r"""Returns whether this platform is DeepSeek."""return self is ModelPlatformType.DEEPSEEK+ @property+ def is_netmind(self) -> bool:+ r"""Returns whether this platform is Netmind."""+ return self is ModelPlatformType.NETMIND+@propertydef is_ppio(self) -> bool:r"""Returns whether this platform is PPIO."""diff --git a/camel/types/unified_model_type.py b/camel/types/unified_model_type.pyindex dffc4ecbd..180ad534d 100644--- a/camel/types/unified_model_type.py+++ b/camel/types/unified_model_type.py@@ -113,6 +113,11 @@ class UnifiedModelType(str):r"""Returns whether the model is a Mistral model."""return True+ @property+ def is_netmind(self) -> bool:+ r"""Returns whether the model is a Netmind model."""+ return True+@propertydef is_reka(self) -> bool:r"""Returns whether the model is a Reka model."""diff --git a/docs/key_modules/models.md b/docs/key_modules/models.mdindex ded769b4d..bd32c2aac 100644--- a/docs/key_modules/models.md+++ b/docs/key_modules/models.md@@ -35,6 +35,7 @@ CAMEL supports a wide range of models, including [OpenAI’s GPT series](https:/| **LMStudio** | [supported models](https://lmstudio.ai/models) || **vLLM** | [supported models](https://docs.vllm.ai/en/latest/models/supported_models.html) || **SGLANG** | [supported models](https://sgl-project.github.io/references/supported_models.html) |+| **NetMind** | [supported models](https://www.netmind.ai/modelsLibrary) || **NVIDIA** | [supported models](https://docs.api.nvidia.com/nim/reference/llm-apis) || **AIML** | [supported models](https://docs.aimlapi.com/api-overview/model-database/text-models) || **ModelScope** | [supported models](https://www.modelscope.cn/docs/model-service/API-Inference/intro) |diff --git a/examples/models/netmind_model_example.py b/examples/models/netmind_model_example.pynew file mode 100644index 000000000..086a6d2ea--- /dev/null+++ b/examples/models/netmind_model_example.py@@ -0,0 +1,45 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+from camel.agents import ChatAgent+from camel.configs import NetmindConfig+from camel.models import ModelFactory+from camel.types import ModelPlatformType, ModelType++model = ModelFactory.create(+ model_platform=ModelPlatformType.NETMIND,+ model_type=ModelType.NETMIND_DEEPSEEK_R1,+ model_config_dict=NetmindConfig(temperature=0.2).as_dict(),+)++# Define system message+sys_msg = "You are a helpful assistant."++# Set agent+camel_agent = ChatAgent(system_message=sys_msg, model=model)++user_msg = """how many 'r' in the word 'strawberry?'"""++# Get response information+response = camel_agent.step(user_msg)+print(response.msgs[0].content)+'''+===============================================================================+The word "strawberry" contains **3** instances of the letter 'r'.++Here's the breakdown:+**S** - **T** - **R** - **A** - **W** - **B** - **E** - **R** - **R** - **Y**+Positions 3, 8, and 9.+===============================================================================++'''diff --git a/test/models/test_netmind_model.py b/test/models/test_netmind_model.pynew file mode 100644index 000000000..b046b318e--- /dev/null+++ b/test/models/test_netmind_model.py@@ -0,0 +1,74 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+import re++import pytest++from camel.configs import NetmindConfig+from camel.models import NetmindModel+from camel.types import ModelType+from camel.utils import OpenAITokenCounter++[email protected]_backend+ "model_type",+ [+ ModelType.NETMIND_LLAMA_4_MAVERICK_17B_128E_INSTRUCT,+ ModelType.NETMIND_LLAMA_4_SCOUT_17B_16E_INSTRUCT,+ ModelType.NETMIND_DEEPSEEK_R1,+ ModelType.NETMIND_DEEPSEEK_V3,+ ModelType.NETMIND_DOUBAO_1_5_PRO,+ ModelType.NETMIND_QWQ_32B,+ ],+)+def test_netmind_model(model_type: ModelType):+ model = NetmindModel(model_type)++ assert model.model_type == model_type++ assert model.model_config_dict == NetmindConfig().as_dict()++ assert isinstance(model.token_counter, OpenAITokenCounter)++ assert isinstance(model.model_type.value_for_tiktoken, str)++ assert isinstance(model.model_type.token_limit, int)++[email protected]_backend+def test_netmind_model_unexpected_argument():+ model_type = ModelType.NETMIND_LLAMA_4_SCOUT_17B_16E_INSTRUCT++ model_config_dict = {+ "model_path": "netmind_llama_4_scout_17b_16e_instruct"+ }++ with pytest.raises(+ ValueError,+ match=re.escape(+ (+ "Unexpected argument `model_path` is "+ "input into NETMIND model backend."+ )+ ),+ ):+ _ = NetmindModel(model_type, model_config_dict)++[email protected]_backend+def test_netmind_model_stream_property():+ model = NetmindModel(ModelType.NETMIND_LLAMA_4_SCOUT_17B_16E_INSTRUCT)++ assert model.stream is False