camel-ai 0.2.73a4__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 (173) hide show
  1. camel/__init__.py +1 -1
  2. camel/agents/_utils.py +38 -0
  3. camel/agents/chat_agent.py +2217 -519
  4. camel/agents/mcp_agent.py +30 -27
  5. camel/configs/__init__.py +15 -0
  6. camel/configs/aihubmix_config.py +88 -0
  7. camel/configs/amd_config.py +70 -0
  8. camel/configs/cometapi_config.py +104 -0
  9. camel/configs/minimax_config.py +93 -0
  10. camel/configs/nebius_config.py +103 -0
  11. camel/data_collectors/alpaca_collector.py +15 -6
  12. camel/datasets/base_generator.py +39 -10
  13. camel/environments/single_step.py +28 -3
  14. camel/environments/tic_tac_toe.py +1 -1
  15. camel/interpreters/__init__.py +2 -0
  16. camel/interpreters/docker/Dockerfile +3 -12
  17. camel/interpreters/e2b_interpreter.py +34 -1
  18. camel/interpreters/microsandbox_interpreter.py +395 -0
  19. camel/loaders/__init__.py +11 -2
  20. camel/loaders/chunkr_reader.py +9 -0
  21. camel/memories/agent_memories.py +48 -4
  22. camel/memories/base.py +26 -0
  23. camel/memories/blocks/chat_history_block.py +122 -4
  24. camel/memories/context_creators/score_based.py +25 -384
  25. camel/memories/records.py +88 -8
  26. camel/messages/base.py +153 -34
  27. camel/models/__init__.py +10 -0
  28. camel/models/aihubmix_model.py +83 -0
  29. camel/models/aiml_model.py +1 -16
  30. camel/models/amd_model.py +101 -0
  31. camel/models/anthropic_model.py +6 -19
  32. camel/models/aws_bedrock_model.py +2 -33
  33. camel/models/azure_openai_model.py +114 -89
  34. camel/models/base_audio_model.py +3 -1
  35. camel/models/base_model.py +32 -14
  36. camel/models/cohere_model.py +1 -16
  37. camel/models/cometapi_model.py +83 -0
  38. camel/models/crynux_model.py +1 -16
  39. camel/models/deepseek_model.py +1 -16
  40. camel/models/fish_audio_model.py +6 -0
  41. camel/models/gemini_model.py +36 -18
  42. camel/models/groq_model.py +1 -17
  43. camel/models/internlm_model.py +1 -16
  44. camel/models/litellm_model.py +1 -16
  45. camel/models/lmstudio_model.py +1 -17
  46. camel/models/minimax_model.py +83 -0
  47. camel/models/mistral_model.py +1 -16
  48. camel/models/model_factory.py +27 -1
  49. camel/models/modelscope_model.py +1 -16
  50. camel/models/moonshot_model.py +105 -24
  51. camel/models/nebius_model.py +83 -0
  52. camel/models/nemotron_model.py +0 -5
  53. camel/models/netmind_model.py +1 -16
  54. camel/models/novita_model.py +1 -16
  55. camel/models/nvidia_model.py +1 -16
  56. camel/models/ollama_model.py +4 -19
  57. camel/models/openai_compatible_model.py +62 -41
  58. camel/models/openai_model.py +62 -57
  59. camel/models/openrouter_model.py +1 -17
  60. camel/models/ppio_model.py +1 -16
  61. camel/models/qianfan_model.py +1 -16
  62. camel/models/qwen_model.py +1 -16
  63. camel/models/reka_model.py +1 -16
  64. camel/models/samba_model.py +34 -47
  65. camel/models/sglang_model.py +64 -31
  66. camel/models/siliconflow_model.py +1 -16
  67. camel/models/stub_model.py +0 -4
  68. camel/models/togetherai_model.py +1 -16
  69. camel/models/vllm_model.py +1 -16
  70. camel/models/volcano_model.py +0 -17
  71. camel/models/watsonx_model.py +1 -16
  72. camel/models/yi_model.py +1 -16
  73. camel/models/zhipuai_model.py +60 -16
  74. camel/parsers/__init__.py +18 -0
  75. camel/parsers/mcp_tool_call_parser.py +176 -0
  76. camel/retrievers/auto_retriever.py +1 -0
  77. camel/runtimes/daytona_runtime.py +11 -12
  78. camel/societies/__init__.py +2 -0
  79. camel/societies/workforce/__init__.py +2 -0
  80. camel/societies/workforce/events.py +122 -0
  81. camel/societies/workforce/prompts.py +146 -66
  82. camel/societies/workforce/role_playing_worker.py +15 -11
  83. camel/societies/workforce/single_agent_worker.py +302 -65
  84. camel/societies/workforce/structured_output_handler.py +30 -18
  85. camel/societies/workforce/task_channel.py +163 -27
  86. camel/societies/workforce/utils.py +107 -13
  87. camel/societies/workforce/workflow_memory_manager.py +772 -0
  88. camel/societies/workforce/workforce.py +1949 -579
  89. camel/societies/workforce/workforce_callback.py +74 -0
  90. camel/societies/workforce/workforce_logger.py +168 -145
  91. camel/societies/workforce/workforce_metrics.py +33 -0
  92. camel/storages/key_value_storages/json.py +15 -2
  93. camel/storages/key_value_storages/mem0_cloud.py +48 -47
  94. camel/storages/object_storages/google_cloud.py +1 -1
  95. camel/storages/vectordb_storages/oceanbase.py +13 -13
  96. camel/storages/vectordb_storages/qdrant.py +3 -3
  97. camel/storages/vectordb_storages/tidb.py +8 -6
  98. camel/tasks/task.py +4 -3
  99. camel/toolkits/__init__.py +20 -7
  100. camel/toolkits/aci_toolkit.py +45 -0
  101. camel/toolkits/base.py +6 -4
  102. camel/toolkits/code_execution.py +28 -1
  103. camel/toolkits/context_summarizer_toolkit.py +684 -0
  104. camel/toolkits/dappier_toolkit.py +5 -1
  105. camel/toolkits/dingtalk.py +1135 -0
  106. camel/toolkits/edgeone_pages_mcp_toolkit.py +11 -31
  107. camel/toolkits/excel_toolkit.py +1 -1
  108. camel/toolkits/{file_write_toolkit.py → file_toolkit.py} +430 -36
  109. camel/toolkits/function_tool.py +13 -3
  110. camel/toolkits/github_toolkit.py +104 -17
  111. camel/toolkits/gmail_toolkit.py +1839 -0
  112. camel/toolkits/google_calendar_toolkit.py +38 -4
  113. camel/toolkits/google_drive_mcp_toolkit.py +12 -31
  114. camel/toolkits/hybrid_browser_toolkit/config_loader.py +15 -0
  115. camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit.py +77 -8
  116. camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit_ts.py +884 -88
  117. camel/toolkits/hybrid_browser_toolkit/installer.py +203 -0
  118. camel/toolkits/hybrid_browser_toolkit/ts/package-lock.json +5 -612
  119. camel/toolkits/hybrid_browser_toolkit/ts/package.json +0 -1
  120. camel/toolkits/hybrid_browser_toolkit/ts/src/browser-session.ts +959 -89
  121. camel/toolkits/hybrid_browser_toolkit/ts/src/config-loader.ts +9 -2
  122. camel/toolkits/hybrid_browser_toolkit/ts/src/hybrid-browser-toolkit.ts +281 -213
  123. camel/toolkits/hybrid_browser_toolkit/ts/src/parent-child-filter.ts +226 -0
  124. camel/toolkits/hybrid_browser_toolkit/ts/src/snapshot-parser.ts +219 -0
  125. camel/toolkits/hybrid_browser_toolkit/ts/src/som-screenshot-injected.ts +543 -0
  126. camel/toolkits/hybrid_browser_toolkit/ts/src/types.ts +23 -3
  127. camel/toolkits/hybrid_browser_toolkit/ts/websocket-server.js +72 -7
  128. camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py +582 -132
  129. camel/toolkits/hybrid_browser_toolkit_py/actions.py +158 -0
  130. camel/toolkits/hybrid_browser_toolkit_py/browser_session.py +55 -8
  131. camel/toolkits/hybrid_browser_toolkit_py/config_loader.py +43 -0
  132. camel/toolkits/hybrid_browser_toolkit_py/hybrid_browser_toolkit.py +321 -8
  133. camel/toolkits/hybrid_browser_toolkit_py/snapshot.py +10 -4
  134. camel/toolkits/hybrid_browser_toolkit_py/unified_analyzer.js +45 -4
  135. camel/toolkits/{openai_image_toolkit.py → image_generation_toolkit.py} +151 -53
  136. camel/toolkits/klavis_toolkit.py +5 -1
  137. camel/toolkits/markitdown_toolkit.py +27 -1
  138. camel/toolkits/math_toolkit.py +64 -10
  139. camel/toolkits/mcp_toolkit.py +366 -71
  140. camel/toolkits/memory_toolkit.py +5 -1
  141. camel/toolkits/message_integration.py +18 -13
  142. camel/toolkits/minimax_mcp_toolkit.py +195 -0
  143. camel/toolkits/note_taking_toolkit.py +19 -10
  144. camel/toolkits/notion_mcp_toolkit.py +16 -26
  145. camel/toolkits/openbb_toolkit.py +5 -1
  146. camel/toolkits/origene_mcp_toolkit.py +8 -49
  147. camel/toolkits/playwright_mcp_toolkit.py +12 -31
  148. camel/toolkits/resend_toolkit.py +168 -0
  149. camel/toolkits/search_toolkit.py +264 -91
  150. camel/toolkits/slack_toolkit.py +64 -10
  151. camel/toolkits/terminal_toolkit/__init__.py +18 -0
  152. camel/toolkits/terminal_toolkit/terminal_toolkit.py +957 -0
  153. camel/toolkits/terminal_toolkit/utils.py +532 -0
  154. camel/toolkits/vertex_ai_veo_toolkit.py +590 -0
  155. camel/toolkits/video_analysis_toolkit.py +17 -11
  156. camel/toolkits/wechat_official_toolkit.py +483 -0
  157. camel/toolkits/zapier_toolkit.py +5 -1
  158. camel/types/__init__.py +2 -2
  159. camel/types/enums.py +274 -7
  160. camel/types/openai_types.py +2 -2
  161. camel/types/unified_model_type.py +15 -0
  162. camel/utils/commons.py +36 -5
  163. camel/utils/constants.py +3 -0
  164. camel/utils/context_utils.py +1003 -0
  165. camel/utils/mcp.py +138 -4
  166. camel/utils/token_counting.py +43 -20
  167. {camel_ai-0.2.73a4.dist-info → camel_ai-0.2.80a2.dist-info}/METADATA +223 -83
  168. {camel_ai-0.2.73a4.dist-info → camel_ai-0.2.80a2.dist-info}/RECORD +170 -141
  169. camel/loaders/pandas_reader.py +0 -368
  170. camel/toolkits/openai_agent_toolkit.py +0 -135
  171. camel/toolkits/terminal_toolkit.py +0 -1550
  172. {camel_ai-0.2.73a4.dist-info → camel_ai-0.2.80a2.dist-info}/WHEEL +0 -0
  173. {camel_ai-0.2.73a4.dist-info → camel_ai-0.2.80a2.dist-info}/licenses/LICENSE +0 -0
