camel-ai 0.2.60__py3-none-any.whl → 0.2.62__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 +159 -8
- camel/agents/mcp_agent.py +5 -5
- camel/configs/anthropic_config.py +6 -5
- camel/{data_collector → data_collectors}/alpaca_collector.py +1 -1
- camel/{data_collector → data_collectors}/sharegpt_collector.py +1 -1
- camel/datagen/evol_instruct/scorer.py +22 -23
- camel/datagen/evol_instruct/templates.py +46 -46
- camel/datasets/static_dataset.py +144 -0
- 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/models/model_manager.py +7 -3
- camel/retrievers/auto_retriever.py +20 -1
- camel/{runtime → runtimes}/daytona_runtime.py +1 -1
- camel/{runtime → runtimes}/docker_runtime.py +1 -1
- camel/{runtime → runtimes}/llm_guard_runtime.py +2 -2
- camel/{runtime → runtimes}/remote_http_runtime.py +1 -1
- camel/{runtime → runtimes}/ubuntu_docker_runtime.py +1 -1
- camel/societies/workforce/base.py +7 -3
- camel/societies/workforce/single_agent_worker.py +2 -1
- camel/societies/workforce/worker.py +5 -3
- 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/toolkits/__init__.py +4 -0
- camel/toolkits/async_browser_toolkit.py +75 -523
- camel/toolkits/bohrium_toolkit.py +318 -0
- camel/toolkits/browser_toolkit.py +215 -538
- camel/toolkits/browser_toolkit_commons.py +568 -0
- camel/toolkits/file_write_toolkit.py +80 -31
- camel/toolkits/mcp_toolkit.py +477 -665
- camel/toolkits/pptx_toolkit.py +777 -0
- camel/toolkits/wolfram_alpha_toolkit.py +5 -1
- camel/types/enums.py +13 -1
- camel/utils/__init__.py +2 -0
- camel/utils/commons.py +27 -0
- camel/utils/mcp_client.py +979 -0
- {camel_ai-0.2.60.dist-info → camel_ai-0.2.62.dist-info}/METADATA +14 -1
- {camel_ai-0.2.60.dist-info → camel_ai-0.2.62.dist-info}/RECORD +53 -47
- /camel/{data_collector → data_collectors}/__init__.py +0 -0
- /camel/{data_collector → data_collectors}/base.py +0 -0
- /camel/{runtime → runtimes}/__init__.py +0 -0
- /camel/{runtime → runtimes}/api.py +0 -0
- /camel/{runtime → runtimes}/base.py +0 -0
- /camel/{runtime → runtimes}/configs.py +0 -0
- /camel/{runtime → runtimes}/utils/__init__.py +0 -0
- /camel/{runtime → runtimes}/utils/function_risk_toolkit.py +0 -0
- /camel/{runtime → runtimes}/utils/ignore_risk_toolkit.py +0 -0
- {camel_ai-0.2.60.dist-info → camel_ai-0.2.62.dist-info}/WHEEL +0 -0
- {camel_ai-0.2.60.dist-info → camel_ai-0.2.62.dist-info}/licenses/LICENSE +0 -0
|
@@ -11,8 +11,6 @@
|
|
|
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
|
-
|
|
16
14
|
import re
|
|
17
15
|
from datetime import datetime
|
|
18
16
|
from pathlib import Path
|
|
@@ -21,7 +19,7 @@ from typing import List, Optional, Union
|
|
|
21
19
|
from camel.logger import get_logger
|
|
22
20
|
from camel.toolkits.base import BaseToolkit
|
|
23
21
|
from camel.toolkits.function_tool import FunctionTool
|
|
24
|
-
from camel.utils import MCPServer
|
|
22
|
+
from camel.utils import MCPServer, dependencies_required
|
|
25
23
|
|
|
26
24
|
logger = get_logger(__name__)
|
|
27
25
|
|
|
@@ -148,40 +146,83 @@ class FileWriteToolkit(BaseToolkit):
|
|
|
148
146
|
document.save(str(file_path))
|
|
149
147
|
logger.debug(f"Wrote DOCX to {file_path} with default formatting")
|
|
150
148
|
|
|
151
|
-
|
|
149
|
+
@dependencies_required('pylatex', 'fpdf')
|
|
150
|
+
def _write_pdf_file(
|
|
151
|
+
self, file_path: Path, content: str, use_latex: bool = False
|
|
152
|
+
) -> None:
|
|
152
153
|
r"""Write text content to a PDF file with default formatting.
|
|
153
154
|
|
|
154
155
|
Args:
|
|
155
156
|
file_path (Path): The target file path.
|
|
156
157
|
content (str): The text content to write.
|
|
158
|
+
use_latex (bool): Whether to use LaTeX for rendering. (requires
|
|
159
|
+
LaTeX toolchain). If False, uses FPDF for simpler PDF
|
|
160
|
+
generation. (default: :obj: `False`)
|
|
157
161
|
|
|
158
162
|
Raises:
|
|
159
|
-
RuntimeError: If the 'fpdf' library is not installed
|
|
163
|
+
RuntimeError: If the 'pylatex' or 'fpdf' library is not installed
|
|
164
|
+
when use_latex=True.
|
|
160
165
|
"""
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
pdf.set_margins(margin, margin, margin)
|
|
172
|
-
|
|
173
|
-
pdf.add_page()
|
|
174
|
-
pdf.set_font(font_family, style=font_style, size=font_size)
|
|
175
|
-
|
|
176
|
-
# Split content into paragraphs and add them
|
|
177
|
-
for para in content.split('\n'):
|
|
178
|
-
if para.strip(): # Skip empty paragraphs
|
|
179
|
-
pdf.multi_cell(0, line_height, para)
|
|
180
|
-
else:
|
|
181
|
-
pdf.ln(line_height) # Add empty line
|
|
166
|
+
if use_latex:
|
|
167
|
+
from pylatex import (
|
|
168
|
+
Command,
|
|
169
|
+
Document,
|
|
170
|
+
Math,
|
|
171
|
+
Section,
|
|
172
|
+
)
|
|
173
|
+
from pylatex.utils import (
|
|
174
|
+
NoEscape,
|
|
175
|
+
)
|
|
182
176
|
|
|
183
|
-
|
|
184
|
-
|
|
177
|
+
doc = Document(documentclass="article")
|
|
178
|
+
doc.packages.append(Command('usepackage', 'amsmath'))
|
|
179
|
+
|
|
180
|
+
with doc.create(Section('Generated Content')):
|
|
181
|
+
for line in content.split('\n'):
|
|
182
|
+
# Remove leading whitespace
|
|
183
|
+
stripped_line = line.strip()
|
|
184
|
+
# Check if the line is intended as a standalone math
|
|
185
|
+
# expression
|
|
186
|
+
if (
|
|
187
|
+
stripped_line.startswith('$')
|
|
188
|
+
and stripped_line.endswith('$')
|
|
189
|
+
and len(stripped_line) > 1
|
|
190
|
+
):
|
|
191
|
+
# Extract content between the '$' delimiters
|
|
192
|
+
math_data = stripped_line[1:-1]
|
|
193
|
+
doc.append(Math(data=math_data))
|
|
194
|
+
else:
|
|
195
|
+
doc.append(NoEscape(line))
|
|
196
|
+
doc.append(NoEscape(r'\par'))
|
|
197
|
+
|
|
198
|
+
doc.generate_pdf(str(file_path), clean_tex=False)
|
|
199
|
+
|
|
200
|
+
logger.info(f"Wrote PDF (with LaTeX) to {file_path}")
|
|
201
|
+
else:
|
|
202
|
+
from fpdf import FPDF
|
|
203
|
+
|
|
204
|
+
# Use default formatting values
|
|
205
|
+
font_family = 'Arial'
|
|
206
|
+
font_size = 12
|
|
207
|
+
font_style = ''
|
|
208
|
+
line_height = 10
|
|
209
|
+
margin = 10
|
|
210
|
+
|
|
211
|
+
pdf = FPDF()
|
|
212
|
+
pdf.set_margins(margin, margin, margin)
|
|
213
|
+
|
|
214
|
+
pdf.add_page()
|
|
215
|
+
pdf.set_font(font_family, style=font_style, size=font_size)
|
|
216
|
+
|
|
217
|
+
# Split content into paragraphs and add them
|
|
218
|
+
for para in content.split('\n'):
|
|
219
|
+
if para.strip(): # Skip empty paragraphs
|
|
220
|
+
pdf.multi_cell(0, line_height, para)
|
|
221
|
+
else:
|
|
222
|
+
pdf.ln(line_height) # Add empty line
|
|
223
|
+
|
|
224
|
+
pdf.output(str(file_path))
|
|
225
|
+
logger.debug(f"Wrote PDF to {file_path} with custom formatting")
|
|
185
226
|
|
|
186
227
|
def _write_csv_file(
|
|
187
228
|
self,
|
|
@@ -286,6 +327,7 @@ class FileWriteToolkit(BaseToolkit):
|
|
|
286
327
|
content: Union[str, List[List[str]]],
|
|
287
328
|
filename: str,
|
|
288
329
|
encoding: Optional[str] = None,
|
|
330
|
+
use_latex: bool = False,
|
|
289
331
|
) -> str:
|
|
290
332
|
r"""Write the given content to a file.
|
|
291
333
|
|
|
@@ -296,12 +338,17 @@ class FileWriteToolkit(BaseToolkit):
|
|
|
296
338
|
|
|
297
339
|
Args:
|
|
298
340
|
content (Union[str, List[List[str]]]): The content to write to the
|
|
299
|
-
file.
|
|
300
|
-
|
|
341
|
+
file. Content format varies by file type:
|
|
342
|
+
- Text formats (txt, md, html, yaml): string
|
|
343
|
+
- CSV: string or list of lists
|
|
344
|
+
- JSON: string or serializable object
|
|
301
345
|
filename (str): The name or path of the file. If a relative path is
|
|
302
346
|
supplied, it is resolved to self.output_dir.
|
|
303
347
|
encoding (Optional[str]): The character encoding to use. (default:
|
|
304
348
|
:obj: `None`)
|
|
349
|
+
use_latex (bool): For PDF files, whether to use LaTeX rendering
|
|
350
|
+
(True) or simple FPDF rendering (False). (default: :obj:
|
|
351
|
+
`False`)
|
|
305
352
|
|
|
306
353
|
Returns:
|
|
307
354
|
str: A message indicating success or error details.
|
|
@@ -326,7 +373,9 @@ class FileWriteToolkit(BaseToolkit):
|
|
|
326
373
|
if extension in [".doc", ".docx"]:
|
|
327
374
|
self._write_docx_file(file_path, str(content))
|
|
328
375
|
elif extension == ".pdf":
|
|
329
|
-
self._write_pdf_file(
|
|
376
|
+
self._write_pdf_file(
|
|
377
|
+
file_path, str(content), use_latex=use_latex
|
|
378
|
+
)
|
|
330
379
|
elif extension == ".csv":
|
|
331
380
|
self._write_csv_file(
|
|
332
381
|
file_path, content, encoding=file_encoding
|