camel-ai 0.2.65__py3-none-any.whl → 0.2.67__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. camel/__init__.py +1 -1
  2. camel/agents/mcp_agent.py +1 -5
  3. camel/configs/__init__.py +3 -0
  4. camel/configs/qianfan_config.py +85 -0
  5. camel/models/__init__.py +2 -0
  6. camel/models/aiml_model.py +8 -0
  7. camel/models/anthropic_model.py +8 -0
  8. camel/models/aws_bedrock_model.py +8 -0
  9. camel/models/azure_openai_model.py +14 -5
  10. camel/models/base_model.py +4 -0
  11. camel/models/cohere_model.py +9 -2
  12. camel/models/crynux_model.py +8 -0
  13. camel/models/deepseek_model.py +8 -0
  14. camel/models/gemini_model.py +8 -0
  15. camel/models/groq_model.py +8 -0
  16. camel/models/internlm_model.py +8 -0
  17. camel/models/litellm_model.py +5 -0
  18. camel/models/lmstudio_model.py +14 -1
  19. camel/models/mistral_model.py +15 -1
  20. camel/models/model_factory.py +6 -0
  21. camel/models/modelscope_model.py +8 -0
  22. camel/models/moonshot_model.py +8 -0
  23. camel/models/nemotron_model.py +17 -2
  24. camel/models/netmind_model.py +8 -0
  25. camel/models/novita_model.py +8 -0
  26. camel/models/nvidia_model.py +8 -0
  27. camel/models/ollama_model.py +8 -0
  28. camel/models/openai_compatible_model.py +23 -5
  29. camel/models/openai_model.py +21 -4
  30. camel/models/openrouter_model.py +8 -0
  31. camel/models/ppio_model.py +8 -0
  32. camel/models/qianfan_model.py +104 -0
  33. camel/models/qwen_model.py +8 -0
  34. camel/models/reka_model.py +18 -3
  35. camel/models/samba_model.py +17 -3
  36. camel/models/sglang_model.py +20 -5
  37. camel/models/siliconflow_model.py +8 -0
  38. camel/models/stub_model.py +8 -1
  39. camel/models/togetherai_model.py +8 -0
  40. camel/models/vllm_model.py +7 -0
  41. camel/models/volcano_model.py +14 -1
  42. camel/models/watsonx_model.py +4 -1
  43. camel/models/yi_model.py +8 -0
  44. camel/models/zhipuai_model.py +8 -0
  45. camel/societies/workforce/prompts.py +33 -17
  46. camel/societies/workforce/role_playing_worker.py +5 -10
  47. camel/societies/workforce/single_agent_worker.py +3 -5
  48. camel/societies/workforce/task_channel.py +16 -18
  49. camel/societies/workforce/utils.py +104 -65
  50. camel/societies/workforce/workforce.py +1263 -100
  51. camel/societies/workforce/workforce_logger.py +613 -0
  52. camel/tasks/task.py +77 -6
  53. camel/toolkits/__init__.py +2 -0
  54. camel/toolkits/code_execution.py +1 -1
  55. camel/toolkits/function_tool.py +79 -7
  56. camel/toolkits/mcp_toolkit.py +70 -19
  57. camel/toolkits/playwright_mcp_toolkit.py +2 -1
  58. camel/toolkits/pptx_toolkit.py +4 -4
  59. camel/types/enums.py +32 -0
  60. camel/types/unified_model_type.py +5 -0
  61. camel/utils/mcp_client.py +1 -35
  62. {camel_ai-0.2.65.dist-info → camel_ai-0.2.67.dist-info}/METADATA +3 -3
  63. {camel_ai-0.2.65.dist-info → camel_ai-0.2.67.dist-info}/RECORD +65 -62
  64. {camel_ai-0.2.65.dist-info → camel_ai-0.2.67.dist-info}/WHEEL +0 -0
  65. {camel_ai-0.2.65.dist-info → camel_ai-0.2.67.dist-info}/licenses/LICENSE +0 -0
camel/__init__.py CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  from camel.logger import disable_logging, enable_logging, set_log_level
16
16
 
17
- __version__ = '0.2.65'
17
+ __version__ = '0.2.67'
18
18
 