camel/messages/base.py CHANGED
@@ -64,8 +64,9 @@ class BaseMessage:
64
64
  content (str): The content of the message.
65
65
  video_bytes (Optional[bytes]): Optional bytes of a video associated
66
66
  with the message. (default: :obj:`None`)
67
- image_list (Optional[List[Image.Image]]): Optional list of PIL Image
68
- objects associated with the message. (default: :obj:`None`)
67
+ image_list (Optional[List[Union[Image.Image, str]]]): Optional list of
68
+ PIL Image objects or image URLs (strings) associated with the
69
+ message. (default: :obj:`None`)
69
70
  image_detail (Literal["auto", "low", "high"]): Detail level of the
70
71
  images associated with the message. (default: :obj:`auto`)
71
72
  video_detail (Literal["auto", "low", "high"]): Detail level of the
@@ -80,7 +81,7 @@ class BaseMessage:
80
81
  content: str
81
82
 
82
83
  video_bytes: Optional[bytes] = None
83
- image_list: Optional[List[Image.Image]] = None
84
+ image_list: Optional[List[Union[Image.Image, str]]] = None
84
85
  image_detail: Literal["auto", "low", "high"] = "auto"
85
86
  video_detail: Literal["auto", "low", "high"] = "auto"
86
87
  parsed: Optional[Union[BaseModel, dict]] = None
