camel-ai 0.2.67__py3-none-any.whl → 0.2.80a2__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 (224) hide show
  1. camel/__init__.py +1 -1
  2. camel/agents/_types.py +6 -2
  3. camel/agents/_utils.py +38 -0
  4. camel/agents/chat_agent.py +4014 -410
  5. camel/agents/mcp_agent.py +30 -27
  6. camel/agents/repo_agent.py +2 -1
  7. camel/benchmarks/browsecomp.py +6 -6
  8. camel/configs/__init__.py +15 -0
  9. camel/configs/aihubmix_config.py +88 -0
  10. camel/configs/amd_config.py +70 -0
  11. camel/configs/cometapi_config.py +104 -0
  12. camel/configs/minimax_config.py +93 -0
  13. camel/configs/nebius_config.py +103 -0
  14. camel/configs/vllm_config.py +2 -0
  15. camel/data_collectors/alpaca_collector.py +15 -6
  16. camel/datagen/self_improving_cot.py +1 -1
  17. camel/datasets/base_generator.py +39 -10
  18. camel/environments/__init__.py +12 -0
  19. camel/environments/rlcards_env.py +860 -0
  20. camel/environments/single_step.py +28 -3
  21. camel/environments/tic_tac_toe.py +1 -1
  22. camel/interpreters/__init__.py +2 -0
  23. camel/interpreters/docker/Dockerfile +4 -16
  24. camel/interpreters/docker_interpreter.py +3 -2
  25. camel/interpreters/e2b_interpreter.py +34 -1
  26. camel/interpreters/internal_python_interpreter.py +51 -2
  27. camel/interpreters/microsandbox_interpreter.py +395 -0
  28. camel/loaders/__init__.py +11 -2
  29. camel/loaders/base_loader.py +85 -0
  30. camel/loaders/chunkr_reader.py +9 -0
  31. camel/loaders/firecrawl_reader.py +4 -4
  32. camel/logger.py +1 -1
  33. camel/memories/agent_memories.py +84 -1
  34. camel/memories/base.py +34 -0
  35. camel/memories/blocks/chat_history_block.py +122 -4
  36. camel/memories/blocks/vectordb_block.py +8 -1
  37. camel/memories/context_creators/score_based.py +29 -237
  38. camel/memories/records.py +88 -8
  39. camel/messages/base.py +166 -40
  40. camel/messages/func_message.py +32 -5
  41. camel/models/__init__.py +10 -0
  42. camel/models/aihubmix_model.py +83 -0
  43. camel/models/aiml_model.py +1 -16
  44. camel/models/amd_model.py +101 -0
  45. camel/models/anthropic_model.py +117 -18
  46. camel/models/aws_bedrock_model.py +2 -33
  47. camel/models/azure_openai_model.py +205 -91
  48. camel/models/base_audio_model.py +3 -1
  49. camel/models/base_model.py +189 -24
  50. camel/models/cohere_model.py +5 -17
  51. camel/models/cometapi_model.py +83 -0
  52. camel/models/crynux_model.py +1 -16
  53. camel/models/deepseek_model.py +6 -16
  54. camel/models/fish_audio_model.py +6 -0
  55. camel/models/gemini_model.py +71 -20
  56. camel/models/groq_model.py +1 -17
  57. camel/models/internlm_model.py +1 -16
  58. camel/models/litellm_model.py +49 -32
  59. camel/models/lmstudio_model.py +1 -17
  60. camel/models/minimax_model.py +83 -0
  61. camel/models/mistral_model.py +1 -16
  62. camel/models/model_factory.py +27 -1
  63. camel/models/model_manager.py +24 -6
  64. camel/models/modelscope_model.py +1 -16
  65. camel/models/moonshot_model.py +185 -19
  66. camel/models/nebius_model.py +83 -0
  67. camel/models/nemotron_model.py +0 -5
  68. camel/models/netmind_model.py +1 -16
  69. camel/models/novita_model.py +1 -16
  70. camel/models/nvidia_model.py +1 -16
  71. camel/models/ollama_model.py +4 -19
  72. camel/models/openai_compatible_model.py +171 -46
  73. camel/models/openai_model.py +205 -77
  74. camel/models/openrouter_model.py +1 -17
  75. camel/models/ppio_model.py +1 -16
  76. camel/models/qianfan_model.py +1 -16
  77. camel/models/qwen_model.py +1 -16
  78. camel/models/reka_model.py +1 -16
  79. camel/models/samba_model.py +34 -47
  80. camel/models/sglang_model.py +64 -31
  81. camel/models/siliconflow_model.py +1 -16
  82. camel/models/stub_model.py +0 -4
  83. camel/models/togetherai_model.py +1 -16
  84. camel/models/vllm_model.py +1 -16
  85. camel/models/volcano_model.py +0 -17
  86. camel/models/watsonx_model.py +1 -16
  87. camel/models/yi_model.py +1 -16
  88. camel/models/zhipuai_model.py +60 -16
  89. camel/parsers/__init__.py +18 -0
  90. camel/parsers/mcp_tool_call_parser.py +176 -0
  91. camel/retrievers/auto_retriever.py +1 -0
  92. camel/runtimes/configs.py +11 -11
  93. camel/runtimes/daytona_runtime.py +15 -16
  94. camel/runtimes/docker_runtime.py +6 -6
  95. camel/runtimes/remote_http_runtime.py +5 -5
  96. camel/services/agent_openapi_server.py +380 -0
  97. camel/societies/__init__.py +2 -0
  98. camel/societies/role_playing.py +26 -28
  99. camel/societies/workforce/__init__.py +2 -0
  100. camel/societies/workforce/events.py +122 -0
  101. camel/societies/workforce/prompts.py +249 -38
  102. camel/societies/workforce/role_playing_worker.py +82 -20
  103. camel/societies/workforce/single_agent_worker.py +634 -34
  104. camel/societies/workforce/structured_output_handler.py +512 -0
  105. camel/societies/workforce/task_channel.py +169 -23
  106. camel/societies/workforce/utils.py +176 -9
  107. camel/societies/workforce/worker.py +77 -23
  108. camel/societies/workforce/workflow_memory_manager.py +772 -0
  109. camel/societies/workforce/workforce.py +3168 -478
  110. camel/societies/workforce/workforce_callback.py +74 -0
  111. camel/societies/workforce/workforce_logger.py +203 -175
  112. camel/societies/workforce/workforce_metrics.py +33 -0
  113. camel/storages/__init__.py +4 -0
  114. camel/storages/key_value_storages/json.py +15 -2
  115. camel/storages/key_value_storages/mem0_cloud.py +48 -47
  116. camel/storages/object_storages/google_cloud.py +1 -1
  117. camel/storages/vectordb_storages/__init__.py +6 -0
  118. camel/storages/vectordb_storages/chroma.py +731 -0
  119. camel/storages/vectordb_storages/oceanbase.py +13 -13
  120. camel/storages/vectordb_storages/pgvector.py +349 -0
  121. camel/storages/vectordb_storages/qdrant.py +3 -3
  122. camel/storages/vectordb_storages/surreal.py +365 -0
  123. camel/storages/vectordb_storages/tidb.py +8 -6
  124. camel/tasks/task.py +244 -27
  125. camel/toolkits/__init__.py +46 -8
  126. camel/toolkits/aci_toolkit.py +64 -19
  127. camel/toolkits/arxiv_toolkit.py +6 -6
  128. camel/toolkits/base.py +63 -5
  129. camel/toolkits/code_execution.py +28 -1
  130. camel/toolkits/context_summarizer_toolkit.py +684 -0
  131. camel/toolkits/craw4ai_toolkit.py +93 -0
  132. camel/toolkits/dappier_toolkit.py +10 -6
  133. camel/toolkits/dingtalk.py +1135 -0
  134. camel/toolkits/edgeone_pages_mcp_toolkit.py +49 -0
  135. camel/toolkits/excel_toolkit.py +901 -67
  136. camel/toolkits/file_toolkit.py +1402 -0
  137. camel/toolkits/function_tool.py +30 -6
  138. camel/toolkits/github_toolkit.py +107 -20
  139. camel/toolkits/gmail_toolkit.py +1839 -0
  140. camel/toolkits/google_calendar_toolkit.py +38 -4
  141. camel/toolkits/google_drive_mcp_toolkit.py +54 -0
  142. camel/toolkits/human_toolkit.py +34 -10
  143. camel/toolkits/hybrid_browser_toolkit/__init__.py +18 -0
  144. camel/toolkits/hybrid_browser_toolkit/config_loader.py +185 -0
  145. camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit.py +246 -0
  146. camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit_ts.py +1973 -0
  147. camel/toolkits/hybrid_browser_toolkit/installer.py +203 -0
  148. camel/toolkits/hybrid_browser_toolkit/ts/package-lock.json +3749 -0
  149. camel/toolkits/hybrid_browser_toolkit/ts/package.json +32 -0
  150. camel/toolkits/hybrid_browser_toolkit/ts/src/browser-scripts.js +125 -0
  151. camel/toolkits/hybrid_browser_toolkit/ts/src/browser-session.ts +1815 -0
  152. camel/toolkits/hybrid_browser_toolkit/ts/src/config-loader.ts +233 -0
  153. camel/toolkits/hybrid_browser_toolkit/ts/src/hybrid-browser-toolkit.ts +590 -0
  154. camel/toolkits/hybrid_browser_toolkit/ts/src/index.ts +7 -0
  155. camel/toolkits/hybrid_browser_toolkit/ts/src/parent-child-filter.ts +226 -0
  156. camel/toolkits/hybrid_browser_toolkit/ts/src/snapshot-parser.ts +219 -0
  157. camel/toolkits/hybrid_browser_toolkit/ts/src/som-screenshot-injected.ts +543 -0
  158. camel/toolkits/hybrid_browser_toolkit/ts/src/types.ts +130 -0
  159. camel/toolkits/hybrid_browser_toolkit/ts/tsconfig.json +26 -0
  160. camel/toolkits/hybrid_browser_toolkit/ts/websocket-server.js +319 -0
  161. camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py +1032 -0
  162. camel/toolkits/hybrid_browser_toolkit_py/__init__.py +17 -0
  163. camel/toolkits/hybrid_browser_toolkit_py/actions.py +575 -0
  164. camel/toolkits/hybrid_browser_toolkit_py/agent.py +311 -0
  165. camel/toolkits/hybrid_browser_toolkit_py/browser_session.py +787 -0
  166. camel/toolkits/hybrid_browser_toolkit_py/config_loader.py +490 -0
  167. camel/toolkits/hybrid_browser_toolkit_py/hybrid_browser_toolkit.py +2390 -0
  168. camel/toolkits/hybrid_browser_toolkit_py/snapshot.py +233 -0
  169. camel/toolkits/hybrid_browser_toolkit_py/stealth_script.js +0 -0
  170. camel/toolkits/hybrid_browser_toolkit_py/unified_analyzer.js +1043 -0
  171. camel/toolkits/image_generation_toolkit.py +390 -0
  172. camel/toolkits/jina_reranker_toolkit.py +3 -4
  173. camel/toolkits/klavis_toolkit.py +5 -1
  174. camel/toolkits/markitdown_toolkit.py +104 -0
  175. camel/toolkits/math_toolkit.py +64 -10
  176. camel/toolkits/mcp_toolkit.py +370 -45
  177. camel/toolkits/memory_toolkit.py +5 -1
  178. camel/toolkits/message_agent_toolkit.py +608 -0
  179. camel/toolkits/message_integration.py +724 -0
  180. camel/toolkits/minimax_mcp_toolkit.py +195 -0
  181. camel/toolkits/note_taking_toolkit.py +277 -0
  182. camel/toolkits/notion_mcp_toolkit.py +224 -0
  183. camel/toolkits/openbb_toolkit.py +5 -1
  184. camel/toolkits/origene_mcp_toolkit.py +56 -0
  185. camel/toolkits/playwright_mcp_toolkit.py +12 -31
  186. camel/toolkits/pptx_toolkit.py +25 -12
  187. camel/toolkits/resend_toolkit.py +168 -0
  188. camel/toolkits/screenshot_toolkit.py +213 -0
  189. camel/toolkits/search_toolkit.py +437 -142
  190. camel/toolkits/slack_toolkit.py +104 -50
  191. camel/toolkits/sympy_toolkit.py +1 -1
  192. camel/toolkits/task_planning_toolkit.py +3 -3
  193. camel/toolkits/terminal_toolkit/__init__.py +18 -0
  194. camel/toolkits/terminal_toolkit/terminal_toolkit.py +957 -0
  195. camel/toolkits/terminal_toolkit/utils.py +532 -0
  196. camel/toolkits/thinking_toolkit.py +1 -1
  197. camel/toolkits/vertex_ai_veo_toolkit.py +590 -0
  198. camel/toolkits/video_analysis_toolkit.py +106 -26
  199. camel/toolkits/video_download_toolkit.py +17 -14
  200. camel/toolkits/web_deploy_toolkit.py +1219 -0
  201. camel/toolkits/wechat_official_toolkit.py +483 -0
  202. camel/toolkits/zapier_toolkit.py +5 -1
  203. camel/types/__init__.py +2 -2
  204. camel/types/agents/tool_calling_record.py +4 -1
  205. camel/types/enums.py +316 -40
  206. camel/types/openai_types.py +2 -2
  207. camel/types/unified_model_type.py +31 -4
  208. camel/utils/commons.py +36 -5
  209. camel/utils/constants.py +3 -0
  210. camel/utils/context_utils.py +1003 -0
  211. camel/utils/mcp.py +138 -4
  212. camel/utils/mcp_client.py +45 -1
  213. camel/utils/message_summarizer.py +148 -0
  214. camel/utils/token_counting.py +43 -20
  215. camel/utils/tool_result.py +44 -0
  216. {camel_ai-0.2.67.dist-info → camel_ai-0.2.80a2.dist-info}/METADATA +296 -85
  217. {camel_ai-0.2.67.dist-info → camel_ai-0.2.80a2.dist-info}/RECORD +219 -146
  218. camel/loaders/pandas_reader.py +0 -368
  219. camel/toolkits/dalle_toolkit.py +0 -175
  220. camel/toolkits/file_write_toolkit.py +0 -444
  221. camel/toolkits/openai_agent_toolkit.py +0 -135
  222. camel/toolkits/terminal_toolkit.py +0 -1037
  223. {camel_ai-0.2.67.dist-info → camel_ai-0.2.80a2.dist-info}/WHEEL +0 -0
  224. {camel_ai-0.2.67.dist-info → camel_ai-0.2.80a2.dist-info}/licenses/LICENSE +0 -0