19
19
  __all__ = [
20
20
  '__version__',
camel/agents/mcp_agent.py CHANGED
@@ -125,7 +125,6 @@ class MCPAgent(ChatAgent):
125
125
  local_config_path: Optional[str] = None,
126
126
  tools: Optional[List[Union[FunctionTool, Callable]]] = None,
127
127
  function_calling_available: bool = True,
128
- strict: bool = False,
129
128
  **kwargs,
130
129
  ):
131
130
  if model is None:
@@ -145,7 +144,6 @@ class MCPAgent(ChatAgent):
145
144
 
146
145
  self.local_config = local_config
147
146
  self.function_calling_available = function_calling_available
148
- self.strict = strict
149
147
 
150
148
  if function_calling_available:
151
149
  sys_msg_content = "You are a helpful assistant, and you prefer "
@@ -179,7 +177,7 @@ class MCPAgent(ChatAgent):
179
177
  if self.local_config:
180
178
  config_dict.update(self.local_config)
181
179
 
182
- return MCPToolkit(config_dict=config_dict, strict=self.strict)
180
+ return MCPToolkit(config_dict=config_dict)
183
181
 
184
182
  def add_registry(self, registry_config: BaseMCPRegistryConfig) -> None:
185
183
  r"""Add a new registry configuration to the agent.
@@ -213,7 +211,6 @@ class MCPAgent(ChatAgent):
213
211
  ] = None,
214
212
  model: Optional[BaseModelBackend] = None,
215
213
  function_calling_available: bool = False,
216
- strict: bool = False,
217
214
  **kwargs,
218
215
  ) -> "MCPAgent":
219
216
  r"""Create and connect an MCPAgent instance.
@@ -279,7 +276,6 @@ class MCPAgent(ChatAgent):
279
276
  registry_configs=final_registry_configs,
280
277
  model=model,
281
278
  function_calling_available=function_calling_available,
282
- strict=strict,
283
279
  **kwargs,
284
280
  )
285
281
 
camel/configs/__init__.py CHANGED
@@ -33,6 +33,7 @@ from .ollama_config import OLLAMA_API_PARAMS, OllamaConfig
33
33
  from .openai_config import OPENAI_API_PARAMS, ChatGPTConfig
34
34
  from .openrouter_config import OPENROUTER_API_PARAMS, OpenRouterConfig
35
35
  from .ppio_config import PPIO_API_PARAMS, PPIOConfig
36
+ from .qianfan_config import QIANFAN_API_PARAMS, QianfanConfig
36
37
  from .qwen_config import QWEN_API_PARAMS, QwenConfig
37
38
  from .reka_config import REKA_API_PARAMS, RekaConfig
