camel-ai 0.2.11__py3-none-any.whl → 0.2.12__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.

Potentially problematic release.


This version of camel-ai might be problematic. Click here for more details.

Files changed (55) hide show
  1. camel/__init__.py +1 -1
  2. camel/agents/chat_agent.py +13 -1
  3. camel/benchmarks/__init__.py +18 -0
  4. camel/benchmarks/base.py +152 -0
  5. camel/benchmarks/gaia.py +478 -0
  6. camel/configs/__init__.py +3 -0
  7. camel/configs/ollama_config.py +4 -2
  8. camel/configs/sglang_config.py +71 -0
  9. camel/data_collector/__init__.py +19 -0
  10. camel/data_collector/alpaca_collector.py +127 -0
  11. camel/data_collector/base.py +211 -0
  12. camel/data_collector/sharegpt_collector.py +205 -0
  13. camel/datahubs/__init__.py +23 -0
  14. camel/datahubs/base.py +136 -0
  15. camel/datahubs/huggingface.py +433 -0
  16. camel/datahubs/models.py +22 -0
  17. camel/interpreters/__init__.py +2 -0
  18. camel/interpreters/e2b_interpreter.py +136 -0
  19. camel/loaders/__init__.py +3 -1
  20. camel/loaders/base_io.py +41 -41
  21. camel/messages/__init__.py +2 -0
  22. camel/models/__init__.py +2 -0
  23. camel/models/anthropic_model.py +14 -4
  24. camel/models/base_model.py +28 -0
  25. camel/models/groq_model.py +1 -1
  26. camel/models/model_factory.py +3 -0
  27. camel/models/ollama_model.py +12 -0
  28. camel/models/openai_model.py +0 -26
  29. camel/models/reward/__init__.py +22 -0
  30. camel/models/reward/base_reward_model.py +58 -0
  31. camel/models/reward/evaluator.py +63 -0
  32. camel/models/reward/nemotron_model.py +112 -0
  33. camel/models/sglang_model.py +225 -0
  34. camel/models/vllm_model.py +1 -1
  35. camel/personas/persona_hub.py +2 -2
  36. camel/schemas/openai_converter.py +2 -2
  37. camel/societies/workforce/role_playing_worker.py +2 -2
  38. camel/societies/workforce/single_agent_worker.py +2 -2
  39. camel/societies/workforce/workforce.py +3 -3
  40. camel/storages/object_storages/amazon_s3.py +2 -2
  41. camel/storages/object_storages/azure_blob.py +2 -2
  42. camel/storages/object_storages/google_cloud.py +2 -2
  43. camel/toolkits/__init__.py +2 -0
  44. camel/toolkits/code_execution.py +5 -1
  45. camel/toolkits/function_tool.py +41 -0
  46. camel/toolkits/math_toolkit.py +47 -16
  47. camel/toolkits/search_toolkit.py +154 -2
  48. camel/toolkits/stripe_toolkit.py +273 -0
  49. camel/types/__init__.py +2 -0
  50. camel/types/enums.py +27 -2
  51. camel/utils/token_counting.py +22 -10
  52. {camel_ai-0.2.11.dist-info → camel_ai-0.2.12.dist-info}/METADATA +13 -6
  53. {camel_ai-0.2.11.dist-info → camel_ai-0.2.12.dist-info}/RECORD +55 -36
  54. {camel_ai-0.2.11.dist-info → camel_ai-0.2.12.dist-info}/LICENSE +0 -0
  55. {camel_ai-0.2.11.dist-info → camel_ai-0.2.12.dist-info}/WHEEL +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.11'
17
+ __version__ = '0.2.12'
18
18
 
19
19
  __all__ = [
20
20
  '__version__',
@@ -499,6 +499,13 @@ class ChatAgent(BaseAgent):
499
499
  "the model configuration and in the ChatAgent step."
500
500
  )
501
501
 
502
+ original_model_dict = self.model_backend.model_config_dict
503
+ if response_format and self.model_type in {"gpt-4o", "gpt-4o-mini"}:
504
+ self.model_backend.model_config_dict = original_model_dict.copy()
505
+ self.model_backend.model_config_dict["response_format"] = (
506
+ response_format
507
+ )
508
+
502
509
  if isinstance(input_message, str):
503
510
  input_message = BaseMessage.make_user_message(
504
511
  role_name='User', content=input_message
@@ -632,6 +639,7 @@ class ChatAgent(BaseAgent):
632
639
  try:
633
640
  openai_messages, num_tokens = self.memory.get_context()
634
641
  except RuntimeError as e:
642
+ self.model_backend.model_config_dict = original_model_dict
635
643
  return self._step_token_exceed(
636
644
  e.args[1], tool_call_records, "max_tokens_exceeded"
637
645
  )
@@ -667,6 +675,8 @@ class ChatAgent(BaseAgent):
667
675
  num_tokens,
668
676
  tool_call_request,
669
677
  )
678
+
679
+ self.model_backend.model_config_dict = original_model_dict
670
680
  return ChatAgentResponse(
671
681
  msgs=output_messages,
672
682
  terminated=self.terminated,
@@ -681,6 +691,7 @@ class ChatAgent(BaseAgent):
681
691
  if (
682
692
  response_format is not None
683
693
  and self.model_type.support_native_tool_calling
694
+ and self.model_type not in {"gpt-4o", "gpt-4o-mini"}
684
695
  ):
685
696
  (
686
697
  output_messages,
@@ -711,6 +722,7 @@ class ChatAgent(BaseAgent):
711
722
  "to record the selected message manually."
712
723
  )
713
724
 
725
+ self.model_backend.model_config_dict = original_model_dict
714
726
  return ChatAgentResponse(
715
727
  msgs=output_messages, terminated=self.terminated, info=info
716
728
  )
@@ -930,7 +942,7 @@ class ChatAgent(BaseAgent):
930
942
  )
