camel-ai 0.2.59__py3-none-any.whl → 0.2.61__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.
- camel/__init__.py +1 -1
- camel/agents/chat_agent.py +158 -7
- camel/configs/anthropic_config.py +6 -5
- camel/configs/cohere_config.py +1 -1
- camel/configs/mistral_config.py +1 -1
- camel/configs/openai_config.py +3 -0
- camel/configs/reka_config.py +1 -1
- camel/configs/samba_config.py +2 -2
- camel/datagen/cot_datagen.py +29 -34
- camel/datagen/evol_instruct/scorer.py +22 -23
- camel/datagen/evol_instruct/templates.py +46 -46
- camel/datasets/static_dataset.py +144 -0
- camel/embeddings/jina_embedding.py +8 -1
- camel/embeddings/sentence_transformers_embeddings.py +2 -2
- camel/embeddings/vlm_embedding.py +9 -2
- camel/loaders/__init__.py +5 -2
- camel/loaders/chunkr_reader.py +117 -91
- camel/loaders/mistral_reader.py +148 -0
- camel/memories/blocks/chat_history_block.py +1 -2
- camel/memories/records.py +3 -0
- camel/messages/base.py +15 -3
- camel/models/azure_openai_model.py +1 -0
- camel/models/model_factory.py +2 -2
- camel/models/model_manager.py +7 -3
- camel/retrievers/bm25_retriever.py +1 -2
- camel/retrievers/hybrid_retrival.py +2 -2
- camel/societies/workforce/workforce.py +65 -24
- camel/storages/__init__.py +2 -0
- camel/storages/vectordb_storages/__init__.py +2 -0
- camel/storages/vectordb_storages/faiss.py +712 -0
- camel/storages/vectordb_storages/oceanbase.py +1 -2
- camel/toolkits/__init__.py +2 -0
- camel/toolkits/async_browser_toolkit.py +80 -524
- camel/toolkits/bohrium_toolkit.py +318 -0
- camel/toolkits/browser_toolkit.py +221 -541
- camel/toolkits/browser_toolkit_commons.py +568 -0
- camel/toolkits/dalle_toolkit.py +4 -0
- camel/toolkits/excel_toolkit.py +8 -2
- camel/toolkits/file_write_toolkit.py +76 -29
- camel/toolkits/github_toolkit.py +43 -25
- camel/toolkits/image_analysis_toolkit.py +3 -0
- camel/toolkits/jina_reranker_toolkit.py +194 -77
- camel/toolkits/mcp_toolkit.py +134 -16
- camel/toolkits/page_script.js +40 -28
- camel/toolkits/twitter_toolkit.py +6 -1
- camel/toolkits/video_analysis_toolkit.py +3 -0
- camel/toolkits/video_download_toolkit.py +3 -0
- camel/toolkits/wolfram_alpha_toolkit.py +51 -23
- camel/types/enums.py +27 -6
- camel/utils/__init__.py +2 -0
- camel/utils/commons.py +27 -0
- {camel_ai-0.2.59.dist-info → camel_ai-0.2.61.dist-info}/METADATA +17 -9
- {camel_ai-0.2.59.dist-info → camel_ai-0.2.61.dist-info}/RECORD +55 -51
- {camel_ai-0.2.59.dist-info → camel_ai-0.2.61.dist-info}/WHEEL +0 -0
- {camel_ai-0.2.59.dist-info → camel_ai-0.2.61.dist-info}/licenses/LICENSE +0 -0
camel/memories/records.py
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
|
|
15
|
+
# Enables postponed evaluation of annotations (for string-based type hints)
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
15
18
|
from dataclasses import asdict
|
|
16
19
|
from datetime import datetime, timezone
|
|
17
20
|
from typing import Any, ClassVar, Dict
|
camel/messages/base.py
CHANGED
|
@@ -11,13 +11,24 @@
|
|
|
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
|
+
|
|
15
|
+
# Enables postponed evaluation of annotations (for string-based type hints)
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
14
18
|
import base64
|
|
15
19
|
import io
|
|
16
20
|
import re
|
|
17
21
|
from dataclasses import dataclass
|
|
18
|
-
from typing import
|
|
22
|
+
from typing import (
|
|
23
|
+
Any,
|
|
24
|
+
Dict,
|
|
25
|
+
List,
|
|
26
|
+
Literal,
|
|
27
|
+
Optional,
|
|
28
|
+
Tuple,
|
|
29
|
+
Union,
|
|
30
|
+
)
|
|
19
31
|
|
|
20
|
-
import numpy as np
|
|
21
32
|
from PIL import Image
|
|
22
33
|
from pydantic import BaseModel
|
|
23
34
|
|
|
@@ -48,7 +59,7 @@ class BaseMessage:
|
|
|
48
59
|
role_name (str): The name of the user or assistant role.
|
|
49
60
|
role_type (RoleType): The type of role, either :obj:`RoleType.
|
|
50
61
|
ASSISTANT` or :obj:`RoleType.USER`.
|
|
51
|
-
meta_dict (Optional[Dict[str,
|
|
62
|
+
meta_dict (Optional[Dict[str, Any]]): Additional metadata dictionary
|
|
52
63
|
for the message.
|
|
53
64
|
content (str): The content of the message.
|
|
54
65
|
video_bytes (Optional[bytes]): Optional bytes of a video associated
|
|
@@ -457,6 +468,7 @@ class BaseMessage:
|
|
|
457
468
|
|
|
458
469
|
if self.video_bytes:
|
|
459
470
|
import imageio.v3 as iio
|
|
471
|
+
import numpy as np
|
|
460
472
|
|
|
461
473
|
base64Frames: List[str] = []
|
|
462
474
|
frame_count = 0
|
camel/models/model_factory.py
CHANGED
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
import json
|
|
15
15
|
from typing import ClassVar, Dict, Optional, Type, Union
|
|
16
16
|
|
|
17
|
-
import yaml
|
|
18
|
-
|
|
19
17
|
from camel.models.aiml_model import AIMLModel
|
|
20
18
|
from camel.models.anthropic_model import AnthropicModel
|
|
21
19
|
from camel.models.aws_bedrock_model import AWSBedrockModel
|
|
@@ -221,6 +219,8 @@ class ModelFactory:
|
|
|
221
219
|
|
|
222
220
|
@classmethod
|
|
223
221
|
def __load_yaml(cls, filepath: str) -> Dict:
|
|
222
|
+
import yaml
|
|
223
|
+
|
|
224
224
|
r"""Loads and parses a YAML file into a dictionary.
|
|
225
225
|
|
|
226
226
|
Args:
|
camel/models/model_manager.py
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
|
|
15
|
+
import asyncio
|
|
15
16
|
import logging
|
|
16
17
|
from itertools import cycle
|
|
17
18
|
from random import choice
|
|
@@ -69,6 +70,7 @@ class ModelManager:
|
|
|
69
70
|
self.models = [models]
|
|
70
71
|
self.models_cycle = cycle(self.models)
|
|
71
72
|
self.current_model = self.models[0]
|
|
73
|
+
self.lock = asyncio.Lock()
|
|
72
74
|
|
|
73
75
|
# Set the scheduling strategy; default is round-robin
|
|
74
76
|
try:
|
|
@@ -246,7 +248,8 @@ class ModelManager:
|
|
|
246
248
|
`ChatCompletion` in the non-stream mode, or
|
|
247
249
|
`AsyncStream[ChatCompletionChunk]` in the stream mode.
|
|
248
250
|
"""
|
|
249
|
-
|
|
251
|
+
async with self.lock:
|
|
252
|
+
self.current_model = self.scheduling_strategy()
|
|
250
253
|
|
|
251
254
|
# Pass all messages to the selected model and get the response
|
|
252
255
|
try:
|
|
@@ -260,7 +263,8 @@ class ModelManager:
|
|
|
260
263
|
logger.warning(
|
|
261
264
|
"The scheduling strategy has been changed to 'round_robin'"
|
|
262
265
|
)
|
|
263
|
-
|
|
264
|
-
|
|
266
|
+
async with self.lock:
|
|
267
|
+
# Skip already used one
|
|
268
|
+
self.current_model = self.scheduling_strategy()
|
|
265
269
|
raise exc
|
|
266
270
|
return response
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
from typing import Any, Dict, List
|
|
15
15
|
|
|
16
|
-
import numpy as np
|
|
17
|
-
|
|
18
16
|
from camel.loaders import UnstructuredIO
|
|
19
17
|
from camel.retrievers import BaseRetriever
|
|
20
18
|
from camel.utils import dependencies_required
|
|
@@ -106,6 +104,7 @@ class BM25Retriever(BaseRetriever):
|
|
|
106
104
|
model has not been initialized by calling `process`
|
|
107
105
|
first.
|
|
108
106
|
"""
|
|
107
|
+
import numpy as np
|
|
109
108
|
|
|
110
109
|
if top_k <= 0:
|
|
111
110
|
raise ValueError("top_k must be a positive integer.")
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
from typing import Any, Collection, Dict, List, Optional, Sequence, Union
|
|
15
15
|
|
|
16
|
-
import numpy as np
|
|
17
|
-
|
|
18
16
|
from camel.embeddings import BaseEmbedding
|
|
19
17
|
from camel.retrievers import BaseRetriever, BM25Retriever, VectorRetriever
|
|
20
18
|
from camel.storages import BaseVectorStorage
|
|
@@ -96,6 +94,8 @@ class HybridRetriever(BaseRetriever):
|
|
|
96
94
|
https://medium.com/@devalshah1619/mathematical-intuition-behind-reciprocal-rank-fusion-rrf-explained-in-2-mins-002df0cc5e2a
|
|
97
95
|
https://colab.research.google.com/drive/1iwVJrN96fiyycxN1pBqWlEr_4EPiGdGy#scrollTo=0qh83qGV2dY8
|
|
98
96
|
"""
|
|
97
|
+
import numpy as np
|
|
98
|
+
|
|
99
99
|
text_to_id = {}
|
|
100
100
|
id_to_info = {}
|
|
101
101
|
current_id = 1
|
|
@@ -48,29 +48,58 @@ logger = get_logger(__name__)
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
class Workforce(BaseNode):
|
|
51
|
-
r"""A system where multiple
|
|
52
|
-
to solve tasks. It can assign tasks to
|
|
51
|
+
r"""A system where multiple worker nodes (agents) cooperate together
|
|
52
|
+
to solve tasks. It can assign tasks to worker nodes and also take
|
|
53
53
|
strategies such as create new worker, decompose tasks, etc. to handle
|
|
54
54
|
situations when the task fails.
|
|
55
55
|
|
|
56
|
+
The workforce uses three specialized ChatAgents internally:
|
|
57
|
+
- Coordinator Agent: Assigns tasks to workers based on their
|
|
58
|
+
capabilities
|
|
59
|
+
- Task Planner Agent: Decomposes complex tasks and composes results
|
|
60
|
+
- Dynamic Workers: Created at runtime when tasks fail repeatedly
|
|
61
|
+
|
|
56
62
|
Args:
|
|
57
|
-
description (str): Description of the
|
|
63
|
+
description (str): Description of the workforce.
|
|
58
64
|
children (Optional[List[BaseNode]], optional): List of child nodes
|
|
59
65
|
under this node. Each child node can be a worker node or
|
|
60
66
|
another workforce node. (default: :obj:`None`)
|
|
61
67
|
coordinator_agent_kwargs (Optional[Dict], optional): Keyword
|
|
62
|
-
arguments
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
(default: :obj:`None`
|
|
68
|
+
arguments passed directly to the coordinator :obj:`ChatAgent`
|
|
69
|
+
constructor. The coordinator manages task assignment and failure
|
|
70
|
+
handling strategies. See :obj:`ChatAgent` documentation
|
|
71
|
+
for all available parameters.
|
|
72
|
+
(default: :obj:`None` - uses ModelPlatformType.DEFAULT,
|
|
73
|
+
ModelType.DEFAULT)
|
|
74
|
+
task_agent_kwargs (Optional[Dict], optional): Keyword arguments
|
|
75
|
+
passed directly to the task planning :obj:`ChatAgent` constructor.
|
|
76
|
+
The task agent handles task decomposition into subtasks and result
|
|
77
|
+
composition. See :obj:`ChatAgent` documentation for all
|
|
78
|
+
available parameters.
|
|
79
|
+
(default: :obj:`None` - uses ModelPlatformType.DEFAULT,
|
|
80
|
+
ModelType.DEFAULT)
|
|
81
|
+
new_worker_agent_kwargs (Optional[Dict], optional): Default keyword
|
|
82
|
+
arguments passed to :obj:`ChatAgent` constructor for workers
|
|
83
|
+
created dynamically at runtime when existing workers cannot handle
|
|
84
|
+
failed tasks. See :obj:`ChatAgent` documentation for all
|
|
85
|
+
available parameters.
|
|
86
|
+
(default: :obj:`None` - creates workers with SearchToolkit,
|
|
87
|
+
CodeExecutionToolkit, and ThinkingToolkit)
|
|
88
|
+
|
|
89
|
+
Example:
|
|
90
|
+
>>> # Configure with custom model
|
|
91
|
+
>>> model = ModelFactory.create(
|
|
92
|
+
... ModelPlatformType.OPENAI, ModelType.GPT_4O
|
|
93
|
+
... )
|
|
94
|
+
>>> workforce = Workforce(
|
|
95
|
+
... "Research Team",
|
|
96
|
+
... coordinator_agent_kwargs={"model": model, "token_limit": 4000},
|
|
97
|
+
... task_agent_kwargs={"model": model, "token_limit": 8000}
|
|
98
|
+
... )
|
|
99
|
+
>>>
|
|
100
|
+
>>> # Process a task
|
|
101
|
+
>>> task = Task(content="Research AI trends", id="1")
|
|
102
|
+
>>> result = workforce.process_task(task)
|
|
74
103
|
"""
|
|
75
104
|
|
|
76
105
|
def __init__(
|
|
@@ -89,21 +118,33 @@ class Workforce(BaseNode):
|
|
|
89
118
|
# Warning messages for default model usage
|
|
90
119
|
if coordinator_agent_kwargs is None:
|
|
91
120
|
logger.warning(
|
|
92
|
-
"No coordinator_agent_kwargs provided. "
|
|
93
|
-
"
|
|
94
|
-
"
|
|
121
|
+
"No coordinator_agent_kwargs provided. Using default "
|
|
122
|
+
"ChatAgent settings (ModelPlatformType.DEFAULT, "
|
|
123
|
+
"ModelType.DEFAULT). To customize the coordinator agent "
|
|
124
|
+
"that assigns tasks and handles failures, pass a dictionary "
|
|
125
|
+
"with ChatAgent parameters, e.g.: {'model': your_model, "
|
|
126
|
+
"'tools': your_tools, 'token_limit': 8000}. See ChatAgent "
|
|
127
|
+
"documentation for all available options."
|
|
95
128
|
)
|
|
96
129
|
if task_agent_kwargs is None:
|
|
97
130
|
logger.warning(
|
|
98
|
-
"No task_agent_kwargs provided. "
|
|
99
|
-
"
|
|
100
|
-
"
|
|
131
|
+
"No task_agent_kwargs provided. Using default ChatAgent "
|
|
132
|
+
"settings (ModelPlatformType.DEFAULT, ModelType.DEFAULT). "
|
|
133
|
+
"To customize the task planning agent that "
|
|
134
|
+
"decomposes/composes tasks, pass a dictionary with "
|
|
135
|
+
"ChatAgent parameters, e.g.: {'model': your_model, "
|
|
136
|
+
"'token_limit': 16000}. See ChatAgent documentation for "
|
|
137
|
+
"all available options."
|
|
101
138
|
)
|
|
102
139
|
if new_worker_agent_kwargs is None:
|
|
103
140
|
logger.warning(
|
|
104
|
-
"No new_worker_agent_kwargs provided. "
|
|
105
|
-
"
|
|
106
|
-
"
|
|
141
|
+
"No new_worker_agent_kwargs provided. Workers created at "
|
|
142
|
+
"runtime will use default ChatAgent settings with "
|
|
143
|
+
"SearchToolkit, CodeExecutionToolkit, and ThinkingToolkit. "
|
|
144
|
+
"To customize runtime worker creation, pass a dictionary "
|
|
145
|
+
"with ChatAgent parameters, e.g.: {'model': your_model, "
|
|
146
|
+
"'tools': your_tools}. See ChatAgent documentation for all "
|
|
147
|
+
"available options."
|
|
107
148
|
)
|
|
108
149
|
|
|
109
150
|
coord_agent_sys_msg = BaseMessage.make_assistant_message(
|
camel/storages/__init__.py
CHANGED
|
@@ -26,6 +26,7 @@ from .vectordb_storages.base import (
|
|
|
26
26
|
VectorDBQueryResult,
|
|
27
27
|
VectorRecord,
|
|
28
28
|
)
|
|
29
|
+
from .vectordb_storages.faiss import FaissStorage
|
|
29
30
|
from .vectordb_storages.milvus import MilvusStorage
|
|
30
31
|
from .vectordb_storages.oceanbase import OceanBaseStorage
|
|
31
32
|
from .vectordb_storages.qdrant import QdrantStorage
|
|
@@ -43,6 +44,7 @@ __all__ = [
|
|
|
43
44
|
'QdrantStorage',
|
|
44
45
|
'MilvusStorage',
|
|
45
46
|
"TiDBStorage",
|
|
47
|
+
"FaissStorage",
|
|
46
48
|
'BaseGraphStorage',
|
|
47
49
|
'Neo4jGraph',
|
|
48
50
|
'NebulaGraph',
|
|
@@ -19,6 +19,7 @@ from .base import (
|
|
|
19
19
|
VectorDBStatus,
|
|
20
20
|
VectorRecord,
|
|
21
21
|
)
|
|
22
|
+
from .faiss import FaissStorage
|
|
22
23
|
from .milvus import MilvusStorage
|
|
23
24
|
from .oceanbase import OceanBaseStorage
|
|
24
25
|
from .qdrant import QdrantStorage
|
|
@@ -31,6 +32,7 @@ __all__ = [
|
|
|
31
32
|
'QdrantStorage',
|
|
32
33
|
'MilvusStorage',
|
|
33
34
|
"TiDBStorage",
|
|
35
|
+
'FaissStorage',
|
|
34
36
|
'OceanBaseStorage',
|
|
35
37
|
'VectorRecord',
|
|
36
38
|
'VectorDBStatus',
|