38
39
  from .samba_config import (
@@ -113,6 +114,8 @@ __all__ = [
113
114
  'LMStudioConfig',
114
115
  'WatsonXConfig',
115
116
  'WATSONX_API_PARAMS',
117
+ 'QianfanConfig',
118
+ 'QIANFAN_API_PARAMS',
116
119
  'CrynuxConfig',
117
120
  'CRYNUX_API_PARAMS',
118
121
  ]
@@ -0,0 +1,85 @@
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
+ from __future__ import annotations
15
+
16
+ from typing import Dict, List, Optional, Union
17
+
18
+ from pydantic import Field
19
+
20
+ from camel.configs.base_config import BaseConfig
21
+ from camel.types import NotGiven
22
+
23
+
24
+ class QianfanConfig(BaseConfig):
25
+ r"""Defines the parameters for generating chat completions using OpenAI
26
+ compatibility.
27
+
28
+ Reference: https://cloud.baidu.com/doc/qianfan-api/s/3m7of64lb
29
+
30
+ Args:
31
+ presence_penalty (float, optional): Number between :obj:`-2.0` and
32
+ :obj:`2.0`. Positive values penalize new tokens based on whether
33
+ they appear in the text so far, increasing the model's likelihood
34
+ to talk about new topics. See more information about frequency and
35
+ presence penalties. (default: :obj:`None`)
36
+ frequency_penalty (float, optional): Number between :obj:`-2.0` and
37
+ :obj:`2.0`. Positive values penalize new tokens based on their
38
+ existing frequency in the text so far, decreasing the model's
39
+ likelihood to repeat the same line verbatim. See more information
40
+ about frequency and presence penalties. (default: :obj:`None`)
41
+ repetition_penalty (float, optional): Penalizes new tokens based on
42
+ their appearance in the prompt and generated text.
43
+ (default: :obj:`None`)
44
+ stream (bool, optional): Whether to stream the response.
45
+ (default: :obj:`None`)
46
+ temperature (float, optional): Controls randomness in the response.
47
+ Higher values make output more random, lower values make it more
48
+ deterministic. Range: [0.0, 2.0]. (default: :obj:`None`)
49
+ top_p (float, optional): Controls diversity via nucleus sampling.
50
+ Range: [0.0, 1.0]. (default: :obj:`None`)
51
+ logit_bias (dict, optional): Modify the likelihood of specified tokens
52
+ appearing in the completion. Accepts a json object that maps tokens
53
+ (specified by their token ID in the tokenizer) to an associated
54
+ bias value from :obj:`-100` to :obj:`100`. Mathematically, the bias
55
+ is added to the logits generated by the model prior to sampling.
56
+ The exact effect will vary per model, but values between:obj:` -1`
57
+ and :obj:`1` should decrease or increase likelihood of selection;
58
+ values like :obj:`-100` or :obj:`100` should result in a ban or
59
+ exclusive selection of the relevant token. (default: :obj:`None`)
60
+ max_tokens (Union[int, NotGiven], optional): Maximum number of tokens
61
+ to generate. If not provided, model will use its default maximum.
62
+ (default: :obj:`None`)
63
+ stop (Optional[List[str]], optional): List of stop sequences.
64
+ (default: :obj:`None`)
65
+ n (Optional[int], optional): Number of chat completion choices to
66
+ generate for each input message. (default: :obj:`None`)
67
+ tools (List, optional): Specifies an array of tools that the model can
68
+ call. It can contain one or more tool objects. During a function
69
+ call process, the model will select one tool from the array.
70
+ (default: :obj:`None`)
71
+ """
72
+
73
+ stream: Optional[bool] = Field(default=None)
74
+ temperature: Optional[float] = Field(default=None)
75
+ top_p: Optional[float] = Field(default=None)
76
+ presence_penalty: Optional[float] = Field(default=None)
77
+ frequency_penalty: Optional[float] = Field(default=None)
78
+ repetition_penalty: Optional[float] = Field(default=None)
79
+ max_tokens: Optional[Union[int, NotGiven]] = Field(default=None)
80
+ stop: Optional[List[str]] = Field(default=None)
81
+ n: Optional[int] = Field(default=None)
82
+ logit_bias: Optional[Dict[str, float]] = Field(default=None)
83
+
84
+
85
+ QIANFAN_API_PARAMS = {param for param in QianfanConfig.model_fields.keys()}
camel/models/__init__.py CHANGED
@@ -41,6 +41,7 @@ from .openai_compatible_model import OpenAICompatibleModel
41
41
  from .openai_model import OpenAIModel
42
42
  from .openrouter_model import OpenRouterModel
43
43
  from .ppio_model import PPIOModel
44
+ from .qianfan_model import QianfanModel
44
45
  from .qwen_model import QwenModel
45
46
  from .reka_model import RekaModel
46
47
  from .samba_model import SambaModel
@@ -97,5 +98,6 @@ __all__ = [
97
98
  'VolcanoModel',
98
99
  'LMStudioModel',
99
100
  'WatsonXModel',
101
+ 'QianfanModel',
100
102
  'CrynuxModel',
101
103
  ]
@@ -46,6 +46,10 @@ class AIMLModel(OpenAICompatibleModel):
46
46
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
47
47
  environment variable or default to 180 seconds.
48
48
  (default: :obj:`None`)
49
+ max_retries (int, optional): Maximum number of retries for API calls.
50
+ (default: :obj:`3`)
51
+ **kwargs (Any): Additional arguments to pass to the client
52
+ initialization.
49
53
  """
50
54
 
51
55
  @api_keys_required([("api_key", "AIML_API_KEY")])
@@ -57,6 +61,8 @@ class AIMLModel(OpenAICompatibleModel):
57
61
  url: Optional[str] = None,
58
62
  token_counter: Optional[BaseTokenCounter] = None,
59
63
  timeout: Optional[float] = None,
64
+ max_retries: int = 3,
65
+ **kwargs: Any,
60
66
  ) -> None:
61
67
  if model_config_dict is None:
62
68
  model_config_dict = AIMLConfig().as_dict()
@@ -73,6 +79,8 @@ class AIMLModel(OpenAICompatibleModel):
73
79
  url=url,
74
80
  token_counter=token_counter,
75
81
  timeout=timeout,
82
+ max_retries=max_retries,
83
+ **kwargs,
76
84
  )
77
85
 
78
86
  def check_model_config(self):
@@ -46,6 +46,10 @@ class AnthropicModel(OpenAICompatibleModel):
46
46
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
47
47
  environment variable or default to 180 seconds.
48
48
  (default: :obj:`None`)
49
+ max_retries (int, optional): Maximum number of retries for API calls.
50
+ (default: :obj:`3`)
51
+ **kwargs (Any): Additional arguments to pass to the client
52
+ initialization.
49
53
  """
50
54
 
51
55
  @api_keys_required(
@@ -62,6 +66,8 @@ class AnthropicModel(OpenAICompatibleModel):
62
66
  url: Optional[str] = None,
63
67
  token_counter: Optional[BaseTokenCounter] = None,
64
68
  timeout: Optional[float] = None,
69
+ max_retries: int = 3,
70
+ **kwargs: Any,
65
71
  ) -> None:
66
72
  if model_config_dict is None:
67
73
  model_config_dict = AnthropicConfig().as_dict()
@@ -79,6 +85,8 @@ class AnthropicModel(OpenAICompatibleModel):
79
85
  url=url,
80
86
  token_counter=token_counter,
81
87
  timeout=timeout,
88
+ max_retries=max_retries,
89
+ **kwargs,
82
90
  )