@@ -92,7 +93,7 @@ class BaseMessage:
92
93
  content: str,
93
94
  meta_dict: Optional[Dict[str, str]] = None,
94
95
  video_bytes: Optional[bytes] = None,
95
- image_list: Optional[List[Image.Image]] = None,
96
+ image_list: Optional[List[Union[Image.Image, str]]] = None,
96
97
  image_detail: Union[
97
98
  OpenAIVisionDetailType, str
98
99
  ] = OpenAIVisionDetailType.AUTO,
@@ -109,8 +110,9 @@ class BaseMessage:
109
110
  dictionary for the message.
110
111
  video_bytes (Optional[bytes]): Optional bytes of a video
111
112
  associated with the message.
112
- image_list (Optional[List[Image.Image]]): Optional list of PIL
113
- Image objects associated with the message.
113
+ image_list (Optional[List[Union[Image.Image, str]]]): Optional list
114
+ of PIL Image objects or image URLs (strings) associated with
115
+ the message.
114
116
  image_detail (Union[OpenAIVisionDetailType, str]): Detail level of
115
117
  the images associated with the message.
116
118
  video_detail (Union[OpenAIVisionDetailType, str]): Detail level of
@@ -137,7 +139,7 @@ class BaseMessage:
137
139
  content: str,
