camel-ai 0.1.6.1__py3-none-any.whl → 0.1.6.4__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 +8 -8
- camel/agents/critic_agent.py +8 -8
- camel/agents/deductive_reasoner_agent.py +7 -7
- camel/agents/embodied_agent.py +8 -8
- camel/agents/knowledge_graph_agent.py +8 -8
- camel/agents/role_assignment_agent.py +8 -8
- camel/agents/search_agent.py +8 -8
- camel/agents/task_agent.py +8 -8
- camel/configs/mistral_config.py +13 -9
- camel/embeddings/mistral_embedding.py +5 -5
- camel/interpreters/docker_interpreter.py +1 -1
- camel/loaders/__init__.py +1 -2
- camel/loaders/base_io.py +118 -52
- camel/loaders/jina_url_reader.py +6 -6
- camel/loaders/unstructured_io.py +24 -286
- camel/models/__init__.py +2 -0
- camel/models/mistral_model.py +120 -26
- camel/models/model_factory.py +3 -3
- camel/models/openai_compatibility_model.py +105 -0
- camel/retrievers/auto_retriever.py +25 -35
- camel/retrievers/vector_retriever.py +20 -18
- camel/storages/object_storages/__init__.py +22 -0
- camel/storages/object_storages/amazon_s3.py +205 -0
- camel/storages/object_storages/azure_blob.py +166 -0
- camel/storages/object_storages/base.py +115 -0
- camel/storages/object_storages/google_cloud.py +152 -0
- camel/toolkits/retrieval_toolkit.py +5 -5
- camel/toolkits/search_toolkit.py +4 -4
- camel/types/enums.py +7 -0
- camel/utils/__init__.py +2 -0
- camel/utils/commons.py +21 -6
- camel/utils/token_counting.py +7 -3
- {camel_ai-0.1.6.1.dist-info → camel_ai-0.1.6.4.dist-info}/METADATA +9 -5
- {camel_ai-0.1.6.1.dist-info → camel_ai-0.1.6.4.dist-info}/RECORD +36 -30
- {camel_ai-0.1.6.1.dist-info → camel_ai-0.1.6.4.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
+
import os
|
|
15
|
+
from pathlib import Path, PurePath
|
|
16
|
+
from typing import Optional, Tuple
|
|
17
|
+
from warnings import warn
|
|
18
|
+
|
|
19
|
+
from camel.loaders import File
|
|
20
|
+
from camel.storages.object_storages.base import BaseObjectStorage
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AzureBlobStorage(BaseObjectStorage):
|
|
24
|
+
r"""A class to connect to Azure Blob Storage. It will connect to one
|
|
25
|
+
container in the storage account.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
storage_account_name (str): The name of the storage account.
|
|
29
|
+
container_name (str): The name of the container.
|
|
30
|
+
access_key (Optional[str], optional): The access key of the storage
|
|
31
|
+
account. Defaults to None.
|
|
32
|
+
|
|
33
|
+
References:
|
|
34
|
+
https://azure.microsoft.com/en-us/products/storage/blobs
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
storage_account_name: str,
|
|
40
|
+
container_name: str,
|
|
41
|
+
create_if_not_exists: bool = True,
|
|
42
|
+
access_key: Optional[str] = None,
|
|
43
|
+
) -> None:
|
|
44
|
+
access_key = access_key or os.getenv("AZURE_ACCESS_KEY")
|
|
45
|
+
self._create_if_not_exists = create_if_not_exists
|
|
46
|
+
|
|
47
|
+
if not access_key:
|
|
48
|
+
warn("AZURE_ACCESS_KEY not provided.")
|
|
49
|
+
# Make all the empty values None
|
|
50
|
+
access_key = None
|
|
51
|
+
|
|
52
|
+
from azure.storage.blob import ContainerClient
|
|
53
|
+
|
|
54
|
+
self._client = ContainerClient(
|
|
55
|
+
account_url="https://"
|
|
56
|
+
f"{storage_account_name}.blob.core.windows.net",
|
|
57
|
+
credential=access_key,
|
|
58
|
+
container_name=container_name,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
self._prepare_and_check()
|
|
62
|
+
|
|
63
|
+
def _prepare_and_check(self) -> None:
|
|
64
|
+
r"""Check privileges and existence of the container."""
|
|
65
|
+
from azure.core.exceptions import ClientAuthenticationError
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
exists = self._client.exists()
|
|
69
|
+
if not exists and self._create_if_not_exists:
|
|
70
|
+
self._client.create_container()
|
|
71
|
+
warn(
|
|
72
|
+
f"Container {self._client.container_name} not found. "
|
|
73
|
+
f"Automatically created."
|
|
74
|
+
)
|
|
75
|
+
elif not exists:
|
|
76
|
+
raise FileNotFoundError(
|
|
77
|
+
f"Failed to access container {self._client.container_name}"
|
|
78
|
+
f": Not found."
|
|
79
|
+
)
|
|
80
|
+
except ClientAuthenticationError:
|
|
81
|
+
raise PermissionError(
|
|
82
|
+
f"Failed to access container {self._client.container_name}: "
|
|
83
|
+
f"No permission."
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
@staticmethod
|
|
87
|
+
def canonicalize_path(file_path: PurePath) -> Tuple[str, str]:
|
|
88
|
+
r"""Canonicalize file path for Azure Blob Storage.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
file_path (PurePath): The path to be canonicalized.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
Tuple[str, str]: The canonicalized file key and file name.
|
|
95
|
+
"""
|
|
96
|
+
# for Azure, both slash and backslash will be treated as separator
|
|
97
|
+
filename = file_path.name
|
|
98
|
+
if "\\" in filename:
|
|
99
|
+
raise ValueError(
|
|
100
|
+
"Azure Blob Storage does not support backslash in filename."
|
|
101
|
+
)
|
|
102
|
+
return file_path.as_posix(), filename
|
|
103
|
+
|
|
104
|
+
def _put_file(self, file_key: str, file: File) -> None:
|
|
105
|
+
r"""Put a file to the Azure Blob Storage container.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
file_key (str): The path to the object in the container.
|
|
109
|
+
file (File): The file to be uploaded.
|
|
110
|
+
"""
|
|
111
|
+
self._client.upload_blob(
|
|
112
|
+
name=file_key, data=file.raw_bytes, overwrite=True
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
def _get_file(self, file_key: str, filename: str) -> File:
|
|
116
|
+
r"""Get a file from the Azure Blob Storage container.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
file_key (str): The path to the object in the container.
|
|
120
|
+
filename (str): The name of the file.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
File: The object from the container.
|
|
124
|
+
"""
|
|
125
|
+
raw_bytes = self._client.download_blob(file_key).readall()
|
|
126
|
+
file = File.create_file_from_raw_bytes(raw_bytes, filename)
|
|
127
|
+
return file
|
|
128
|
+
|
|
129
|
+
def _upload_file(
|
|
130
|
+
self, local_file_path: Path, remote_file_key: str
|
|
131
|
+
) -> None:
|
|
132
|
+
r"""Upload a local file to the Azure Blob Storage container.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
local_file_path (Path): The path to the local file to be uploaded.
|
|
136
|
+
remote_file_key (str): The path to the object in the container.
|
|
137
|
+
"""
|
|
138
|
+
with open(local_file_path, "rb") as f:
|
|
139
|
+
self._client.upload_blob(
|
|
140
|
+
name=remote_file_key, data=f, overwrite=True
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def _download_file(
|
|
144
|
+
self, local_file_path: Path, remote_file_key: str
|
|
145
|
+
) -> None:
|
|
146
|
+
r"""Download a file from the Azure Blob Storage container to the local
|
|
147
|
+
system.
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
local_file_path (Path): The path to the local file to be saved.
|
|
151
|
+
remote_file_key (str): The key of the object in the container.
|
|
152
|
+
"""
|
|
153
|
+
with open(local_file_path, "wb") as f:
|
|
154
|
+
f.write(self._client.download_blob(remote_file_key).readall())
|
|
155
|
+
|
|
156
|
+
def _object_exists(self, file_key: str) -> bool:
|
|
157
|
+
r"""
|
|
158
|
+
Check if the object exists in the Azure Blob Storage container.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
file_key: The key of the object in the container.
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
bool: Whether the object exists in the container.
|
|
165
|
+
"""
|
|
166
|
+
return self._client.get_blob_client(file_key).exists()
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
+
|
|
15
|
+
from abc import ABC, abstractmethod
|
|
16
|
+
from pathlib import Path, PurePath
|
|
17
|
+
from typing import Tuple
|
|
18
|
+
|
|
19
|
+
from camel.loaders import File
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BaseObjectStorage(ABC):
|
|
23
|
+
def object_exists(self, file_path: PurePath) -> bool:
|
|
24
|
+
r"""Check if the object exists in the storage.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
file_path (PurePath): The path to the object in the storage.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
bool: True if the object exists, False otherwise.
|
|
31
|
+
"""
|
|
32
|
+
file_key, _ = self.canonicalize_path(file_path)
|
|
33
|
+
return self._object_exists(file_key)
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def canonicalize_path(file_path: PurePath) -> Tuple[str, str]:
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
def put_file(self, file_path: PurePath, file: File) -> None:
|
|
41
|
+
r"""Put a file to the object storage.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
file_path (PurePath): The path to the object in the storage.
|
|
45
|
+
file (File): The file to be put.
|
|
46
|
+
"""
|
|
47
|
+
file_key, _ = self.canonicalize_path(file_path)
|
|
48
|
+
self._put_file(file_key, file)
|
|
49
|
+
|
|
50
|
+
def get_file(self, file_path: PurePath) -> File:
|
|
51
|
+
r"""Get a file from the object storage.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
file_path (PurePath): The path to the object in the storage.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
File: The file object get from the storage.
|
|
58
|
+
"""
|
|
59
|
+
file_key, filename = self.canonicalize_path(file_path)
|
|
60
|
+
return self._get_file(file_key, filename)
|
|
61
|
+
|
|
62
|
+
def upload_file(
|
|
63
|
+
self, local_file_path: Path, remote_file_path: PurePath
|
|
64
|
+
) -> None:
|
|
65
|
+
r"""Upload a local file to the object storage.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
local_file_path (Path): The path to the local file to be uploaded.
|
|
69
|
+
remote_file_path (PurePath): The path to the object in storage.
|
|
70
|
+
"""
|
|
71
|
+
file_key, _ = self.canonicalize_path(remote_file_path)
|
|
72
|
+
# check if the local file exists
|
|
73
|
+
if not local_file_path.exists():
|
|
74
|
+
raise FileNotFoundError(
|
|
75
|
+
f"Local file {local_file_path} does not exist."
|
|
76
|
+
)
|
|
77
|
+
self._upload_file(local_file_path, file_key)
|
|
78
|
+
|
|
79
|
+
def download_file(
|
|
80
|
+
self, local_file_path: Path, remote_file_path: PurePath
|
|
81
|
+
) -> None:
|
|
82
|
+
r"""Download a file from the object storage to the local system.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
local_file_path (Path): The path to the local file to be saved.
|
|
86
|
+
remote_file_path (PurePath): The path to the object in storage.
|
|
87
|
+
"""
|
|
88
|
+
file_key, _ = self.canonicalize_path(remote_file_path)
|
|
89
|
+
self._download_file(local_file_path, file_key)
|
|
90
|
+
|
|
91
|
+
@abstractmethod
|
|
92
|
+
def _put_file(self, file_key: str, file: File) -> None:
|
|
93
|
+
pass
|
|
94
|
+
|
|
95
|
+
@abstractmethod
|
|
96
|
+
def _get_file(self, file_key: str, filename: str) -> File:
|
|
97
|
+
pass
|
|
98
|
+
|
|
99
|
+
@abstractmethod
|
|
100
|
+
def _object_exists(self, file_key: str) -> bool:
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
@abstractmethod
|
|
104
|
+
def _upload_file(
|
|
105
|
+
self, local_file_path: Path, remote_file_key: str
|
|
106
|
+
) -> None:
|
|
107
|
+
pass
|
|
108
|
+
|
|
109
|
+
@abstractmethod
|
|
110
|
+
def _download_file(
|
|
111
|
+
self,
|
|
112
|
+
local_file_path: Path,
|
|
113
|
+
remote_file_key: str,
|
|
114
|
+
) -> None:
|
|
115
|
+
pass
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
+
from pathlib import Path, PurePath
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from warnings import warn
|
|
17
|
+
|
|
18
|
+
from camel.loaders import File
|
|
19
|
+
from camel.storages.object_storages.base import BaseObjectStorage
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class GoogleCloudStorage(BaseObjectStorage):
|
|
23
|
+
r"""A class to connect to Google Cloud Storage. It will connect to one
|
|
24
|
+
bucket in the storage account.
|
|
25
|
+
|
|
26
|
+
Note that Google Cloud Storage does not support api key authentication.
|
|
27
|
+
Therefore, before using this class, you need to log in with gcloud command
|
|
28
|
+
line tool and save the credentials first.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
bucket_name (str): The name of the bucket.
|
|
32
|
+
create_if_not_exists (bool, optional): Whether to create the bucket if
|
|
33
|
+
it does not exist. Defaults to True.
|
|
34
|
+
anonymous (bool, optional): Whether to use anonymous access. Defaults
|
|
35
|
+
to False.
|
|
36
|
+
|
|
37
|
+
References:
|
|
38
|
+
https://cloud.google.com/storage
|
|
39
|
+
|
|
40
|
+
https://cloud.google.com/docs/authentication/api-keys
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
bucket_name: str,
|
|
46
|
+
create_if_not_exists: bool = True,
|
|
47
|
+
anonymous: bool = False,
|
|
48
|
+
) -> None:
|
|
49
|
+
from google.cloud import storage
|
|
50
|
+
|
|
51
|
+
self.create_if_not_exists = create_if_not_exists
|
|
52
|
+
|
|
53
|
+
if anonymous:
|
|
54
|
+
client = storage.Client.create_anonymous_client()
|
|
55
|
+
else:
|
|
56
|
+
client = storage.Client()
|
|
57
|
+
self._client = client.bucket(bucket_name)
|
|
58
|
+
|
|
59
|
+
self._prepare_and_check()
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def canonicalize_path(file_path: PurePath) -> Tuple[str, str]:
|
|
63
|
+
r"""Canonicalize the path for Google Cloud Storage.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
file_path (PurePath): The path to be canonicalized.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
Tuple[str, str]: The canonicalized file key and file name.
|
|
70
|
+
"""
|
|
71
|
+
return file_path.as_posix(), file_path.name
|
|
72
|
+
|
|
73
|
+
def _prepare_and_check(self) -> None:
|
|
74
|
+
r"""Check privileges and existence of the bucket."""
|
|
75
|
+
from google.auth.exceptions import InvalidOperation
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
exists = self._client.exists()
|
|
79
|
+
if not exists and self.create_if_not_exists:
|
|
80
|
+
self._client.create()
|
|
81
|
+
warn(
|
|
82
|
+
f"Bucket {self._client.name} not found. Automatically "
|
|
83
|
+
f"created."
|
|
84
|
+
)
|
|
85
|
+
elif not exists:
|
|
86
|
+
raise FileNotFoundError(
|
|
87
|
+
f"Failed to access bucket {self._client.name}: Not found."
|
|
88
|
+
)
|
|
89
|
+
except InvalidOperation:
|
|
90
|
+
raise PermissionError(
|
|
91
|
+
f"Failed to access bucket {self._client.name}: No permission."
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def _put_file(self, file_key: str, file: File) -> None:
|
|
95
|
+
r"""Put a file to the GCloud bucket.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
file_key (str): The path to the object in the bucket.
|
|
99
|
+
file (File): The file to be uploaded.
|
|
100
|
+
"""
|
|
101
|
+
self._client.blob(file_key).upload_from_string(file.raw_bytes)
|
|
102
|
+
|
|
103
|
+
def _get_file(self, file_key: str, filename: str) -> File:
|
|
104
|
+
r"""Get a file from the GCloud bucket.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
file_key (str): The path to the object in the bucket.
|
|
108
|
+
filename (str): The name of the file.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
File: The object from the S3 bucket.
|
|
112
|
+
"""
|
|
113
|
+
raw_bytes = self._client.get_blob(file_key).download_as_bytes()
|
|
114
|
+
return File.create_file_from_raw_bytes(raw_bytes, filename)
|
|
115
|
+
|
|
116
|
+
def _upload_file(
|
|
117
|
+
self, local_file_path: Path, remote_file_key: str
|
|
118
|
+
) -> None:
|
|
119
|
+
r"""Upload a local file to the GCloud bucket.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
local_file_path (Path): The path to the local file to be uploaded.
|
|
123
|
+
remote_file_key (str): The path to the object in the bucket.
|
|
124
|
+
"""
|
|
125
|
+
self._client.blob(remote_file_key).upload_from_filename(
|
|
126
|
+
local_file_path
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
def _download_file(
|
|
130
|
+
self, local_file_path: Path, remote_file_key: str
|
|
131
|
+
) -> None:
|
|
132
|
+
r"""Download a file from the GCloud bucket to the local system.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
local_file_path (Path): The path to the local file to be saved.
|
|
136
|
+
remote_file_key (str): The key of the object in the bucket.
|
|
137
|
+
"""
|
|
138
|
+
self._client.get_blob(remote_file_key).download_to_filename(
|
|
139
|
+
local_file_path
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def _object_exists(self, file_key: str) -> bool:
|
|
143
|
+
r"""
|
|
144
|
+
Check if the object exists in the GCloud bucket.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
file_key: The key of the object in the bucket.
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
bool: Whether the object exists in the bucket.
|
|
151
|
+
"""
|
|
152
|
+
return self._client.blob(file_key).exists()
|
|
@@ -27,7 +27,7 @@ class RetrievalToolkit(BaseToolkit):
|
|
|
27
27
|
"""
|
|
28
28
|
|
|
29
29
|
def information_retrieval(
|
|
30
|
-
self, query: str,
|
|
30
|
+
self, query: str, contents: Union[str, List[str]]
|
|
31
31
|
) -> str:
|
|
32
32
|
r"""Retrieves information from a local vector storage based on the
|
|
33
33
|
specified query. This function connects to a local vector storage
|
|
@@ -37,8 +37,8 @@ class RetrievalToolkit(BaseToolkit):
|
|
|
37
37
|
|
|
38
38
|
Args:
|
|
39
39
|
query (str): The question or query for which an answer is required.
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
contents (Union[str, List[str]]): Local file paths, remote URLs or
|
|
41
|
+
string contents.
|
|
42
42
|
|
|
43
43
|
Returns:
|
|
44
44
|
str: The information retrieved in response to the query, aggregated
|
|
@@ -47,7 +47,7 @@ class RetrievalToolkit(BaseToolkit):
|
|
|
47
47
|
Example:
|
|
48
48
|
# Retrieve information about CAMEL AI.
|
|
49
49
|
information_retrieval(query = "what is CAMEL AI?",
|
|
50
|
-
|
|
50
|
+
contents="https://www.camel-ai.org/")
|
|
51
51
|
"""
|
|
52
52
|
auto_retriever = AutoRetriever(
|
|
53
53
|
vector_storage_local_path="camel/temp_storage",
|
|
@@ -55,7 +55,7 @@ class RetrievalToolkit(BaseToolkit):
|
|
|
55
55
|
)
|
|
56
56
|
|
|
57
57
|
retrieved_info = auto_retriever.run_vector_retriever(
|
|
58
|
-
query=query,
|
|
58
|
+
query=query, contents=contents, top_k=3
|
|
59
59
|
)
|
|
60
60
|
return retrieved_info
|
|
61
61
|
|
camel/toolkits/search_toolkit.py
CHANGED
|
@@ -65,7 +65,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
65
65
|
return result
|
|
66
66
|
|
|
67
67
|
def search_duckduckgo(
|
|
68
|
-
self, query: str, source: str = "text", max_results: int =
|
|
68
|
+
self, query: str, source: str = "text", max_results: int = 5
|
|
69
69
|
) -> List[Dict[str, Any]]:
|
|
70
70
|
r"""Use DuckDuckGo search engine to search information for
|
|
71
71
|
the given query.
|
|
@@ -78,7 +78,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
78
78
|
query (str): The query to be searched.
|
|
79
79
|
source (str): The type of information to query (e.g., "text",
|
|
80
80
|
"images", "videos"). Defaults to "text".
|
|
81
|
-
max_results (int): Max number of results, defaults to `
|
|
81
|
+
max_results (int): Max number of results, defaults to `5`.
|
|
82
82
|
|
|
83
83
|
Returns:
|
|
84
84
|
List[Dict[str, Any]]: A list of dictionaries where each dictionary
|
|
@@ -152,7 +152,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
152
152
|
return responses
|
|
153
153
|
|
|
154
154
|
def search_google(
|
|
155
|
-
self, query: str, num_result_pages: int =
|
|
155
|
+
self, query: str, num_result_pages: int = 5
|
|
156
156
|
) -> List[Dict[str, Any]]:
|
|
157
157
|
r"""Use Google search engine to search information for the given query.
|
|
158
158
|
|
|
@@ -196,7 +196,7 @@ class SearchToolkit(BaseToolkit):
|
|
|
196
196
|
# Different language may get different result
|
|
197
197
|
search_language = "en"
|
|
198
198
|
# How many pages to return
|
|
199
|
-
num_result_pages =
|
|
199
|
+
num_result_pages = num_result_pages
|
|
200
200
|
# Constructing the URL
|
|
201
201
|
# Doc: https://developers.google.com/custom-search/v1/using_rest
|
|
202
202
|
url = (
|
camel/types/enums.py
CHANGED
|
@@ -448,6 +448,7 @@ class ModelPlatformType(Enum):
|
|
|
448
448
|
GEMINI = "gemini"
|
|
449
449
|
VLLM = "vllm"
|
|
450
450
|
MISTRAL = "mistral"
|
|
451
|
+
OPENAICOMPATIBILITYMODEL = "openai-compatibility-model"
|
|
451
452
|
|
|
452
453
|
@property
|
|
453
454
|
def is_openai(self) -> bool:
|
|
@@ -499,6 +500,12 @@ class ModelPlatformType(Enum):
|
|
|
499
500
|
r"""Returns whether this platform is opensource."""
|
|
500
501
|
return self is ModelPlatformType.OPENSOURCE
|
|
501
502
|
|
|
503
|
+
@property
|
|
504
|
+
def is_openai_compatibility_model(self) -> bool:
|
|
505
|
+
r"""Returns whether this is a platform supporting openai
|
|
506
|
+
compatibility"""
|
|
507
|
+
return self is ModelPlatformType.OPENAICOMPATIBILITYMODEL
|
|
508
|
+
|
|
502
509
|
@property
|
|
503
510
|
def is_gemini(self) -> bool:
|
|
504
511
|
r"""Returns whether this platform is Gemini."""
|
camel/utils/__init__.py
CHANGED
|
@@ -32,6 +32,7 @@ from .commons import (
|
|
|
32
32
|
print_text_animated,
|
|
33
33
|
text_extract_from_web,
|
|
34
34
|
to_pascal,
|
|
35
|
+
track_agent,
|
|
35
36
|
)
|
|
36
37
|
from .constants import Constants
|
|
37
38
|
from .token_counting import (
|
|
@@ -74,4 +75,5 @@ __all__ = [
|
|
|
74
75
|
'json_to_function_code',
|
|
75
76
|
'agentops_decorator',
|
|
76
77
|
'AgentOpsMeta',
|
|
78
|
+
'track_agent',
|
|
77
79
|
]
|
camel/utils/commons.py
CHANGED
|
@@ -488,8 +488,14 @@ def is_docker_running() -> bool:
|
|
|
488
488
|
|
|
489
489
|
|
|
490
490
|
try:
|
|
491
|
-
|
|
492
|
-
|
|
491
|
+
if os.getenv("AGENTOPS_API_KEY") is not None:
|
|
492
|
+
from agentops import (
|
|
493
|
+
ToolEvent,
|
|
494
|
+
record,
|
|
495
|
+
)
|
|
496
|
+
else:
|
|
497
|
+
raise ImportError
|
|
498
|
+
except (ImportError, AttributeError):
|
|
493
499
|
ToolEvent = None
|
|
494
500
|
|
|
495
501
|
|
|
@@ -528,7 +534,16 @@ class AgentOpsMeta(type):
|
|
|
528
534
|
"""
|
|
529
535
|
|
|
530
536
|
def __new__(cls, name, bases, dct):
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
537
|
+
if ToolEvent:
|
|
538
|
+
for attr, value in dct.items():
|
|
539
|
+
if callable(value) and attr != 'get_tools':
|
|
540
|
+
dct[attr] = agentops_decorator(value)
|
|
541
|
+
return super().__new__(cls, name, bases, dct)
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
# Mock trak agent decorator for AgentOps
|
|
545
|
+
def track_agent(*args, **kwargs):
|
|
546
|
+
def noop(f):
|
|
547
|
+
return f
|
|
548
|
+
|
|
549
|
+
return noop
|
camel/utils/token_counting.py
CHANGED
|
@@ -26,7 +26,9 @@ from PIL import Image
|
|
|
26
26
|
from camel.types import ModelType, OpenAIImageType, OpenAIVisionDetailType
|
|
27
27
|
|
|
28
28
|
if TYPE_CHECKING:
|
|
29
|
-
from mistral_common.protocol.instruct.request import
|
|
29
|
+
from mistral_common.protocol.instruct.request import ( # type:ignore[import-not-found]
|
|
30
|
+
ChatCompletionRequest,
|
|
31
|
+
)
|
|
30
32
|
|
|
31
33
|
from camel.messages import OpenAIMessage
|
|
32
34
|
|
|
@@ -517,7 +519,9 @@ class MistralTokenCounter(BaseTokenCounter):
|
|
|
517
519
|
model_type (ModelType): Model type for which tokens will be
|
|
518
520
|
counted.
|
|
519
521
|
"""
|
|
520
|
-
from mistral_common.tokens.tokenizers.mistral import
|
|
522
|
+
from mistral_common.tokens.tokenizers.mistral import ( # type:ignore[import-not-found]
|
|
523
|
+
MistralTokenizer,
|
|
524
|
+
)
|
|
521
525
|
|
|
522
526
|
self.model_type = model_type
|
|
523
527
|
|
|
@@ -565,7 +569,7 @@ class MistralTokenCounter(BaseTokenCounter):
|
|
|
565
569
|
"""
|
|
566
570
|
|
|
567
571
|
from mistral_common.protocol.instruct.request import (
|
|
568
|
-
ChatCompletionRequest,
|
|
572
|
+
ChatCompletionRequest, # type:ignore[import-not-found]
|
|
569
573
|
)
|
|
570
574
|
|
|
571
575
|
mistral_request = ChatCompletionRequest( # type: ignore[type-var]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: camel-ai
|
|
3
|
-
Version: 0.1.6.
|
|
3
|
+
Version: 0.1.6.4
|
|
4
4
|
Summary: Communicative Agents for AI Society Study
|
|
5
5
|
Home-page: https://www.camel-ai.org/
|
|
6
6
|
License: Apache-2.0
|
|
@@ -18,6 +18,7 @@ Provides-Extra: graph-storages
|
|
|
18
18
|
Provides-Extra: huggingface-agent
|
|
19
19
|
Provides-Extra: kv-stroages
|
|
20
20
|
Provides-Extra: model-platforms
|
|
21
|
+
Provides-Extra: object-storages
|
|
21
22
|
Provides-Extra: retrievers
|
|
22
23
|
Provides-Extra: test
|
|
23
24
|
Provides-Extra: tools
|
|
@@ -26,7 +27,9 @@ Requires-Dist: PyMuPDF (>=1.22.5,<2.0.0) ; extra == "tools" or extra == "all"
|
|
|
26
27
|
Requires-Dist: accelerate (>=0,<1) ; extra == "huggingface-agent" or extra == "all"
|
|
27
28
|
Requires-Dist: agentops (>=0.3.6,<0.4.0) ; extra == "tools" or extra == "all"
|
|
28
29
|
Requires-Dist: anthropic (>=0.29.0,<0.30.0)
|
|
30
|
+
Requires-Dist: azure-storage-blob (>=12.21.0,<13.0.0) ; extra == "object-storages" or extra == "all"
|
|
29
31
|
Requires-Dist: beautifulsoup4 (>=4,<5) ; extra == "tools" or extra == "all"
|
|
32
|
+
Requires-Dist: boto3 (>=1.34.149,<2.0.0) ; extra == "object-storages" or extra == "all"
|
|
30
33
|
Requires-Dist: cohere (>=4.56,<5.0) ; extra == "retrievers" or extra == "all"
|
|
31
34
|
Requires-Dist: colorama (>=0,<1)
|
|
32
35
|
Requires-Dist: curl_cffi (==0.6.2)
|
|
@@ -39,6 +42,7 @@ Requires-Dist: docx2txt (>=0.8,<0.9) ; extra == "tools" or extra == "all"
|
|
|
39
42
|
Requires-Dist: duckduckgo-search (>=6.1.0,<7.0.0) ; extra == "tools" or extra == "all"
|
|
40
43
|
Requires-Dist: eval-type-backport (==0.2.0)
|
|
41
44
|
Requires-Dist: firecrawl-py (>=0.0.20,<0.0.21) ; extra == "tools" or extra == "all"
|
|
45
|
+
Requires-Dist: google-cloud-storage (>=2.18.0,<3.0.0) ; extra == "object-storages" or extra == "all"
|
|
42
46
|
Requires-Dist: google-generativeai (>=0.6.0,<0.7.0) ; extra == "model-platforms" or extra == "all"
|
|
43
47
|
Requires-Dist: googlemaps (>=4.10.0,<5.0.0) ; extra == "tools" or extra == "all"
|
|
44
48
|
Requires-Dist: groq (>=0.5.0,<0.6.0)
|
|
@@ -47,11 +51,11 @@ Requires-Dist: ipykernel (>=6.0.0,<7.0.0)
|
|
|
47
51
|
Requires-Dist: jsonschema (>=4,<5)
|
|
48
52
|
Requires-Dist: jupyter_client (>=8.6.2,<9.0.0) ; extra == "tools" or extra == "all"
|
|
49
53
|
Requires-Dist: litellm (>=1.38.1,<2.0.0) ; extra == "model-platforms" or extra == "all"
|
|
50
|
-
Requires-Dist:
|
|
51
|
-
Requires-Dist: mistralai (>=0.4.2,<0.5.0) ; extra == "model-platforms" or extra == "all"
|
|
54
|
+
Requires-Dist: mistralai (>=1.0.0,<2.0.0) ; extra == "model-platforms" or extra == "all"
|
|
52
55
|
Requires-Dist: mock (>=5,<6) ; extra == "test"
|
|
53
56
|
Requires-Dist: neo4j (>=5.18.0,<6.0.0) ; extra == "graph-storages" or extra == "all"
|
|
54
57
|
Requires-Dist: newspaper3k (>=0.2.8,<0.3.0) ; extra == "tools" or extra == "all"
|
|
58
|
+
Requires-Dist: nltk (==3.8.1) ; extra == "tools" or extra == "all"
|
|
55
59
|
Requires-Dist: numpy (>=1,<2)
|
|
56
60
|
Requires-Dist: openai (>=1.2.3,<2.0.0)
|
|
57
61
|
Requires-Dist: openapi-spec-validator (>=0.7.1,<0.8.0) ; extra == "tools" or extra == "all"
|
|
@@ -79,7 +83,7 @@ Requires-Dist: soundfile (>=0,<1) ; extra == "huggingface-agent" or extra == "al
|
|
|
79
83
|
Requires-Dist: tiktoken (>=0.7.0,<0.8.0)
|
|
80
84
|
Requires-Dist: torch (>=2,<3) ; extra == "huggingface-agent" or extra == "all"
|
|
81
85
|
Requires-Dist: transformers (>=4,<5) ; extra == "huggingface-agent" or extra == "all"
|
|
82
|
-
Requires-Dist: unstructured[all-docs] (>=0.10
|
|
86
|
+
Requires-Dist: unstructured[all-docs] (>=0.10,<0.11) ; extra == "tools" or extra == "all"
|
|
83
87
|
Requires-Dist: wikipedia (>=1,<2) ; extra == "tools" or extra == "all"
|
|
84
88
|
Requires-Dist: wolframalpha (>=5.0.0,<6.0.0) ; extra == "tools" or extra == "all"
|
|
85
89
|
Project-URL: Documentation, https://docs.camel-ai.org
|
|
@@ -198,7 +202,7 @@ conda create --name camel python=3.9
|
|
|
198
202
|
conda activate camel
|
|
199
203
|
|
|
200
204
|
# Clone github repo
|
|
201
|
-
git clone -b v0.1.6.
|
|
205
|
+
git clone -b v0.1.6.4 https://github.com/camel-ai/camel.git
|
|
202
206
|
|
|
203
207
|
# Change directory into project directory
|
|
204
208
|
cd camel
|