83
91
 
84
92
  @property
@@ -50,6 +50,10 @@ class AWSBedrockModel(OpenAICompatibleModel):
50
50
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
51
51
  environment variable or default to 180 seconds.
52
52
  (default: :obj:`None`)
53
+ max_retries (int, optional): Maximum number of retries for API calls.
54
+ (default: :obj:`3`)
55
+ **kwargs (Any): Additional arguments to pass to the client
56
+ initialization.
53
57
 
54
58
  References:
55
59
  https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html
@@ -69,6 +73,8 @@ class AWSBedrockModel(OpenAICompatibleModel):
69
73
  url: Optional[str] = None,
70
74
  token_counter: Optional[BaseTokenCounter] = None,
71
75
  timeout: Optional[float] = None,
76
+ max_retries: int = 3,
77
+ **kwargs: Any,
72
78
  ) -> None:
73
79
  if model_config_dict is None:
74
80
  model_config_dict = BedrockConfig().as_dict()
@@ -84,6 +90,8 @@ class AWSBedrockModel(OpenAICompatibleModel):
84
90
  url=url,
85
91
  token_counter=token_counter,
86
92
  timeout=timeout,
93
+ max_retries=max_retries,
94
+ **kwargs,
87
95
  )
88
96
 
89
97
  async def _arun(
@@ -76,7 +76,10 @@ class AzureOpenAIModel(BaseModelBackend):
76
76
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
77
77
  environment variable or default to 180 seconds.
78
78
  (default: :obj:`None`)
79
-
79
+ max_retries (int, optional): Maximum number of retries for API calls.
80
+ (default: :obj:`3`)
81
+ **kwargs (Any): Additional arguments to pass to the client
82
+ initialization.
80
83
 
81
84
  References:
82
85
  https://learn.microsoft.com/en-us/azure/ai-services/openai/
@@ -94,6 +97,8 @@ class AzureOpenAIModel(BaseModelBackend):
94
97
  azure_deployment_name: Optional[str] = None,
95
98
  azure_ad_token_provider: Optional["AzureADTokenProvider"] = None,
96
99
  azure_ad_token: Optional[str] = None,
100
+ max_retries: int = 3,
101
+ **kwargs: Any,
97
102
  ) -> None:
98
103
  if model_config_dict is None:
99
104
  model_config_dict = ChatGPTConfig().as_dict()
@@ -135,7 +140,8 @@ class AzureOpenAIModel(BaseModelBackend):
135
140
  azure_ad_token=self._azure_ad_token,
136
141
  azure_ad_token_provider=self.azure_ad_token_provider,
137
142
  timeout=self._timeout,
138
- max_retries=3,
143
+ max_retries=max_retries,
144
+ **kwargs,
139
145
  )