138
140
  meta_dict: Optional[Dict[str, str]] = None,
139
141
  video_bytes: Optional[bytes] = None,
140
- image_list: Optional[List[Image.Image]] = None,
142
+ image_list: Optional[List[Union[Image.Image, str]]] = None,
141
143
  image_detail: Union[
142
144
  OpenAIVisionDetailType, str
143
145
  ] = OpenAIVisionDetailType.AUTO,
@@ -154,8 +156,9 @@ class BaseMessage:
154
156
  dictionary for the message.
155
157
  video_bytes (Optional[bytes]): Optional bytes of a video
156
158
  associated with the message.
157
- image_list (Optional[List[Image.Image]]): Optional list of PIL
158
- Image objects associated with the message.
159
+ image_list (Optional[List[Union[Image.Image, str]]]): Optional list
160
+ of PIL Image objects or image URLs (strings) associated with
161
+ the message.
159
162
  image_detail (Union[OpenAIVisionDetailType, str]): Detail level of
160
163
  the images associated with the message.
161
164
  video_detail (Union[OpenAIVisionDetailType, str]): Detail level of
@@ -175,6 +178,32 @@ class BaseMessage:
175
178
  OpenAIVisionDetailType(video_detail).value,
176
179
  )
177
180
 
181
+ @classmethod
182
+ def make_system_message(
183
+ cls,
184
+ content: str,
185
+ role_name: str = "System",
186
+ meta_dict: Optional[Dict[str, str]] = None,
187
+ ) -> "BaseMessage":
188
+ r"""Create a new system message.
189
+
190
+ Args:
191
+ content (str): The content of the system message.
192
+ role_name (str): The name of the system role.
193
+ (default: :obj:`"System"`)
194
+ meta_dict (Optional[Dict[str, str]]): Additional metadata
195
+ dictionary for the message.
196
+
197
+ Returns:
198
+ BaseMessage: The new system message.
199
+ """
200
+ return cls(
201
+ role_name,
202
+ RoleType.SYSTEM,
203
+ meta_dict,
204
+ content,
205
+ )
206
+
178
207
  def create_new_instance(self, content: str) -> "BaseMessage":