931
943
 
932
944
  for base_message_item in output_messages:
933
- base_message_item.content = str(tool_call_record.result)
945
+ base_message_item.content = json.dumps(tool_call_record.result)
934
946
 
935
947
  # Recover the original tools
936
948
  self.func_dict = original_func_dict
@@ -0,0 +1,18 @@
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
+ from .base import BaseBenchmark
16
+ from .gaia import DefaultGAIARetriever, GAIABenchmark
17
+
18
+ __all__ = ["BaseBenchmark", "GAIABenchmark", "DefaultGAIARetriever"]
@@ -0,0 +1,152 @@
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 logging
16
+ from abc import ABC, abstractmethod
17
+ from pathlib import Path
18
+ from typing import Any, Dict, List, Literal, Optional
19
+
20
+ from camel.agents import ChatAgent
21
+
22
+ logger = logging.getLogger(__name__)
23
+
24
+
25
+ class BaseBenchmark(ABC):
26
+ r"""Base class for benchmarks.
27
+
28
+ Attributes:
29
+ name (str): Name of the benchmark.
30
+ data_dir (str): Path to the data directory.
31
+ save_to (str): Path to save the results.
32
+ processes (int): Number of processes to use for parallel
33
+ processing. :(default: :obj:`1`)
34
+ """
35
+
36
+ def __init__(
37
+ self, name: str, data_dir: str, save_to: str, processes: int = 1
38
+ ):
39
+ r"""Initialize the benchmark.
40
+
41
+ Args:
42
+ name (str): Name of the benchmark.
43
+ data_dir (str): Path to the data directory.
44
+ save_to (str): Path to save the results.
45
+ processes (int): Number of processes to use for parallel
46
+ processing. :(default: :obj:`1`)
47
+
48
+ """
49
+ self.name = name
50
+ self.data_dir = Path(data_dir)
51
+ self.processes = processes
52
+ self.save_to = save_to
53
+ if not self.data_dir.exists():
54
+ logger.info(
55
+ f"Data directory {data_dir} does not exist. Creating it."
56
+ )
57
+ self.data_dir.mkdir(parents=True, exist_ok=True)
58
+ if not self.data_dir.is_dir():
59
+ raise NotADirectoryError(
60
+ f"Data directory {data_dir} is not a directory"
61
+ )
62
+ self._data: Dict[str, List[Dict[str, Any]]] = dict()
63
+ self._results: List[Dict[str, Any]] = []
64
+
65
+ @abstractmethod
66
+ def download(self) -> "BaseBenchmark":
67
+ r"""Download the benchmark data.
68
+
69
+ Returns:
70
+ BaseBenchmark: The benchmark instance.
71
+ """
72
+ pass
73
+
74
+ @abstractmethod
75
+ def load(self, force_download: bool = False) -> "BaseBenchmark":
76
+ r"""Load the benchmark data.
77
+
78
+ Args:
79
+ force_download (bool): Whether to force download the data.
80
+
81
+ Returns:
82
+ BaseBenchmark: The benchmark instance.
83
+ """
84
+ pass
85
+
86
+ @property
87
+ def train(self) -> List[Dict[str, Any]]:
88
+ r"""Get the training data.
89
+
90
+ Returns:
91
+ List[Dict[str, Any]]: The training data.
92
+ """
93
+ if not self._data:
94
+ logger.info("Data not loaded. Loading data.")
95
+ self.load()
96
+ return self._data["train"]
97
+
98
+ @property
99
+ def valid(self) -> List[Dict[str, Any]]:
100
+ r"""Get the validation data.
101
+
102
+ Returns:
103
+ List[Dict[str, Any]]: The validation data.
104
+ """
105
+ if not self._data:
106
+ logger.info("Data not loaded. Loading data.")
107
+ self.load()
108
+ return self._data["valid"]
109
+
110
+ @property
111
+ def test(self) -> List[Dict[str, Any]]:
112
+ r"""Get the test data.
113
+
114
+ Returns:
115
+ List[Dict[str, Any]]: The test data.
116
+ """
117
+ if not self._data:
118
+ logger.info("Data not loaded. Loading data.")
119
+ self.load()
120
+ return self._data["test"]
121
+
122
+ @abstractmethod
123
+ def run(
124
+ self,
125
+ agent: ChatAgent,
126
+ on: Literal["train", "valid", "test"],
127
+ randomize: bool = False,
128
+ subset: Optional[int] = None,
129
+ *args,
130
+ **kwargs,
131
+ ) -> "BaseBenchmark":
132
+ r"""Run the benchmark.
133
+
134
+ Args:
135
+ agent (ChatAgent): The chat agent.
136
+ on (str): The data split to run the benchmark on.
137
+ randomize (bool): Whether to randomize the data.
138
+ subset (int): The subset of the data to run the benchmark on.
139
+
140
+ Returns:
141
+ BaseBenchmark: The benchmark instance.
142
+ """
143
+ pass
144
+
145
+ @property
146
+ def results(self) -> List[Dict[str, Any]]:
147
+ r"""Get the results.
148
+
149
+ Returns:
150
+ List[Dict[str, Any]]: The results.
151
+ """
152
+ return self._results