140
146
  self._async_client = LangfuseAsyncOpenAI(
141
147
  azure_endpoint=str(self._url),
@@ -145,7 +151,8 @@ class AzureOpenAIModel(BaseModelBackend):
145
151
  azure_ad_token=self._azure_ad_token,
146
152
  azure_ad_token_provider=self.azure_ad_token_provider,
147
153
  timeout=self._timeout,
148
- max_retries=3,
154
+ max_retries=max_retries,
155
+ **kwargs,
149
156
  )
150
157
  else:
151
158
  self._client = AzureOpenAI(
@@ -156,7 +163,8 @@ class AzureOpenAIModel(BaseModelBackend):
156
163
  azure_ad_token=self._azure_ad_token,
157
164
  azure_ad_token_provider=self.azure_ad_token_provider,
158
165
  timeout=self._timeout,
159
- max_retries=3,
166
+ max_retries=max_retries,
167
+ **kwargs,
160
168
  )
161
169
 
162
170
  self._async_client = AsyncAzureOpenAI(
@@ -167,7 +175,8 @@ class AzureOpenAIModel(BaseModelBackend):
167
175
  azure_ad_token=self._azure_ad_token,
168
176
  azure_ad_token_provider=self.azure_ad_token_provider,
169
177
  timeout=self._timeout,
170
- max_retries=3,
178
+ max_retries=max_retries,
179
+ **kwargs,
171
180
  )
172
181
 
173
182
  @property
@@ -71,6 +71,8 @@ class BaseModelBackend(ABC, metaclass=ModelBackendMeta):
71
71
  :obj:`OpenAITokenCounter` will be used. (default: :obj:`None`)
72
72
  timeout (Optional[float], optional): The timeout value in seconds for
73
73
  API calls. (default: :obj:`None`)
74
+ max_retries (int, optional): Maximum number of retries
75
+ for API calls. (default: :obj:`3`)
74
76
  """
75
77
 
76
78
  def __init__(
@@ -81,6 +83,7 @@ class BaseModelBackend(ABC, metaclass=ModelBackendMeta):
81
83
  url: Optional[str] = None,
82
84
  token_counter: Optional[BaseTokenCounter] = None,
83
85
  timeout: Optional[float] = None,
86
+ max_retries: int = 3,
84
87
  ) -> None:
85
88
  self.model_type: UnifiedModelType = UnifiedModelType(model_type)
86
89
  if model_config_dict is None:
@@ -90,6 +93,7 @@ class BaseModelBackend(ABC, metaclass=ModelBackendMeta):
90
93
  self._url = url
91
94
  self._token_counter = token_counter
92
95
  self._timeout = timeout
96
+ self._max_retries = max_retries
93
97
  self.check_model_config()
94
98
 
95
99
  @property
@@ -76,6 +76,8 @@ class CohereModel(BaseModelBackend):
76
76
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
77
77
  environment variable or default to 180 seconds.
78
78
  (default: :obj:`None`)
79
+ **kwargs (Any): Additional arguments to pass to the client
80
+ initialization.
79
81
  """
80
82
 
81
83
  @api_keys_required(
@@ -91,6 +93,7 @@ class CohereModel(BaseModelBackend):
91
93
  url: Optional[str] = None,
92
94
  token_counter: Optional[BaseTokenCounter] = None,
93
95
  timeout: Optional[float] = None,
96
+ **kwargs: Any,
94
97
  ):
95
98
  import cohere
96
99
 
@@ -105,10 +108,14 @@ class CohereModel(BaseModelBackend):
105
108
  model_type, model_config_dict, api_key, url, token_counter, timeout
106
109
  )
107
110
  self._client = cohere.ClientV2(
108
- timeout=self._timeout, api_key=self._api_key
111
+ timeout=self._timeout,
112
+ api_key=self._api_key,
113
+ **kwargs,
109
114
  )
110
115
  self._async_client = cohere.AsyncClientV2(
111
- timeout=self._timeout, api_key=self._api_key
116
+ timeout=self._timeout,
117
+ api_key=self._api_key,
118
+ **kwargs,
112
119
  )
113
120
 
114
121
  def _to_openai_response(self, response: 'ChatResponse') -> ChatCompletion:
@@ -46,6 +46,10 @@ class CrynuxModel(OpenAICompatibleModel):
46
46
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
47
47
  environment variable or default to 180 seconds.
48
48
  (default: :obj:`None`)