179
208
  r"""Create a new instance of the :obj:`BaseMessage` with updated
180
209
  content.
@@ -436,31 +465,64 @@ class BaseMessage:
436
465
  )
437
466
  if self.image_list and len(self.image_list) > 0:
438
467
  for image in self.image_list:
439
- if image.format is None:
440
- # Set default format to PNG as fallback
441
- image.format = 'PNG'
442
-
443
- image_type: str = image.format.lower()
444
- if image_type not in OpenAIImageType:
445
- raise ValueError(
446
- f"Image type {image.format} "
447
- f"is not supported by OpenAI vision model"
468
+ # Check if image is a URL string or PIL Image
469
+ if isinstance(image, str):
470
+ # Image is a URL string
471
+ hybrid_content.append(
472
+ {
473
+ "type": "image_url",
474
+ "image_url": {
475
+ "url": image,
476
+ "detail": self.image_detail,
477
+ },
478
+ }
448
479
  )
449
- with io.BytesIO() as buffer:
450
- image.save(fp=buffer, format=image.format)
451
- encoded_image = base64.b64encode(buffer.getvalue()).decode(
452
- "utf-8"
480
+ else:
481
+ # Image is a PIL Image object
482
+ if image.format is None:
483
+ # Set default format to PNG as fallback
484
+ image.format = 'PNG'
485
+
486
+ image_type: str = image.format.lower()
487
+ if image_type not in OpenAIImageType:
488
+ raise ValueError(
489
+ f"Image type {image.format} "
490
+ f"is not supported by OpenAI vision model"
491
+ )
492
+
493
+ # Convert RGBA to RGB for formats that don't support
494
+ # transparency or when the image has transparency channel
495
+ img_to_save = image
496
+ if image.mode in ('RGBA', 'LA', 'P') and image_type in (
497
+ 'jpeg',
498
+ 'jpg',
499
+ ):
500
+ # JPEG doesn't support transparency, convert to RGB
501
+ img_to_save = image.convert('RGB')
502
+ elif (
503
+ image.mode in ('RGBA', 'LA', 'P')
504
+ and image_type == 'png'
505
+ ):
506
+ # For PNG with transparency, convert to RGBA if needed
507
+ if image.mode in ('LA', 'P'):
508
+ img_to_save = image.convert('RGBA')
509
+ # else: RGBA mode, keep as-is
510
+
511
+ with io.BytesIO() as buffer:
512
+ img_to_save.save(fp=buffer, format=image.format)
513
+ encoded_image = base64.b64encode(
514
+ buffer.getvalue()
515
+ ).decode("utf-8")
516
+ image_prefix = f"data:image/{image_type};base64,"
517
+ hybrid_content.append(
518
+ {
519
+ "type": "image_url",
520
+ "image_url": {
521
+ "url": f"{image_prefix}{encoded_image}",
522
+ "detail": self.image_detail,
523
+ },
524
+ }
453
525
  )
454
- image_prefix = f"data:image/{image_type};base64,"
455
- hybrid_content.append(
456
- {
457
- "type": "image_url",
458
- "image_url": {
459
- "url": f"{image_prefix}{encoded_image}",
460
- "detail": self.image_detail,
461
- },
462
- }
463
- )
464
526
 
465
527
  if self.video_bytes:
466
528
  import imageio.v3 as iio
@@ -552,9 +614,66 @@ class BaseMessage:
552
614
  Returns:
553
615
  dict: The converted dictionary.
554
616
  """
