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

feat: Integrate ModelScope models to camel (#2019)

Yunlin Mao6fd287258777
diff --git a/.env b/.env
index e9f79f382..70043a348 100644
--- a/.env
+++ b/.env
@@ -56,6 +56,9 @@
# Moonshot API (https://platform.moonshot.cn/)
# MOONSHOT_API_KEY="Fill your API key here"
+# ModelScope API (https://www.modelscope.cn/my/myaccesstoken)
+# MODELSCOPE_SDK_TOKEN="Fill your API key here"
+
# JINA API (https://jina.ai/)
# JINA_API_KEY="Fill your API key here"
diff --git a/camel/configs/__init__.py b/camel/configs/__init__.py
index 22ff9c3ac..402ed0e0f 100644
--- a/camel/configs/__init__.py
+++ b/camel/configs/__init__.py
@@ -21,6 +21,7 @@ from .groq_config import GROQ_API_PARAMS, GroqConfig
from .internlm_config import INTERNLM_API_PARAMS, InternLMConfig
from .litellm_config import LITELLM_API_PARAMS, LiteLLMConfig
from .mistral_config import MISTRAL_API_PARAMS, MistralConfig
+from .modelscope_config import MODELSCOPE_API_PARAMS, ModelScopeConfig
from .moonshot_config import MOONSHOT_API_PARAMS, MoonshotConfig
from .nvidia_config import NVIDIA_API_PARAMS, NvidiaConfig
from .ollama_config import OLLAMA_API_PARAMS, OllamaConfig
@@ -85,6 +86,8 @@ __all__ = [
'INTERNLM_API_PARAMS',
'MoonshotConfig',
"MOONSHOT_API_PARAMS",
+ 'ModelScopeConfig',
+ 'MODELSCOPE_API_PARAMS',
'SiliconFlowConfig',
'SILICONFLOW_API_PARAMS',
'AIMLConfig',
diff --git a/camel/configs/modelscope_config.py b/camel/configs/modelscope_config.py
new file mode 100644
index 000000000..18e2b5368
--- /dev/null
+++ b/camel/configs/modelscope_config.py
@@ -0,0 +1,59 @@
+# ========= 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 Optional, Union
+
+from camel.configs.base_config import BaseConfig
+
+
+class ModelScopeConfig(BaseConfig):
+ r"""Defines the parameters for generating chat completions using the
+ ModelScope API. You can refer to the following link for more details:
+ https://www.modelscope.cn/docs/model-service/API-Inference/intro
+
+ Args:
+ tool_choice (Union[dict[str, str], str], optional): Controls which (if
+ any) tool is called by the model. :obj:`"none"` means the model
+ will not call any tool and instead generates a message.
+ :obj:`"auto"` means the model can pick between generating a
+ message or calling one or more tools. :obj:`"required"` or
+ specifying a particular tool via
+ {"type": "function", "function": {"name": "some_function"}}
+ can be used to guide the model to use tools more strongly.
+ (default: :obj:`None`)
+ max_tokens (int, optional): Specifies the maximum number of tokens
+ the model can generate. This sets an upper limit, but does not
+ guarantee that this number will always be reached.
+ (default: :obj:`None`)
+ top_p (float, optional): Controls the randomness of the generated
+ results. Lower values lead to less randomness, while higher
+ values increase randomness. (default: :obj:`None`)
+ temperature (float, optional): Controls the diversity and focus of
+ the generated results. Lower values make the output more focused,
+ while higher values make it more diverse. (default: :obj:`0.3`)
+ stream (bool, optional): If True, enables streaming output.
+ (default: :obj:`None`)
+ """
+
+ tool_choice: Optional[Union[dict[str, str], str]] = None
+ max_tokens: Optional[int] = None
+ top_p: Optional[float] = None
+ temperature: Optional[float] = None
+ stream: Optional[bool] = None
+
+
+MODELSCOPE_API_PARAMS = {
+ param for param in ModelScopeConfig.model_fields.keys()
+}
diff --git a/camel/models/__init__.py b/camel/models/__init__.py
index fa71d4380..43d6ad9f5 100644
--- a/camel/models/__init__.py
+++ b/camel/models/__init__.py
@@ -26,6 +26,7 @@ from .litellm_model import LiteLLMModel
from .mistral_model import MistralModel
from .model_factory import ModelFactory
from .model_manager import ModelManager, ModelProcessingError
+from .modelscope_model import ModelScopeModel
from .moonshot_model import MoonshotModel
from .nemotron_model import NemotronModel
from .nvidia_model import NvidiaModel
@@ -77,6 +78,7 @@ __all__ = [
'DeepSeekModel',
'FishAudioModel',
'InternLMModel',
+ 'ModelScopeModel',
'MoonshotModel',
'AIMLModel',
'BaseAudioModel',
diff --git a/camel/models/model_factory.py b/camel/models/model_factory.py
index 42563e8cd..91f580cfa 100644
--- a/camel/models/model_factory.py
+++ b/camel/models/model_factory.py
@@ -24,6 +24,7 @@ from camel.models.groq_model import GroqModel
from camel.models.internlm_model import InternLMModel
from camel.models.litellm_model import LiteLLMModel
from camel.models.mistral_model import MistralModel
+from camel.models.modelscope_model import ModelScopeModel
from camel.models.moonshot_model import MoonshotModel
from camel.models.nvidia_model import NvidiaModel
from camel.models.ollama_model import OllamaModel
@@ -145,6 +146,8 @@ class ModelFactory:
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_type == ModelType.STUB:
model_class = StubModel
diff --git a/camel/models/modelscope_model.py b/camel/models/modelscope_model.py
new file mode 100644
index 000000000..c025ec07d
--- /dev/null
+++ b/camel/models/modelscope_model.py
@@ -0,0 +1,208 @@
+# ========= 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, List, Optional, Type, Union
+
+from openai import AsyncOpenAI, AsyncStream, OpenAI, Stream
+from pydantic import BaseModel
+
+from camel.configs import MODELSCOPE_API_PARAMS, ModelScopeConfig
+from camel.messages import OpenAIMessage
+from camel.models import BaseModelBackend
+from camel.models._utils import try_modify_message_with_format
+from camel.types import (
+ ChatCompletion,
+ ChatCompletionChunk,
+ ModelType,
+)
+from camel.utils import (
+ BaseTokenCounter,
+ OpenAITokenCounter,
+ api_keys_required,
+)
+
+
+class ModelScopeModel(BaseModelBackend):
+ r"""ModelScope API in a unified BaseModelBackend interface.
+
+ Args:
+ model_type (Union[ModelType, str]): Model for which a backend is
+ created, one of ModelScope series.
+ model_config_dict (Optional[Dict[str, Any]], optional): A dictionary
+ that will be fed into:obj:`openai.ChatCompletion.create()`. If
+ :obj:`None`, :obj:`ModelScopeConfig().as_dict()` will be used.
+ (default: :obj:`None`)
+ api_key (Optional[str], optional): The MODELSCOPE_SDK_TOKEN for
+ authenticating with the ModelScope service. (default: :obj:`None`)
+ refer to the following link for more details:
+ https://modelscope.cn/my/myaccesstoken
+ url (Optional[str], optional): The url to the ModelScope service.
+ (default: :obj:`https://api-inference.modelscope.cn/v1/`)
+ token_counter (Optional[BaseTokenCounter], optional): Token counter to
+ use for the model. If not provided, :obj:`OpenAITokenCounter(
+ ModelType.GPT_4O_MINI)` will be used.
+ (default: :obj:`None`)
+ 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", 'MODELSCOPE_SDK_TOKEN'),
+ ]
+ )
+ 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 = ModelScopeConfig().as_dict()
+ api_key = api_key or os.environ.get("MODELSCOPE_SDK_TOKEN")
+ url = url or os.environ.get(
+ "MODELSCOPE_API_BASE_URL",
+ "https://api-inference.modelscope.cn/v1/",
+ )
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
+ super().__init__(
+ model_type, model_config_dict, api_key, url, token_counter, timeout
+ )
+ self._client = OpenAI(
+ timeout=self._timeout,
+ max_retries=3,
+ api_key=self._api_key,
+ base_url=self._url,
+ )
+ self._async_client = AsyncOpenAI(
+ timeout=self._timeout,
+ max_retries=3,
+ api_key=self._api_key,
+ base_url=self._url,
+ )
+
+ async def _arun(
+ self,
+ messages: List[OpenAIMessage],
+ response_format: Optional[Type[BaseModel]] = None,
+ tools: Optional[List[Dict[str, Any]]] = None,
+ ) -> Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]:
+ r"""Runs inference of ModelScope chat completion.
+
+ Args:
+ messages (List[OpenAIMessage]): Message list with the chat history
+ in OpenAI API format.
+
+ Returns:
+ Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]:
+ `ChatCompletion` in the non-stream mode, or
+ `AsyncStream[ChatCompletionChunk]` in the stream mode.
+ """
+ request_config = self._prepare_request(
+ messages, response_format, tools
+ )
+
+ response = await self._async_client.chat.completions.create(
+ messages=messages,
+ model=self.model_type,
+ **request_config,
+ )
+ return response
+
+ def _run(
+ self,
+ messages: List[OpenAIMessage],
+ response_format: Optional[Type[BaseModel]] = None,
+ tools: Optional[List[Dict[str, Any]]] = None,
+ ) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]:
+ r"""Runs inference of ModelScope chat completion.
+
+ Args:
+ messages (List[OpenAIMessage]): Message list with the chat history
+ in OpenAI API format.
+
+ Returns:
+ Union[ChatCompletion, Stream[ChatCompletionChunk]]:
+ `ChatCompletion` in the non-stream mode, or
+ `Stream[ChatCompletionChunk]` in the stream mode.
+ """
+ request_config = self._prepare_request(
+ messages, response_format, tools
+ )
+
+ response = self._client.chat.completions.create(
+ messages=messages,
+ model=self.model_type,
+ **request_config,
+ )
+ return response
+
+ def _prepare_request(
+ self,
+ messages: List[OpenAIMessage],
+ response_format: Optional[Type[BaseModel]] = None,
+ tools: Optional[List[Dict[str, Any]]] = None,
+ ) -> Dict[str, Any]:
+ request_config = self.model_config_dict.copy()
+ if tools:
+ request_config["tools"] = tools
+ elif response_format:
+ try_modify_message_with_format(messages[-1], response_format)
+ request_config["response_format"] = {"type": "json_object"}
+
+ return request_config
+
+ @property
+ def token_counter(self) -> BaseTokenCounter:
+ r"""Initialize the token counter for the model backend.
+
+ Returns:
+ OpenAITokenCounter: The token counter following the model's
+ tokenization style.
+ """
+
+ if not self._token_counter:
+ self._token_counter = OpenAITokenCounter(ModelType.GPT_4O_MINI)
+ return self._token_counter
+
+ def check_model_config(self):
+ r"""Check whether the model configuration contains any
+ unexpected arguments to ModelScope API.
+
+ Raises:
+ ValueError: If the model configuration dictionary contains any
+ unexpected arguments to ModelScope API.
+ """
+ for param in self.model_config_dict:
+ if param not in MODELSCOPE_API_PARAMS:
+ raise ValueError(
+ f"Unexpected argument `{param}` is "
+ "input into ModelScope model backend."
+ )
+
+ @property
+ def stream(self) -> bool:
+ r"""Returns whether the model is in stream mode, which sends partial
+ results each time.
+
+ Returns:
+ bool: Whether the model is in stream mode.
+ """
+ return self.model_config_dict.get('stream', False)
diff --git a/camel/types/enums.py b/camel/types/enums.py
index 5c107a8cf..0c0f657f0 100644
--- a/camel/types/enums.py
+++ b/camel/types/enums.py
@@ -217,6 +217,29 @@ class ModelType(UnifiedModelType, Enum):
AIML_MIXTRAL_8X7B = "mistralai/Mixtral-8x7B-Instruct-v0.1"
AIML_MISTRAL_7B_INSTRUCT = "mistralai/Mistral-7B-Instruct-v0.1"
+ # ModelScope models support tool calling
+ MODELSCOPE_QWEN_2_5_7B_INSTRUCT = "Qwen/Qwen2.5-7B-Instruct"
+ MODELSCOPE_QWEN_2_5_14B_INSTRUCT = "Qwen/Qwen2.5-14B-Instruct"
+ MODELSCOPE_QWEN_2_5_32B_INSTRUCT = "Qwen/Qwen2.5-32B-Instruct"
+ MODELSCOPE_QWEN_2_5_72B_INSTRUCT = "Qwen/Qwen2.5-72B-Instruct"
+ MODELSCOPE_QWEN_2_5_CODER_7B_INSTRUCT = "Qwen/Qwen2.5-Coder-7B-Instruct"
+ MODELSCOPE_QWEN_2_5_CODER_14B_INSTRUCT = "Qwen/Qwen2.5-Coder-14B-Instruct"
+ MODELSCOPE_QWEN_2_5_CODER_32B_INSTRUCT = "Qwen/Qwen2.5-Coder-32B-Instruct"
+ MODELSCOPE_QWQ_32B = "Qwen/QwQ-32B"
+ MODELSCOPE_QWQ_32B_PREVIEW = "Qwen/QwQ-32B-Preview"
+ MODELSCOPE_LLAMA_3_1_8B_INSTRUCT = (
+ "LLM-Research/Meta-Llama-3.1-8B-Instruct"
+ )
+ MODELSCOPE_LLAMA_3_1_70B_INSTRUCT = (
+ "LLM-Research/Meta-Llama-3.1-70B-Instruct"
+ )
+ MODELSCOPE_LLAMA_3_1_405B_INSTRUCT = (
+ "LLM-Research/Meta-Llama-3.1-405B-Instruct"
+ )
+ MODELSCOPE_LLAMA_3_3_70B_INSTRUCT = "LLM-Research/Llama-3.3-70B-Instruct"
+ MODELSCOPE_MINISTRAL_8B_INSTRUCT = "mistralai/Ministral-8B-Instruct-2410"
+ MODELSCOPE_DEEPSEEK_V3_0324 = "deepseek-ai/DeepSeek-V3-0324"
+
def __str__(self):
return self.value
@@ -263,6 +286,7 @@ class ModelType(UnifiedModelType, Enum):
self.is_sglang,
self.is_moonshot,
self.is_siliconflow,
+ self.is_modelscope,
self.is_zhipuai,
self.is_aiml,
self.is_azure_openai,
@@ -515,6 +539,26 @@ class ModelType(UnifiedModelType, Enum):
ModelType.INTERNLM2_PRO_CHAT,
}
+ @property
+ def is_modelscope(self) -> bool:
+ return self in {
+ ModelType.MODELSCOPE_QWEN_2_5_7B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_14B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_32B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_72B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_CODER_7B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_CODER_14B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_CODER_32B_INSTRUCT,
+ ModelType.MODELSCOPE_QWQ_32B,
+ ModelType.MODELSCOPE_QWQ_32B_PREVIEW,
+ ModelType.MODELSCOPE_LLAMA_3_1_8B_INSTRUCT,
+ ModelType.MODELSCOPE_LLAMA_3_1_70B_INSTRUCT,
+ ModelType.MODELSCOPE_LLAMA_3_1_405B_INSTRUCT,
+ ModelType.MODELSCOPE_LLAMA_3_3_70B_INSTRUCT,
+ ModelType.MODELSCOPE_MINISTRAL_8B_INSTRUCT,
+ ModelType.MODELSCOPE_DEEPSEEK_V3_0324,
+ }
+
@property
def is_moonshot(self) -> bool:
return self in {
@@ -638,6 +682,21 @@ class ModelType(UnifiedModelType, Enum):
ModelType.MOONSHOT_V1_32K,
ModelType.AIML_MIXTRAL_8X7B,
ModelType.AIML_MISTRAL_7B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_7B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_14B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_32B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_72B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_CODER_7B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_CODER_14B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_CODER_32B_INSTRUCT,
+ ModelType.MODELSCOPE_QWQ_32B,
+ ModelType.MODELSCOPE_QWQ_32B_PREVIEW,
+ ModelType.MODELSCOPE_LLAMA_3_1_8B_INSTRUCT,
+ ModelType.MODELSCOPE_LLAMA_3_1_70B_INSTRUCT,
+ ModelType.MODELSCOPE_LLAMA_3_1_405B_INSTRUCT,
+ ModelType.MODELSCOPE_LLAMA_3_3_70B_INSTRUCT,
+ ModelType.MODELSCOPE_MINISTRAL_8B_INSTRUCT,
+ ModelType.MODELSCOPE_DEEPSEEK_V3_0324,
}:
return 32_768
elif self in {
@@ -922,6 +981,7 @@ class ModelPlatformType(Enum):
SGLANG = "sglang"
INTERNLM = "internlm"
MOONSHOT = "moonshot"
+ MODELSCOPE = "modelscope"
SILICONFLOW = "siliconflow"
AIML = "aiml"
VOLCANO = "volcano"
@@ -1050,6 +1110,11 @@ class ModelPlatformType(Enum):
r"""Returns whether this platform is Moonshot model."""
return self is ModelPlatformType.MOONSHOT
+ @property
+ def is_modelscope(self) -> bool:
+ r"""Returns whether this platform is ModelScope model."""
+ return self is ModelPlatformType.MODELSCOPE
+
@property
def is_siliconflow(self) -> bool:
r"""Returns whether this platform is SiliconFlow."""
diff --git a/camel/types/unified_model_type.py b/camel/types/unified_model_type.py
index d7148b025..9b6b667cd 100644
--- a/camel/types/unified_model_type.py
+++ b/camel/types/unified_model_type.py
@@ -123,6 +123,11 @@ class UnifiedModelType(str):
r"""Returns whether the model is a InternLM model."""
return True
+ @property
+ def is_modelscope(self) -> bool:
+ r"""Returns whether the model is a ModelScope serverd model."""
+ return True
+
@property
def is_moonshot(self) -> bool:
r"""Returns whether this platform is Moonshot model."""
diff --git a/docs/key_modules/models.md b/docs/key_modules/models.md
index c09cf0bdf..d3716f176 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:/
| **SGLANG** | [supported models](https://sgl-project.github.io/references/supported_models.html) |
| **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) |
## 3. How to Use Models via API Calls
diff --git a/examples/models/modelscope_model_example.py b/examples/models/modelscope_model_example.py
new file mode 100644
index 000000000..f0e344926
--- /dev/null
+++ b/examples/models/modelscope_model_example.py
@@ -0,0 +1,55 @@
+# ========= 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 ModelScopeConfig
+from camel.models import ModelFactory
+from camel.toolkits import MathToolkit
+from camel.types import ModelPlatformType, ModelType
+
+model = ModelFactory.create(
+ model_platform=ModelPlatformType.MODELSCOPE,
+ model_type=ModelType.MODELSCOPE_QWEN_2_5_32B_INSTRUCT,
+ model_config_dict=ModelScopeConfig(temperature=0.2).as_dict(),
+)
+
+# Define system message
+sys_msg = "You are a helpful assistant."
+
+# Set agent
+agent = ChatAgent(
+ system_message=sys_msg,
+ model=model,
+ tools=[
+ *MathToolkit().get_tools(),
+ ],
+)
+# Let agent step the message
+response = agent.step(
+ "Assume now is 2024 in the Gregorian calendar, University of Oxford was set up in 1096, estimate the current age of University of Oxford" # noqa: E501
+)
+
+# Check tool calling
+print(response)
+print(response.info['tool_calls'])
+print(response.msgs[0].content)
+
+
+'''
+==============================================================================
+msgs=[BaseMessage(role_name='Assistant', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={}, content='The University of Oxford is approximately 928 years old in the year 2024.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low', parsed=None)] terminated=False info={'id': 'chatcmpl-6eeb61bf-1003-9fe3-962e-88ffe5d1704e', 'usage': {'completion_tokens': 22, 'prompt_tokens': 717, 'total_tokens': 739, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'termination_reasons': ['stop'], 'num_tokens': 80, 'tool_calls': [ToolCallingRecord(tool_name='sub', args={'a': 2024, 'b': 1096}, result=928, tool_call_id='call_05f85b0fdd9241be912883')], 'external_tool_call_requests': None}
+[ToolCallingRecord(tool_name='sub', args={'a': 2024, 'b': 1096}, result=928, tool_call_id='call_05f85b0fdd9241be912883')]
+The University of Oxford is approximately 928 years old in the year 2024.
+==============================================================================
+''' # noqa: E501
diff --git a/test/models/test_modelscope_model.py b/test/models/test_modelscope_model.py
new file mode 100644
index 000000000..f0fe8931d
--- /dev/null
+++ b/test/models/test_modelscope_model.py
@@ -0,0 +1,69 @@
+# ========= 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 ModelScopeConfig
+from camel.models import ModelScopeModel
+from camel.types import ModelType
+from camel.utils import OpenAITokenCounter
+
+
+ "model_type",
+ [
+ ModelType.MODELSCOPE_QWEN_2_5_7B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_14B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_32B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_72B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_CODER_7B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_CODER_14B_INSTRUCT,
+ ModelType.MODELSCOPE_QWEN_2_5_CODER_32B_INSTRUCT,
+ ModelType.MODELSCOPE_QWQ_32B,
+ ModelType.MODELSCOPE_QWQ_32B_PREVIEW,
+ ModelType.MODELSCOPE_LLAMA_3_1_8B_INSTRUCT,
+ ModelType.MODELSCOPE_LLAMA_3_1_70B_INSTRUCT,
+ ModelType.MODELSCOPE_LLAMA_3_1_405B_INSTRUCT,
+ ModelType.MODELSCOPE_LLAMA_3_3_70B_INSTRUCT,
+ ModelType.MODELSCOPE_MINISTRAL_8B_INSTRUCT,
+ ModelType.MODELSCOPE_DEEPSEEK_V3_0324,
+ ],
+)
+def test_modelscope_model(model_type: ModelType):
+ model = ModelScopeModel(model_type)
+ assert model.model_type == model_type
+ assert model.model_config_dict == ModelScopeConfig().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)
+
+
+def test_modelscope_model_unexpected_argument():
+ model_type = ModelType.MODELSCOPE_QWEN_2_5_32B_INSTRUCT
+ model_config_dict = {"model_path": "qwen-32b-instruct"}
+
+ with pytest.raises(
+ ValueError,
+ match=re.escape(
+ (
+ "Unexpected argument `model_path` is "
+ "input into ModelScope model backend."
+ )
+ ),
+ ):
+ _ = ModelScopeModel(model_type, model_config_dict)