49
+ max_retries (int, optional): Maximum number of retries for API calls.
50
+ (default: :obj:`3`)
51
+ **kwargs (Any): Additional arguments to pass to the client
52
+ initialization.
49
53
  """
50
54
 
51
55
  @api_keys_required(
@@ -61,6 +65,8 @@ class CrynuxModel(OpenAICompatibleModel):
61
65
  url: Optional[str] = None,
62
66
  token_counter: Optional[BaseTokenCounter] = None,
63
67
  timeout: Optional[float] = None,
68
+ max_retries: int = 3,
69
+ **kwargs: Any,
64
70
  ) -> None:
65
71
  if model_config_dict is None:
66
72
  model_config_dict = CrynuxConfig().as_dict()
@@ -76,6 +82,8 @@ class CrynuxModel(OpenAICompatibleModel):
76
82
  url=url,
77
83
  token_counter=token_counter,
78
84
  timeout=timeout,
85
+ max_retries=max_retries,
86
+ **kwargs,
79
87
  )
80
88
 
81
89
  def check_model_config(self):
@@ -78,6 +78,10 @@ class DeepSeekModel(OpenAICompatibleModel):
78
78
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
79
79
  environment variable or default to 180 seconds.
80
80
  (default: :obj:`None`)
81
+ max_retries (int, optional): Maximum number of retries for API calls.
82
+ (default: :obj:`3`)
83
+ **kwargs (Any): Additional arguments to pass to the client
84
+ initialization.
81
85
 
82
86
  References:
83
87
  https://api-docs.deepseek.com/
@@ -96,6 +100,8 @@ class DeepSeekModel(OpenAICompatibleModel):
96
100
  url: Optional[str] = None,
97
101
  token_counter: Optional[BaseTokenCounter] = None,
98
102
  timeout: Optional[float] = None,
103
+ max_retries: int = 3,
104
+ **kwargs: Any,
99
105
  ) -> None:
100
106
  if model_config_dict is None:
101
107
  model_config_dict = DeepSeekConfig().as_dict()
@@ -112,6 +118,8 @@ class DeepSeekModel(OpenAICompatibleModel):
112
118
  url=url,
113
119
  token_counter=token_counter,
114
120
  timeout=timeout,
121
+ max_retries=max_retries,
122
+ **kwargs,
115
123
  )
116
124
 
117
125
  def _prepare_request(
@@ -64,6 +64,10 @@ class GeminiModel(OpenAICompatibleModel):
64
64
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
65
65
  environment variable or default to 180 seconds.
66
66
  (default: :obj:`None`)
67
+ max_retries (int, optional): Maximum number of retries for API calls.
68
+ (default: :obj:`3`)
69
+ **kwargs (Any): Additional arguments to pass to the client
70
+ initialization.
67
71
  """
68
72
 
69
73
  @api_keys_required(
@@ -79,6 +83,8 @@ class GeminiModel(OpenAICompatibleModel):
79
83
  url: Optional[str] = None,
80
84
  token_counter: Optional[BaseTokenCounter] = None,
81
85
  timeout: Optional[float] = None,
86
+ max_retries: int = 3,
87
+ **kwargs: Any,
82
88
  ) -> None:
83
89
  if model_config_dict is None:
84
90
  model_config_dict = GeminiConfig().as_dict()
@@ -95,6 +101,8 @@ class GeminiModel(OpenAICompatibleModel):
95
101
  url=url,
96
102
  token_counter=token_counter,
97
103
  timeout=timeout,
104
+ max_retries=max_retries,
105
+ **kwargs,
98
106
  )
99
107
 
100
108
  def _process_messages(self, messages) -> List[OpenAIMessage]:
@@ -45,6 +45,10 @@ class GroqModel(OpenAICompatibleModel):
45
45
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
46
46
  environment variable or default to 180 seconds.
47
47
  (default: :obj:`None`)