@@ -12,14 +12,17 @@
12
12
  # limitations under the License.
13
13
  # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
14
 
15
+ import copy
15
16
  import os
16
17
  from typing import Any, Dict, List, Optional, Type, Union
17
18
 
18
19
  from openai import AsyncStream
19
20
  from pydantic import BaseModel
20
21
 
21
- from camel.configs import MOONSHOT_API_PARAMS, MoonshotConfig
22
+ from camel.configs import MoonshotConfig
23
+ from camel.logger import get_logger
22
24
  from camel.messages import OpenAIMessage
25
+ from camel.models._utils import try_modify_message_with_format
23
26
  from camel.models.openai_compatible_model import OpenAICompatibleModel
24
27
  from camel.types import (
25
28
  ChatCompletion,
@@ -29,8 +32,25 @@ from camel.types import (
29
32
  from camel.utils import (
30
33
  BaseTokenCounter,
31
34
  api_keys_required,
35
+ get_current_agent_session_id,
36
+ update_langfuse_trace,
32
37
  )
33
38
 
39
+ logger = get_logger(__name__)
40
+
41
+ if os.environ.get("LANGFUSE_ENABLED", "False").lower() == "true":
42
+ try:
43
+ from langfuse.decorators import observe
44
+ except ImportError:
45
+ from camel.utils import observe
46
+ elif os.environ.get("TRACEROOT_ENABLED", "False").lower() == "true":
47
+ try:
48
+ from traceroot import trace as observe # type: ignore[import]
49
+ except ImportError:
50
+ from camel.utils import observe
51
+ else:
52
+ from camel.utils import observe
53
+
34
54
 
35
55
  class MoonshotModel(OpenAICompatibleModel):
36
56
  r"""Moonshot API in a unified OpenAICompatibleModel interface.
@@ -45,7 +65,9 @@ class MoonshotModel(OpenAICompatibleModel):
45
65
  api_key (Optional[str], optional): The API key for authenticating with
46
66
  the Moonshot service. (default: :obj:`None`)
47
67
  url (Optional[str], optional): The url to the Moonshot service.
48
- (default: :obj:`https://api.moonshot.cn/v1`)
68
+ For Chinese users, use :obj:`https://api.moonshot.cn/v1`.
69
+ For overseas users, the default endpoint will be used.
70
+ (default: :obj:`https://api.moonshot.ai/v1`)
49
71
  token_counter (Optional[BaseTokenCounter], optional): Token counter to
50
72
  use for the model. If not provided, :obj:`OpenAITokenCounter(
51
73
  ModelType.GPT_4)` will be used.
@@ -75,10 +97,12 @@ class MoonshotModel(OpenAICompatibleModel):
75
97
  if model_config_dict is None:
76
98
  model_config_dict = MoonshotConfig().as_dict()
77
99
  api_key = api_key or os.environ.get("MOONSHOT_API_KEY")
78
- url = url or os.environ.get(
79
- "MOONSHOT_API_BASE_URL",
80
- "https://api.moonshot.cn/v1",
81
- )
100
+ # Preserve default URL if not provided
101
+ if url is None:
102
+ url = (
103
+ os.environ.get("MOONSHOT_API_BASE_URL")
104
+ or "https://api.moonshot.ai/v1"
105
+ )
82
106
  timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
83
107
  super().__init__(
84
108
  model_type=model_type,
@@ -91,25 +115,167 @@ class MoonshotModel(OpenAICompatibleModel):
91
115
  **kwargs,
92
116
  )
93
117
 
118
+ def _prepare_request(
119
+ self,
120
+ messages: List[OpenAIMessage],
121
+ response_format: Optional[Type[BaseModel]] = None,
122
+ tools: Optional[List[Dict[str, Any]]] = None,
123
+ ) -> Dict[str, Any]:
124
+ r"""Prepare the request configuration for Moonshot API.
125
+
126
+ Args:
127
+ messages (List[OpenAIMessage]): Message list with the chat history
128
+ in OpenAI API format.
129
+ response_format (Optional[Type[BaseModel]]): The format of the
130
+ response.
131
+ tools (Optional[List[Dict[str, Any]]]): The schema of the tools to
132
+ use for the request.
133
+
134
+ Returns:
135
+ Dict[str, Any]: The prepared request configuration.
136
+ """
137
+ request_config = copy.deepcopy(self.model_config_dict)
138
+
139
+ if tools:
140
+ # Clean tools to remove null types (Moonshot API incompatibility)
141
+ cleaned_tools = self._clean_tool_schemas(tools)
142
+ request_config["tools"] = cleaned_tools
143
+ elif response_format:
144
+ # Use the same approach as DeepSeek for structured output
145
+ try_modify_message_with_format(messages[-1], response_format)
146
+ request_config["response_format"] = {"type": "json_object"}
147
+
148
+ return request_config
149
+
150
+ def _clean_tool_schemas(
151
+ self, tools: List[Dict[str, Any]]
152
+ ) -> List[Dict[str, Any]]:
153
+ r"""Clean tool schemas to remove null types for Moonshot compatibility.
154
+
155
+ Moonshot API doesn't accept {"type": "null"} in anyOf schemas.
156
+ This method removes null type definitions from parameters.
157
+
158
+ Args:
159
+ tools (List[Dict[str, Any]]): Original tool schemas.
160
+
161
+ Returns:
162
+ List[Dict[str, Any]]: Cleaned tool schemas.
163
+ """
164
+
165
+ def remove_null_from_schema(schema: Any) -> Any:
166
+ """Recursively remove null types from schema."""
167
+ if isinstance(schema, dict):
168
+ # Create a copy to avoid modifying the original
169
+ result = {}
170
+
171
+ for key, value in schema.items():
172
+ if key == 'type' and isinstance(value, list):
173
+ # Handle type arrays like ["string", "null"]
174
+ filtered_types = [t for t in value if t != 'null']
175
+ if len(filtered_types) == 1:
176
+ # Single type remains, convert to string
177
+ result[key] = filtered_types[0]
178
+ elif len(filtered_types) > 1:
179
+ # Multiple types remain, keep as array
180
+ result[key] = filtered_types
181
+ else:
182
+ # All were null, use string as fallback
183
+ logger.warning(
184
+ "All types in tool schema type array "
185
+ "were null, falling back to 'string' "
186
+ "type for Moonshot API compatibility. "
187
+ "Original tool schema may need review."
188
+ )
189
+ result[key] = 'string'
190
+ elif key == 'anyOf':
191
+ # Handle anyOf with null types
192
+ filtered = [
193
+ item
194
+ for item in value
195
+ if not (
196
+ isinstance(item, dict)
197
+ and item.get('type') == 'null'
198
+ )
199
+ ]
200
+ if len(filtered) == 1:
201
+ # If only one type remains, flatten it
202
+ return remove_null_from_schema(filtered[0])
203
+ elif len(filtered) > 1:
204
+ result[key] = [
205
+ remove_null_from_schema(item)
206
+ for item in filtered
207
+ ]
208
+ else:
209
+ # All were null, return string type as fallback
210
+ logger.warning(
211
+ "All types in tool schema anyOf were null, "
212
+ "falling back to 'string' type for "
213
+ "Moonshot API compatibility. Original "
214
+ "tool schema may need review."
215
+ )
216
+ return {"type": "string"}
217
+ else:
218
+ # Recursively process other values
219
+ result[key] = remove_null_from_schema(value)
220
+
221
+ return result
222
+ elif isinstance(schema, list):
223
+ return [remove_null_from_schema(item) for item in schema]
224
+ else:
225
+ return schema
226
+
227
+ cleaned_tools = copy.deepcopy(tools)
228
+ for tool in cleaned_tools:
229
+ if 'function' in tool and 'parameters' in tool['function']:
230
+ params = tool['function']['parameters']
231
+ if 'properties' in params:
232
+ params['properties'] = remove_null_from_schema(
233
+ params['properties']
234
+ )
235
+
236
+ return cleaned_tools
237
+
238
+ @observe()
94
239
  async def _arun(
95
240
  self,
96
241
  messages: List[OpenAIMessage],
97
242
  response_format: Optional[Type[BaseModel]] = None,
98
243
  tools: Optional[List[Dict[str, Any]]] = None,
99
244
  ) -> Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]:
100
- raise NotImplementedError("Moonshot does not support async inference.")
245
+ r"""Runs inference of Moonshot chat completion asynchronously.
101
246
 
102
- def check_model_config(self):
103
- r"""Check whether the model configuration contains any
104
- unexpected arguments to Moonshot API.
247
+ Args:
248
+ messages (List[OpenAIMessage]): Message list with the chat history
249
+ in OpenAI API format.
250
+ response_format (Optional[Type[BaseModel]]): The format of the
251
+ response.
252
+ tools (Optional[List[Dict[str, Any]]]): The schema of the tools to
253
+ use for the request.
105
254
 
106
- Raises:
107
- ValueError: If the model configuration dictionary contains any
108
- unexpected arguments to Moonshot API.
255
+ Returns:
256
+ Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]:
257
+ `ChatCompletion` in the non-stream mode, or
258
+ `AsyncStream[ChatCompletionChunk]` in the stream mode.
109
259
  """
110
- for param in self.model_config_dict:
111
- if param not in MOONSHOT_API_PARAMS:
112
- raise ValueError(
113
- f"Unexpected argument `{param}` is "
114
- "input into Moonshot model backend."
115
- )
260
+
261
+ # Update Langfuse trace with current agent session and metadata
262
+ agent_session_id = get_current_agent_session_id()
263
+ if agent_session_id:
264
+ update_langfuse_trace(
265
+ session_id=agent_session_id,
266
+ metadata={
267
+ "agent_id": agent_session_id,
268
+ "model_type": str(self.model_type),
269
+ },
270
+ tags=["CAMEL-AI", str(self.model_type)],
271
+ )
272
+
273
+ request_config = self._prepare_request(
274
+ messages, response_format, tools
275
+ )
276
+
277
+ return await self._async_client.chat.completions.create(
278
+ messages=messages,
279
+ model=self.model_type,
280
+ **request_config,
281
+ )
@@ -0,0 +1,83 @@
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
+ import os
15
+ from typing import Any, Dict, Optional, Union
16
+
17
+ from camel.configs import NebiusConfig
18
+ from camel.models.openai_compatible_model import OpenAICompatibleModel
19
+ from camel.types import ModelType
20
+ from camel.utils import (
21
+ BaseTokenCounter,
22
+ api_keys_required,
23
+ )
24
+
25
+
26
+ class NebiusModel(OpenAICompatibleModel):
27
+ r"""LLM API served by Nebius AI Studio in a unified OpenAICompatibleModel
28
+ interface.
29
+
30
+ Args:
31
+ model_type (Union[ModelType, str]): Model for which a backend is
32
+ created.
33
+ model_config_dict (Optional[Dict[str, Any]], optional): A dictionary
34
+ that will be fed into:obj:`openai.ChatCompletion.create()`.
35
+ If:obj:`None`, :obj:`NebiusConfig().as_dict()` will be used.
36
+ (default: :obj:`None`)
37
+ api_key (Optional[str], optional): The API key for authenticating
38
+ with the Nebius AI Studio service. (default: :obj:`None`).
39
+ url (Optional[str], optional): The url to the Nebius AI Studio service.
40
+ (default: :obj:`None`)
41
+ token_counter (Optional[BaseTokenCounter], optional): Token counter to
42
+ use for the model. If not provided, :obj:`OpenAITokenCounter(
43
+ ModelType.GPT_4O_MINI)` will be used.
44
+ (default: :obj:`None`)
45
+ timeout (Optional[float], optional): The timeout value in seconds for
46
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
47
+ environment variable or default to 180 seconds.
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.
53
+ """
54
+
55
+ @api_keys_required([("api_key", "NEBIUS_API_KEY")])
56
+ def __init__(
57
+ self,
58
+ model_type: Union[ModelType, str],
59
+ model_config_dict: Optional[Dict[str, Any]] = None,
60
+ api_key: Optional[str] = None,
61
+ url: Optional[str] = None,
62
+ token_counter: Optional[BaseTokenCounter] = None,
63
+ timeout: Optional[float] = None,
64
+ max_retries: int = 3,
65
+ **kwargs: Any,
66
+ ) -> None:
67
+ if model_config_dict is None:
68
+ model_config_dict = NebiusConfig().as_dict()
69
+ api_key = api_key or os.environ.get("NEBIUS_API_KEY")
70
+ url = url or os.environ.get(
71
+ "NEBIUS_API_BASE_URL", "https://api.studio.nebius.com/v1"
72
+ )
73
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
74
+ super().__init__(
75
+ model_type=model_type,
76
+ model_config_dict=model_config_dict,
77
+ api_key=api_key,
78
+ url=url,
79
+ token_counter=token_counter,
80
+ timeout=timeout,
81
+ max_retries=max_retries,
82
+ **kwargs,
83
+ )
@@ -80,8 +80,3 @@ class NemotronModel(OpenAICompatibleModel):
80
80
  raise NotImplementedError(
81
81
  "Nemotron model doesn't support token counter."
82
82
  )
83
-
84
- def check_model_config(self):
85
- raise NotImplementedError(
86
- "Nemotron model doesn't support model config."
87
- )
@@ -15,7 +15,7 @@
15
15
  import os
16
16
  from typing import Any, Dict, Optional, Union
17
17
 
18
- from camel.configs import NETMIND_API_PARAMS, NetmindConfig
18
+ from camel.configs import NetmindConfig
19
19
  from camel.models.openai_compatible_model import OpenAICompatibleModel
20
20
  from camel.types import ModelType
21
21
  from camel.utils import (
@@ -87,18 +87,3 @@ class NetmindModel(OpenAICompatibleModel):
87
87
  max_retries=max_retries,
88
88
  **kwargs,
89
89
  )
90
-
91
- def check_model_config(self):
92
- r"""Check whether the model configuration contains any
93
- unexpected arguments to NETMIND API.
94
-
95
- Raises:
96
- ValueError: If the model configuration dictionary contains any
97
- unexpected arguments to NETMIND API.
98
- """
99
- for param in self.model_config_dict:
100
- if param not in NETMIND_API_PARAMS:
101
- raise ValueError(
102
- f"Unexpected argument `{param}` is "
103
- "input into NETMIND model backend."
104
- )
@@ -15,7 +15,7 @@
15
15
  import os
16
16
  from typing import Any, Dict, Optional, Union
17
17
 
18
- from camel.configs import NOVITA_API_PARAMS, NovitaConfig
18
+ from camel.configs import NovitaConfig
19
19
  from camel.models.openai_compatible_model import OpenAICompatibleModel
20
20
  from camel.types import ModelType
21
21
  from camel.utils import (
@@ -86,18 +86,3 @@ class NovitaModel(OpenAICompatibleModel):
86
86
  max_retries=max_retries,
87
87
  **kwargs,
88
88
  )
89
-
90
- def check_model_config(self):
91
- r"""Check whether the model configuration contains any
92
- unexpected arguments to Novita API.
93
-
94
- Raises:
95
- ValueError: If the model configuration dictionary contains any
96
- unexpected arguments to Novita API.
97
- """
98
- for param in self.model_config_dict:
99
- if param not in NOVITA_API_PARAMS:
100
- raise ValueError(
101
- f"Unexpected argument `{param}` is "
102
- "input into Novita model backend."
103
- )
@@ -15,7 +15,7 @@
15
15
  import os
16
16
  from typing import Any, Dict, Optional, Union
17
17
 
18
- from camel.configs import NVIDIA_API_PARAMS, NvidiaConfig
18
+ from camel.configs import NvidiaConfig
19
19
  from camel.models.openai_compatible_model import OpenAICompatibleModel
20
20
  from camel.types import ModelType
21
21
  from camel.utils import BaseTokenCounter, api_keys_required
@@ -82,18 +82,3 @@ class NvidiaModel(OpenAICompatibleModel):
82
82
  max_retries=max_retries,
83
83
  **kwargs,
84
84
  )
85
-
86
- def check_model_config(self):
87
- r"""Check whether the model configuration contains any
88
- unexpected arguments to NVIDIA API.
89
-
90
- Raises:
91
- ValueError: If the model configuration dictionary contains any
92
- unexpected arguments to NVIDIA API.
93
- """
94
- for param in self.model_config_dict:
95
- if param not in NVIDIA_API_PARAMS:
96
- raise ValueError(
97
- f"Unexpected argument `{param}` is "
98
- "input into NVIDIA model backend."
99
- )
@@ -15,7 +15,7 @@ import os
15
15
  import subprocess
16
16
  from typing import Any, Dict, Optional, Union
17
17
 
18
- from camel.configs import OLLAMA_API_PARAMS, OllamaConfig
18
+ from camel.configs import OllamaConfig
19
19
  from camel.logger import get_logger
20
20
  from camel.models.openai_compatible_model import OpenAICompatibleModel
21
21
  from camel.types import ModelType
@@ -35,8 +35,8 @@ class OllamaModel(OpenAICompatibleModel):
35
35
  If:obj:`None`, :obj:`OllamaConfig().as_dict()` will be used.
36
36
  (default: :obj:`None`)
37
37
  api_key (Optional[str], optional): The API key for authenticating with
38
- the model service. Ollama doesn't need API key, it would be
39
- ignored if set. (default: :obj:`None`)
38
+ the model service. Required for Ollama cloud services. If not
39
+ provided, defaults to "Not_Provided". (default: :obj:`None`)
40
40
  url (Optional[str], optional): The url to the model service.
41
41
  (default: :obj:`None`)
42
42
  token_counter (Optional[BaseTokenCounter], optional): Token counter to
@@ -79,7 +79,7 @@ class OllamaModel(OpenAICompatibleModel):
79
79
  super().__init__(
80
80
  model_type=self._model_type,
81
81
  model_config_dict=model_config_dict,
82
- api_key="Not_Used",
82
+ api_key=api_key or "Not_Provided",
83
83
  url=self._url,
84
84
  token_counter=token_counter,
85
85
  timeout=timeout,
@@ -102,18 +102,3 @@ class OllamaModel(OpenAICompatibleModel):
102
102
  )
103
103
  except Exception as e:
104
104
  logger.error(f"Failed to start Ollama server: {e}.")
105
-
106
- def check_model_config(self):
107
- r"""Check whether the model configuration contains any
108
- unexpected arguments to Ollama API.
109
-
110
- Raises:
111
- ValueError: If the model configuration dictionary contains any
112
- unexpected arguments to OpenAI API.
113
- """
114
- for param in self.model_config_dict:
115
- if param not in OLLAMA_API_PARAMS:
116
- raise ValueError(
117
- f"Unexpected argument `{param}` is "
118
- "input into Ollama model backend."
119
- )