555
- return {
617
+ result = {
556
618
  "role_name": self.role_name,
557
- "role_type": self.role_type.name,
619
+ "role_type": self.role_type.value,
558
620
  **(self.meta_dict or {}),
559
621
  "content": self.content,
560
622
  }
623
+
624
+ # Include image/video fields if present
625
+ if self.image_list is not None:
626
+ # Handle both PIL Images and URL strings
627
+ import base64
628
+ from io import BytesIO
629
+
630
+ image_data_list = []
631
+ for img in self.image_list:
632
+ if isinstance(img, str):
633
+ # Image is a URL string, store as-is
634
+ image_data_list.append({"type": "url", "data": img})
635
+ else:
636
+ # Image is a PIL Image, convert to base64
637
+ # Preserve format, default to PNG if not set
638
+ img_format = img.format if img.format else "PNG"
639
+
640
+ # Handle transparency for different formats
641
+ img_to_save = img
642
+ if img.mode in (
643
+ 'RGBA',
644
+ 'LA',
645
+ 'P',
646
+ ) and img_format.upper() in ('JPEG', 'JPG'):
647
+ # JPEG doesn't support transparency, convert to RGB
648
+ img_to_save = img.convert('RGB')
649
+ elif (
650
+ img.mode in ('LA', 'P') and img_format.upper() == 'PNG'
651
+ ):
652
+ # For PNG with transparency, convert to RGBA if needed
653
+ img_to_save = img.convert('RGBA')
654
+ # else: keep as-is for other combinations
655
+
656
+ buffered = BytesIO()
657
+ img_to_save.save(buffered, format=img_format)
658
+ img_str = base64.b64encode(buffered.getvalue()).decode()
659
+ image_data_list.append(
660
+ {
661
+ "type": "base64",
662
+ "data": img_str,
663
+ "format": img_format, # Preserve format
664
+ }
665
+ )
666
+ result["image_list"] = image_data_list
667
+
668
+ if self.video_bytes is not None:
669
+ import base64
670
+
671
+ result["video_bytes"] = base64.b64encode(self.video_bytes).decode()
672
+
673
+ if self.image_detail is not None:
674
+ result["image_detail"] = self.image_detail
675
+
676
+ if self.video_detail is not None:
677
+ result["video_detail"] = self.video_detail
678
+
679
+ return result
camel/models/__init__.py CHANGED
@@ -11,13 +11,16 @@
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
13
  # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
+ from .aihubmix_model import AihubMixModel
14
15
  from .aiml_model import AIMLModel
16
+ from .amd_model import AMDModel
15
17
  from .anthropic_model import AnthropicModel
16
18
  from .aws_bedrock_model import AWSBedrockModel
17
19
  from .azure_openai_model import AzureOpenAIModel
18
20
  from .base_audio_model import BaseAudioModel
19
21
  from .base_model import BaseModelBackend
20
22
  from .cohere_model import CohereModel
23
+ from .cometapi_model import CometAPIModel
21
24
  from .crynux_model import CrynuxModel
22
25
  from .deepseek_model import DeepSeekModel
23
26
  from .fish_audio_model import FishAudioModel
@@ -26,11 +29,13 @@ from .groq_model import GroqModel
26
29
  from .internlm_model import InternLMModel
27
30
  from .litellm_model import LiteLLMModel
28
31
  from .lmstudio_model import LMStudioModel
32
+ from .minimax_model import MinimaxModel
29
33
  from .mistral_model import MistralModel
30
34
  from .model_factory import ModelFactory
31
35
  from .model_manager import ModelManager, ModelProcessingError
32
36
  from .modelscope_model import ModelScopeModel
33
37
  from .moonshot_model import MoonshotModel
38
+ from .nebius_model import NebiusModel
34
39
  from .nemotron_model import NemotronModel
35
40
  from .netmind_model import NetmindModel
36
41
  from .novita_model import NovitaModel
@@ -61,11 +66,13 @@ __all__ = [
61
66
  'OpenRouterModel',
62
67
  'AzureOpenAIModel',
63
68
  'AnthropicModel',
69
+ 'AMDModel',
64
70
  'MistralModel',
65
71
  'GroqModel',
66
72
  'StubModel',
67
73
  'ZhipuAIModel',
68
74
  'CohereModel',
75
+ 'CometAPIModel',
69
76
  'ModelFactory',
70
77
  'ModelManager',
71
78
  'LiteLLMModel',
@@ -87,6 +94,7 @@ __all__ = [
87
94
  'QwenModel',
88
95
  'AWSBedrockModel',
89
96
  'ModelProcessingError',
97
+ 'NebiusModel',
90
98
  'DeepSeekModel',
91
99
  'FishAudioModel',
92
100
  'InternLMModel',
@@ -97,7 +105,9 @@ __all__ = [
97
105
  'SiliconFlowModel',
98
106
  'VolcanoModel',
99
107
  'LMStudioModel',
108
+ 'MinimaxModel',
100
109
  'WatsonXModel',
101
110
  'QianfanModel',
102
111
  'CrynuxModel',
112
+ 'AihubMixModel',
103
113
  ]
@@ -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.models.openai_compatible_model import OpenAICompatibleModel
18
+ from camel.types import ModelType
19
+ from camel.utils import (
20
+ BaseTokenCounter,
21
+ api_keys_required,
22
+ )
23
+
24
+
25
+ class AihubMixModel(OpenAICompatibleModel):
26
+ r"""AihubMix API in a unified OpenAICompatibleModel interface.
27
+
28
+ Args:
29
+ model_type (Union[ModelType, str]): Model for which a backend is
30
+ created.
31
+ model_config_dict (Optional[Dict[str, Any]], optional): A dictionary
32
+ that will be fed into OpenAI client. If :obj:`None`,
33
+ :obj:`{}` will be used.
34
+ (default: :obj:`None`)
35
+ api_key (Optional[str], optional): The API key for authenticating with
36
+ AihubMix service. (default: :obj:`None`)
37
+ url (Optional[str], optional): The URL to AihubMix service. If
38
+ not provided, :obj:`https://aihubmix.com/v1` will be used.
39
+ (default: :obj:`None`)
40
+ token_counter (Optional[BaseTokenCounter], optional): Token counter to
41
+ use for the model. If not provided, :obj:`OpenAITokenCounter(
42
+ ModelType.GPT_4O_MINI)` will be used.
43
+ (default: :obj:`None`)
44
+ timeout (Optional[float], optional): The timeout value in seconds for
45
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
46
+ environment variable or default to 180 seconds.
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.
52
+ """
53
+
54
+ @api_keys_required([("api_key", "AIHUBMIX_API_KEY")])
55
+ def __init__(
56
+ self,
57
+ model_type: Union[ModelType, str],
58
+ model_config_dict: Optional[Dict[str, Any]] = None,
59
+ api_key: Optional[str] = None,
60
+ url: Optional[str] = None,
61
+ token_counter: Optional[BaseTokenCounter] = None,
62
+ timeout: Optional[float] = None,
63
+ max_retries: int = 3,
64
+ **kwargs: Any,
65
+ ) -> None:
66
+ if model_config_dict is None:
67
+ model_config_dict = {}
68
+ api_key = api_key or os.environ.get("AIHUBMIX_API_KEY")
69
+ url = url or os.environ.get(
70
+ "AIHUBMIX_API_BASE_URL",
71
+ "https://aihubmix.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
+ )
@@ -14,7 +14,7 @@
14
14
  import os
15
15
  from typing import Any, Dict, Optional, Union
16
16
 
17
- from camel.configs import AIML_API_PARAMS, AIMLConfig
17
+ from camel.configs import AIMLConfig
18
18
  from camel.models.openai_compatible_model import OpenAICompatibleModel
19
19
  from camel.types import ModelType
20
20
  from camel.utils import (
@@ -82,18 +82,3 @@ class AIMLModel(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 AIML API.
89
-
90
- Raises:
91
- ValueError: If the model configuration dictionary contains any
92
- unexpected arguments to AIML API.
93
- """
94
- for param in self.model_config_dict:
95
- if param not in AIML_API_PARAMS:
96
- raise ValueError(
97
- f"Unexpected argument `{param}` is "
98
- "input into AIML model backend."
99
- )
@@ -0,0 +1,101 @@
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
+
15
+ import os
16
+ from typing import Any, Dict, Optional, Union
17
+
18
+ from camel.configs import AMD_API_PARAMS, AMDConfig
19
+ from camel.models.openai_compatible_model import OpenAICompatibleModel
20
+ from camel.types import ModelType
21
+ from camel.utils import BaseTokenCounter, api_keys_required
22
+
23
+
24
+ class AMDModel(OpenAICompatibleModel):
25
+ r"""AMD API in a unified OpenAICompatibleModel interface.
26
+
27
+ Args:
28
+ model_type (Union[ModelType, str]): Model for which a backend is
29
+ created, one of AMD series.
30
+ model_config_dict (Optional[Dict[str, Any]], optional): A dictionary
31
+ that will be fed into:obj:`openai.ChatCompletion.create()`. If
32
+ :obj:`None`, :obj:`AMDConfig().as_dict()` will be used.
33
+ (default: :obj:`None`)
34
+ api_key (Optional[str], optional): The API key for authenticating with
35
+ the AMD service. (default: :obj:`None`)
36
+ url (Optional[str], optional): The url to the AMD service.
37
+ (default: :obj:`None`)
38
+ token_counter (Optional[BaseTokenCounter], optional): Token counter to
39
+ use for the model. If not provided, :obj:`OpenAITokenCounter(
40
+ ModelType.GPT_4)` will be used.
41
+ (default: :obj:`None`)
42
+ timeout (Optional[float], optional): The timeout value in seconds for
43
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
44
+ environment variable or default to 180 seconds.
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.
50
+ """
51
+
52
+ @api_keys_required(
53
+ [
54
+ ("api_key", "AMD_API_KEY"),
55
+ ]
56
+ )
57
+ def __init__(
58
+ self,
59
+ model_type: Union[ModelType, str],
60
+ model_config_dict: Optional[Dict[str, Any]] = None,
61
+ api_key: Optional[str] = None,
62
+ url: Optional[str] = None,
63
+ token_counter: Optional[BaseTokenCounter] = None,
64
+ timeout: Optional[float] = None,
65
+ max_retries: int = 3,
66
+ **kwargs: Any,
67
+ ) -> None:
68
+ if model_config_dict is None:
69
+ model_config_dict = AMDConfig().as_dict()
70
+ api_key = api_key or os.environ.get("AMD_API_KEY")
71
+ url = url or os.environ.get(
72
+ "AMD_API_BASE_URL", "https://llm-api.amd.com"
73
+ )
74
+ headers = {'Ocp-Apim-Subscription-Key': api_key}
75
+ kwargs["default_headers"] = headers
76
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
77
+ super().__init__(
78
+ model_type=model_type,
79
+ model_config_dict=model_config_dict,
80
+ api_key=api_key,
81
+ url=url,
82
+ token_counter=token_counter,
83
+ timeout=timeout,
84
+ max_retries=max_retries,
85
+ **kwargs,
86
+ )
87
+
88
+ def check_model_config(self):
89
+ r"""Check whether the model configuration contains any
90
+ unexpected arguments to AMD API.
91
+
92
+ Raises:
93
+ ValueError: If the model configuration dictionary contains any
94
+ unexpected arguments to AMD API.
95
+ """
96
+ for param in self.model_config_dict:
97
+ if param not in AMD_API_PARAMS:
98
+ raise ValueError(
99
+ f"Unexpected argument `{param}` is "
100
+ "input into AMD model backend."
101
+ )
@@ -16,13 +16,13 @@ from typing import Any, Dict, List, Optional, Union
16
16
 
17
17
  from openai import AsyncStream, Stream
18
18
 
19
- from camel.configs import ANTHROPIC_API_PARAMS, AnthropicConfig
19
+ from camel.configs import AnthropicConfig
20
20
  from camel.messages import OpenAIMessage
21
21
  from camel.models.openai_compatible_model import OpenAICompatibleModel
22
22
  from camel.types import ChatCompletion, ChatCompletionChunk, ModelType
23
23
  from camel.utils import (
24
- AnthropicTokenCounter,
25
24
  BaseTokenCounter,
25
+ OpenAITokenCounter,
26
26
  api_keys_required,
27
27
  dependencies_required,
28
28
  )
@@ -141,28 +141,15 @@ class AnthropicModel(OpenAICompatibleModel):
141
141
  r"""Initialize the token counter for the model backend.
142
142
 
143
143
  Returns:
144
- BaseTokenCounter: The token counter following the model's
144
+ OpenAITokenCounter: The token counter following the model's
145
145
  tokenization style.
146
146
  """
147
+ # TODO: use anthropic token counter
148
+
147
149
  if not self._token_counter:
148
- self._token_counter = AnthropicTokenCounter(self.model_type)
150
+ self._token_counter = OpenAITokenCounter(ModelType.GPT_4O_MINI)
149
151
  return self._token_counter
150
152
 
151
- def check_model_config(self):
152
- r"""Check whether the model configuration is valid for anthropic
153
- model backends.
154
-
155
- Raises:
156
- ValueError: If the model configuration dictionary contains any
157
- unexpected arguments to Anthropic API.
158
- """
159
- for param in self.model_config_dict:
160
- if param not in ANTHROPIC_API_PARAMS:
161
- raise ValueError(
162
- f"Unexpected argument `{param}` is "
163
- "input into Anthropic model backend."
164
- )
165
-
166
153
  def _request_chat_completion(
167
154
  self,
168
155
  messages: List[OpenAIMessage],
@@ -13,17 +13,11 @@
13
13
  # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
14
 
15
15
  import os
16
- from typing import Any, Dict, List, Optional, Type, Union
16
+ from typing import Any, Dict, Optional, Union
17
17
 
18
- from openai import AsyncStream
19
- from pydantic import BaseModel
20
-
21
- from camel.configs import BEDROCK_API_PARAMS, BedrockConfig
22
- from camel.messages import OpenAIMessage
18
+ from camel.configs import BedrockConfig
23
19
  from camel.models.openai_compatible_model import OpenAICompatibleModel
24
20
  from camel.types import (
25
- ChatCompletion,
26
- ChatCompletionChunk,
27
21
  ModelType,
28
22
  )
29
23
  from camel.utils import BaseTokenCounter, api_keys_required
@@ -93,28 +87,3 @@ class AWSBedrockModel(OpenAICompatibleModel):
93
87
  max_retries=max_retries,
94
88
  **kwargs,
95
89
  )
96
-
97
- async def _arun(
98
- self,
99
- messages: List[OpenAIMessage],
100
- response_format: Optional[Type[BaseModel]] = None,
101
- tools: Optional[List[Dict[str, Any]]] = None,
102
- ) -> Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]:
103
- raise NotImplementedError(
104
- "AWS Bedrock does not support async inference."
105
- )
106
-
107
- def check_model_config(self):
108
- r"""Check whether the input model configuration contains unexpected
109
- arguments.
110
-
111
- Raises:
112
- ValueError: If the model configuration dictionary contains any
113
- unexpected argument for this model class.
114
- """
115
- for param in self.model_config_dict:
116
- if param not in BEDROCK_API_PARAMS:
117
- raise ValueError(
118
- f"Invalid parameter '{param}' in model_config_dict. "
119
- f"Valid parameters are: {BEDROCK_API_PARAMS}"
120
- )