48
+ max_retries (int, optional): Maximum number of retries for API calls.
49
+ (default: :obj:`3`)
50
+ **kwargs (Any): Additional arguments to pass to the client
51
+ initialization.
48
52
  """
49
53
 
50
54
  @api_keys_required([("api_key", "GROQ_API_KEY")])
@@ -56,6 +60,8 @@ class GroqModel(OpenAICompatibleModel):
56
60
  url: Optional[str] = None,
57
61
  token_counter: Optional[BaseTokenCounter] = None,
58
62
  timeout: Optional[float] = None,
63
+ max_retries: int = 3,
64
+ **kwargs: Any,
59
65
  ) -> None:
60
66
  if model_config_dict is None:
61
67
  model_config_dict = GroqConfig().as_dict()
@@ -71,6 +77,8 @@ class GroqModel(OpenAICompatibleModel):
71
77
  url=url,
72
78
  token_counter=token_counter,
73
79
  timeout=timeout,
80
+ max_retries=max_retries,
81
+ **kwargs,
74
82
  )
75
83
 
76
84
  def check_model_config(self):
@@ -54,6 +54,10 @@ class InternLMModel(OpenAICompatibleModel):
54
54
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
55
55
  environment variable or default to 180 seconds.
56
56
  (default: :obj:`None`)
57
+ max_retries (int, optional): Maximum number of retries for API calls.
58
+ (default: :obj:`3`)
59
+ **kwargs (Any): Additional arguments to pass to the client
60
+ initialization.
57
61
  """
58
62
 
59
63
  @api_keys_required(
@@ -69,6 +73,8 @@ class InternLMModel(OpenAICompatibleModel):
69
73
  url: Optional[str] = None,
70
74
  token_counter: Optional[BaseTokenCounter] = None,
71
75
  timeout: Optional[float] = None,
76
+ max_retries: int = 3,
77
+ **kwargs: Any,
72
78
  ) -> None:
73
79
  self.model_config = model_config_dict or InternLMConfig().as_dict()
74
80
  api_key = api_key or os.environ.get("INTERNLM_API_KEY")
@@ -84,6 +90,8 @@ class InternLMModel(OpenAICompatibleModel):
84
90
  url=url,
85
91
  token_counter=token_counter,
86
92
  timeout=timeout,
93
+ max_retries=max_retries,
94
+ **kwargs,
87
95
  )
88
96
 
89
97
  async def _arun(
@@ -59,6 +59,8 @@ class LiteLLMModel(BaseModelBackend):
59
59
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
60
60
  environment variable or default to 180 seconds.
61
61
  (default: :obj:`None`)
62
+ **kwargs (Any): Additional arguments to pass to the client
63
+ initialization.
62
64
  """
63
65
 
64
66
  # NOTE: Currently stream mode is not supported.
@@ -72,6 +74,7 @@ class LiteLLMModel(BaseModelBackend):
72
74
  url: Optional[str] = None,
73
75
  token_counter: Optional[BaseTokenCounter] = None,
74
76
  timeout: Optional[float] = None,
77
+ **kwargs: Any,
75
78
  ) -> None:
76
79
  from litellm import completion
77
80
 
@@ -82,6 +85,7 @@ class LiteLLMModel(BaseModelBackend):
82
85
  model_type, model_config_dict, api_key, url, token_counter, timeout
83
86
  )
84
87
  self.client = completion
88
+ self.kwargs = kwargs
85
89
 
86
90
  def _convert_response_from_litellm_to_openai(
87
91
  self, response
@@ -173,6 +177,7 @@ class LiteLLMModel(BaseModelBackend):
173
177
  model=self.model_type,
174
178
  messages=messages,
175
179
  **self.model_config_dict,
180
+ **self.kwargs,
176
181
  )
177
182
  response = self._convert_response_from_litellm_to_openai(response)
178
183
 
@@ -43,6 +43,10 @@ class LMStudioModel(OpenAICompatibleModel):
43
43
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
44
44
  environment variable or default to 180 seconds.
45
45
  (default: :obj:`None`)
46
+ max_retries (int, optional): Maximum number of retries for API calls.
47
+ (default: :obj:`3`)
48
+ **kwargs (Any): Additional arguments to pass to the client
49
+ initialization.
46
50
  """
47
51
 
48
52
  def __init__(
@@ -53,6 +57,8 @@ class LMStudioModel(OpenAICompatibleModel):
53
57
  url: Optional[str] = None,
54
58
  token_counter: Optional[BaseTokenCounter] = None,
55
59
  timeout: Optional[float] = None,
60
+ max_retries: int = 3,
61
+ **kwargs: Any,
56
62
  ) -> None:
57
63
  if model_config_dict is None:
58
64
  model_config_dict = LMStudioConfig().as_dict()
@@ -62,7 +68,14 @@ class LMStudioModel(OpenAICompatibleModel):
62
68
  )
63
69
  timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
