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:add deepseek_reasoner model (#1474)

正经人王同学45f8ca406a02
diff --git a/camel/configs/deepseek_config.py b/camel/configs/deepseek_config.py
index 077653206..4bf8eb7b4 100644
--- a/camel/configs/deepseek_config.py
+++ b/camel/configs/deepseek_config.py
@@ -30,7 +30,7 @@ class DeepSeekConfig(BaseConfig):
temperature (float, optional): Sampling temperature to use, between
:obj:`0` and :obj:`2`. Higher values make the output more random,
while lower values make it more focused and deterministic.
- (default: :obj:`0.2`)
+ (default: :obj:`1.0`)
top_p (float, optional): Controls the diversity and focus of the
generated results. Higher values make the output more diverse,
while lower values make it more focused. (default: :obj:`1.0`)
@@ -86,7 +86,7 @@ class DeepSeekConfig(BaseConfig):
:obj:`True`)
"""
- temperature: float = 0.2 # deepseek default: 1.0
+ temperature: float = 1.0 # deepseek default: 1.0
top_p: float = 1.0
stream: bool = False
stop: Union[str, Sequence[str], NotGiven] = NOT_GIVEN
diff --git a/camel/models/deepseek_model.py b/camel/models/deepseek_model.py
index b00078df2..2bc0cf3be 100644
--- a/camel/models/deepseek_model.py
+++ b/camel/models/deepseek_model.py
@@ -13,6 +13,7 @@
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
import os
+import warnings
from typing import Any, Dict, List, Optional, Union
from openai import OpenAI, Stream
@@ -110,6 +111,33 @@ class DeepSeekModel(BaseModelBackend):
`ChatCompletion` in the non-stream mode, or
`Stream[ChatCompletionChunk]` in the stream mode.
"""
+ # deepseek reasoner has limitations
+ # reference: https://api-docs.deepseek.com/guides/reasoning_model#api-parameters
+ if self.model_type in [
+ ModelType.DEEPSEEK_REASONER,
+ ]:
+ warnings.warn(
+ "Warning: You are using an DeepSeek Reasoner model, "
+ "which has certain limitations, reference: "
+ "`https://api-docs.deepseek.com/guides/reasoning_model#api-parameters`.",
+ UserWarning,
+ )
+
+ # Check and remove unsupported parameters and reset the fixed
+ # parameters
+ unsupported_keys = [
+ "temperature",
+ "top_p",
+ "presence_penalty",
+ "frequency_penalty",
+ "logprobs",
+ "top_logprobs",
+ "tools",
+ ]
+ for key in unsupported_keys:
+ if key in self.model_config_dict:
+ del self.model_config_dict[key]
+
response = self._client.chat.completions.create(
messages=messages,
model=self.model_type,
diff --git a/camel/types/enums.py b/camel/types/enums.py
index 035192557..117312ec8 100644
--- a/camel/types/enums.py
+++ b/camel/types/enums.py
@@ -141,7 +141,7 @@ class ModelType(UnifiedModelType, Enum):
# DeepSeek models
DEEPSEEK_CHAT = "deepseek-chat"
-
+ DEEPSEEK_REASONER = "deepseek-reasoner"
# InternLM models
INTERNLM3_LATEST = "internlm3-latest"
INTERNLM3_8B_INSTRUCT = "internlm3-8b-instruct"
@@ -365,6 +365,7 @@ class ModelType(UnifiedModelType, Enum):
def is_deepseek(self) -> bool:
return self in {
ModelType.DEEPSEEK_CHAT,
+ ModelType.DEEPSEEK_REASONER,
}
@property
@@ -443,6 +444,7 @@ class ModelType(UnifiedModelType, Enum):
elif self in {
ModelType.MISTRAL_MIXTRAL_8x22B,
ModelType.DEEPSEEK_CHAT,
+ ModelType.DEEPSEEK_REASONER,
}:
return 64_000
elif self in {
diff --git a/docs/key_modules/models.md b/docs/key_modules/models.md
index 45b20f306..ede9fdad8 100644
--- a/docs/key_modules/models.md
+++ b/docs/key_modules/models.md
@@ -68,6 +68,7 @@ The following table lists currently supported model platforms by CAMEL.
| Qwen | qwen2.5-32b-instruct | N |
| Qwen | qwen2.5-14b-instruct | N |
| DeepSeek | deepseek-chat | N |
+| DeepSeek | deepseek-reasoner | N |
| ZhipuAI | glm-4v | Y |
| ZhipuAI | glm-4 | N |
| ZhipuAI | glm-3-turbo | N |
diff --git a/examples/models/deepseek_model_example.py b/examples/models/deepseek_model_example.py
index ca11c2599..b1f2db030 100644
--- a/examples/models/deepseek_model_example.py
+++ b/examples/models/deepseek_model_example.py
@@ -24,8 +24,8 @@ export DEEPSEEK_API_KEY=""
model = ModelFactory.create(
model_platform=ModelPlatformType.DEEPSEEK,
- model_type=ModelType.DEEPSEEK_CHAT,
- model_config_dict=DeepSeekConfig(temperature=1.3).as_dict(),
+ model_type=ModelType.DEEPSEEK_REASONER,
+ model_config_dict=DeepSeekConfig(temperature=0.2).as_dict(),
)
# Define system message
@@ -34,16 +34,26 @@ sys_msg = "You are a helpful assistant."
# Set agent
camel_agent = ChatAgent(system_message=sys_msg, model=model)
-user_msg = """Say hi to CAMEL AI, one open-source community dedicated to the
- study of autonomous and communicative agents."""
+user_msg = """How many Rs are there in the word 'strawberry'?"""
# Get response information
response = camel_agent.step(user_msg)
print(response.msgs[0].content)
'''
===============================================================================
-Hello CAMEL AI! It's great to hear about your open-source community dedicated
-to the study of autonomous and communicative agents. If you have any
-questions or need assistance, feel free to ask!
+The word 'strawberry' is spelled **S-T-R-A-W-B-E-R-R-Y**. Breaking it down:
+
+1. **S**
+2. **T**
+3. **R** (first R)
+4. **A**
+5. **W**
+6. **B**
+7. **E**
+8. **R** (second R)
+9. **R** (third R)
+10. **Y**
+
+There are **3 Rs** in the word 'strawberry'.
===============================================================================
'''
diff --git a/test/models/test_deepseek_model.py b/test/models/test_deepseek_model.py
index d2c6fa019..67b356039 100644
--- a/test/models/test_deepseek_model.py
+++ b/test/models/test_deepseek_model.py
@@ -27,6 +27,7 @@ from camel.utils import OpenAITokenCounter
"model_type",
[
ModelType.DEEPSEEK_CHAT,
+ ModelType.DEEPSEEK_REASONER,
],
)
def test_deepseek_model(model_type):
@@ -44,6 +45,7 @@ def test_deepseek_model(model_type):
"model_type",
[
ModelType.DEEPSEEK_CHAT,
+ ModelType.DEEPSEEK_REASONER,
],
)
def test_deepseek_model_create(model_type: ModelType):