64
70
  super().__init__(
65
- model_type, model_config_dict, api_key, url, token_counter, timeout
71
+ model_type,
72
+ model_config_dict,
73
+ api_key,
74
+ url,
75
+ token_counter,
76
+ timeout,
77
+ max_retries=max_retries,
78
+ **kwargs,
66
79
  )
67
80
 
68
81
  def check_model_config(self):
@@ -80,6 +80,10 @@ class MistralModel(BaseModelBackend):
80
80
  API calls. If not provided, will fall back to the MODEL_TIMEOUT
81
81
  environment variable or default to 180 seconds.
82
82
  (default: :obj:`None`)
83
+ max_retries (int, optional): Maximum number of retries
84
+ for API calls. (default: :obj:`3`)
85
+ **kwargs (Any): Additional arguments to pass to the client
86
+ initialization.
83
87
  """
84
88
 
85
89
  @api_keys_required(
@@ -96,6 +100,8 @@ class MistralModel(BaseModelBackend):
96
100
  url: Optional[str] = None,
97
101
  token_counter: Optional[BaseTokenCounter] = None,
98
102
  timeout: Optional[float] = None,
103
+ max_retries: int = 3,
104
+ **kwargs: Any,
99
105
  ) -> None:
100
106
  from mistralai import Mistral
101
107
 
@@ -106,7 +112,14 @@ class MistralModel(BaseModelBackend):
106
112
  url = url or os.environ.get("MISTRAL_API_BASE_URL")
107
113
  timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
108
114
  super().__init__(
109
- model_type, model_config_dict, api_key, url, token_counter, timeout
115
+ model_type,
116
+ model_config_dict,
117
+ api_key,
118
+ url,
119
+ token_counter,
120
+ timeout,
121
+ max_retries,
122
+ **kwargs,
110
123
  )
111
124
  self._client = Mistral(
112
125
  timeout_ms=int(self._timeout * 1000)
@@ -114,6 +127,7 @@ class MistralModel(BaseModelBackend):
114
127
  else None,
115
128
  api_key=self._api_key,
116
129
  server_url=self._url,
130
+ **kwargs,
117
131
  )
118
132
 
119
133
  def _to_openai_response(
@@ -39,6 +39,7 @@ from camel.models.openai_compatible_model import OpenAICompatibleModel
39
39
  from camel.models.openai_model import OpenAIModel
40
40
  from camel.models.openrouter_model import OpenRouterModel
41
41
  from camel.models.ppio_model import PPIOModel
42
+ from camel.models.qianfan_model import QianfanModel
42
43
  from camel.models.qwen_model import QwenModel
43
44
  from camel.models.reka_model import RekaModel
44
45
  from camel.models.samba_model import SambaModel
@@ -98,6 +99,7 @@ class ModelFactory:
98
99
  ModelPlatformType.MODELSCOPE: ModelScopeModel,
99
100
  ModelPlatformType.NOVITA: NovitaModel,
100
101
  ModelPlatformType.WATSONX: WatsonXModel,
102
+ ModelPlatformType.QIANFAN: QianfanModel,
101
103
  ModelPlatformType.CRYNUX: CrynuxModel,
102
104
  }
103
105
 
@@ -110,6 +112,7 @@ class ModelFactory:
110
112
  api_key: Optional[str] = None,
111
113
  url: Optional[str] = None,
112
114
  timeout: Optional[float] = None,
115
+ max_retries: int = 3,
113
116
  **kwargs,
114
117
  ) -> BaseModelBackend:
115
118
  r"""Creates an instance of `BaseModelBackend` of the specified type.
@@ -134,6 +137,8 @@ class ModelFactory:
134
137
  (default: :obj:`None`)
135
138
  timeout (Optional[float], optional): The timeout value in seconds
136
139
  for API calls. (default: :obj:`None`)
140
+ max_retries (int, optional): Maximum number of retries
141
+ for API calls. (default: :obj:`3`)
137
142
  **kwargs: Additional model-specific parameters that will be passed
138
143
  to the model constructor. For example, Azure OpenAI models may
139
144
  require `api_version`, `azure_deployment_name`,
@@ -186,6 +191,7 @@ class ModelFactory:
186
191
  url=url,
187
192
  token_counter=token_counter,
188
193
  timeout=timeout,
194
+ max_retries=max_retries,
189
195
  **kwargs,
190
196
  )
191
197