camel-ai 0.2.21__py3-none-any.whl → 0.2.23a0__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/_types.py +41 -0
- camel/agents/_utils.py +188 -0
- camel/agents/chat_agent.py +556 -965
- camel/agents/knowledge_graph_agent.py +7 -1
- camel/agents/multi_hop_generator_agent.py +1 -1
- camel/configs/base_config.py +10 -13
- camel/configs/deepseek_config.py +4 -30
- camel/configs/gemini_config.py +5 -31
- camel/configs/openai_config.py +14 -32
- camel/configs/qwen_config.py +36 -36
- camel/datagen/self_improving_cot.py +79 -1
- camel/datagen/self_instruct/filter/instruction_filter.py +19 -3
- camel/datagen/self_instruct/self_instruct.py +7 -2
- camel/datasets/__init__.py +28 -0
- camel/datasets/base.py +969 -0
- camel/embeddings/openai_embedding.py +10 -1
- camel/environments/__init__.py +16 -0
- camel/environments/base.py +503 -0
- camel/extractors/__init__.py +16 -0
- camel/extractors/base.py +263 -0
- camel/interpreters/docker/Dockerfile +12 -0
- camel/interpreters/docker_interpreter.py +19 -1
- camel/interpreters/subprocess_interpreter.py +42 -17
- camel/loaders/__init__.py +2 -0
- camel/loaders/mineru_extractor.py +250 -0
- camel/memories/agent_memories.py +16 -1
- camel/memories/blocks/chat_history_block.py +10 -2
- camel/memories/blocks/vectordb_block.py +1 -0
- camel/memories/context_creators/score_based.py +20 -3
- camel/memories/records.py +10 -0
- camel/messages/base.py +8 -8
- camel/models/_utils.py +57 -0
- camel/models/aiml_model.py +48 -17
- camel/models/anthropic_model.py +41 -3
- camel/models/azure_openai_model.py +39 -3
- camel/models/base_model.py +132 -4
- camel/models/cohere_model.py +88 -11
- camel/models/deepseek_model.py +107 -63
- camel/models/gemini_model.py +133 -15
- camel/models/groq_model.py +72 -10
- camel/models/internlm_model.py +14 -3
- camel/models/litellm_model.py +9 -2
- camel/models/mistral_model.py +42 -5
- camel/models/model_manager.py +48 -3
- camel/models/moonshot_model.py +33 -4
- camel/models/nemotron_model.py +32 -3
- camel/models/nvidia_model.py +43 -3
- camel/models/ollama_model.py +139 -17
- camel/models/openai_audio_models.py +7 -1
- camel/models/openai_compatible_model.py +37 -3
- camel/models/openai_model.py +158 -46
- camel/models/qwen_model.py +61 -4
- camel/models/reka_model.py +53 -3
- camel/models/samba_model.py +209 -4
- camel/models/sglang_model.py +153 -14
- camel/models/siliconflow_model.py +16 -3
- camel/models/stub_model.py +46 -4
- camel/models/togetherai_model.py +38 -3
- camel/models/vllm_model.py +37 -3
- camel/models/yi_model.py +36 -3
- camel/models/zhipuai_model.py +38 -3
- camel/retrievers/__init__.py +3 -0
- camel/retrievers/hybrid_retrival.py +237 -0
- camel/toolkits/__init__.py +9 -2
- camel/toolkits/arxiv_toolkit.py +2 -1
- camel/toolkits/ask_news_toolkit.py +4 -2
- camel/toolkits/base.py +22 -3
- camel/toolkits/code_execution.py +2 -0
- camel/toolkits/dappier_toolkit.py +2 -1
- camel/toolkits/data_commons_toolkit.py +38 -12
- camel/toolkits/function_tool.py +13 -0
- camel/toolkits/github_toolkit.py +5 -1
- camel/toolkits/google_maps_toolkit.py +2 -1
- camel/toolkits/google_scholar_toolkit.py +2 -0
- camel/toolkits/human_toolkit.py +0 -3
- camel/toolkits/linkedin_toolkit.py +3 -2
- camel/toolkits/meshy_toolkit.py +3 -2
- camel/toolkits/mineru_toolkit.py +178 -0
- camel/toolkits/networkx_toolkit.py +240 -0
- camel/toolkits/notion_toolkit.py +2 -0
- camel/toolkits/openbb_toolkit.py +3 -2
- camel/toolkits/reddit_toolkit.py +11 -3
- camel/toolkits/retrieval_toolkit.py +6 -1
- camel/toolkits/semantic_scholar_toolkit.py +2 -1
- camel/toolkits/stripe_toolkit.py +8 -2
- camel/toolkits/sympy_toolkit.py +44 -1
- camel/toolkits/video_toolkit.py +2 -0
- camel/toolkits/whatsapp_toolkit.py +3 -2
- camel/toolkits/zapier_toolkit.py +191 -0
- camel/types/__init__.py +2 -2
- camel/types/agents/__init__.py +16 -0
- camel/types/agents/tool_calling_record.py +52 -0
- camel/types/enums.py +3 -0
- camel/types/openai_types.py +16 -14
- camel/utils/__init__.py +2 -1
- camel/utils/async_func.py +2 -2
- camel/utils/commons.py +114 -1
- camel/verifiers/__init__.py +23 -0
- camel/verifiers/base.py +340 -0
- camel/verifiers/models.py +82 -0
- camel/verifiers/python_verifier.py +202 -0
- {camel_ai-0.2.21.dist-info → camel_ai-0.2.23a0.dist-info}/METADATA +273 -256
- {camel_ai-0.2.21.dist-info → camel_ai-0.2.23a0.dist-info}/RECORD +106 -85
- {camel_ai-0.2.21.dist-info → camel_ai-0.2.23a0.dist-info}/WHEEL +1 -1
- {camel_ai-0.2.21.dist-info → camel_ai-0.2.23a0.dist-info}/LICENSE +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
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 asyncio
|
|
16
|
+
import os
|
|
17
|
+
import shutil
|
|
18
|
+
import subprocess
|
|
19
|
+
import tempfile
|
|
20
|
+
import venv
|
|
21
|
+
from typing import List, Optional
|
|
22
|
+
|
|
23
|
+
from camel.logger import get_logger
|
|
24
|
+
from camel.verifiers import BaseVerifier
|
|
25
|
+
|
|
26
|
+
from .models import VerificationOutcome, VerificationResult, VerifierInput
|
|
27
|
+
|
|
28
|
+
logger = get_logger(__name__)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class PythonVerifier(BaseVerifier):
|
|
32
|
+
r"""The PythonVerifier class verifies Python-based implementations
|
|
33
|
+
by executing them in an isolated virtual environment.
|
|
34
|
+
|
|
35
|
+
Features:
|
|
36
|
+
- Creates a virtual environment with a specified Python version.
|
|
37
|
+
- Installs required packages before executing the provided script.
|
|
38
|
+
- Executes the script and compares the output against a ground truth,
|
|
39
|
+
if supplied.
|
|
40
|
+
- Automatically cleans up the virtual environment after execution.
|
|
41
|
+
|
|
42
|
+
The verification process ensures that the code runs in a controlled
|
|
43
|
+
environment, minimizing external dependencies and conflicts.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(
|
|
47
|
+
self,
|
|
48
|
+
timeout: Optional[float] = 30.0,
|
|
49
|
+
required_packages: Optional[List[str]] = None,
|
|
50
|
+
):
|
|
51
|
+
r"""Initializes the PythonVerifier.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
timeout (Optional[float], optional): The execution timeout in
|
|
55
|
+
seconds. (default: :obj:`30.0`)
|
|
56
|
+
required_packages (Optional[List[str]], optional): A list of
|
|
57
|
+
packages to install in the virtual environment.
|
|
58
|
+
(default: :obj:`None`)
|
|
59
|
+
"""
|
|
60
|
+
# TODO: Use CAMEL's Interpreter to execute the code
|
|
61
|
+
super().__init__(timeout=timeout)
|
|
62
|
+
self.venv_path: Optional[str] = None
|
|
63
|
+
self.required_packages = required_packages or []
|
|
64
|
+
|
|
65
|
+
if os.name == 'nt': # Windows
|
|
66
|
+
self.bin_dir = 'Scripts'
|
|
67
|
+
else: # Unix-like systems
|
|
68
|
+
self.bin_dir = 'bin'
|
|
69
|
+
|
|
70
|
+
async def _setup(self) -> None:
|
|
71
|
+
r"""Set up a virtual environment for execution
|
|
72
|
+
and install required packages.
|
|
73
|
+
"""
|
|
74
|
+
self.venv_path = tempfile.mkdtemp()
|
|
75
|
+
venv.create(self.venv_path, with_pip=True)
|
|
76
|
+
logger.info(f"Virtual environment created at {self.venv_path}")
|
|
77
|
+
|
|
78
|
+
venv_pip = os.path.join(self.venv_path, self.bin_dir, "pip")
|
|
79
|
+
|
|
80
|
+
if self.required_packages:
|
|
81
|
+
try:
|
|
82
|
+
subprocess.run(
|
|
83
|
+
[venv_pip, "install", *self.required_packages],
|
|
84
|
+
check=True,
|
|
85
|
+
capture_output=True,
|
|
86
|
+
)
|
|
87
|
+
logger.info(
|
|
88
|
+
"Installed required packages:"
|
|
89
|
+
f"{', '.join(self.required_packages)}"
|
|
90
|
+
)
|
|
91
|
+
except subprocess.CalledProcessError as e:
|
|
92
|
+
logger.error(
|
|
93
|
+
"Failed to install required packages: "
|
|
94
|
+
f"{e.stderr.decode().strip()}"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
async def _cleanup(self) -> None:
|
|
98
|
+
r"""Clean up the virtual environment."""
|
|
99
|
+
if self.venv_path:
|
|
100
|
+
shutil.rmtree(self.venv_path)
|
|
101
|
+
logger.info(f"Virtual environment at {self.venv_path} removed")
|
|
102
|
+
self.venv_path = None
|
|
103
|
+
|
|
104
|
+
async def _verify_implementation(
|
|
105
|
+
self, result: VerifierInput
|
|
106
|
+
) -> VerificationResult:
|
|
107
|
+
r"""Executes the LLM-generated response in a Python virtual
|
|
108
|
+
environment.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
result (VerifierInput): Contains the LLM-generated Python code to
|
|
112
|
+
execute and optional ground truth for comparison.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
VerificationResult: Contains verification status (SUCCESS/FAILURE/
|
|
116
|
+
ERROR), execution output, error messages if any, and execution
|
|
117
|
+
duration.
|
|
118
|
+
|
|
119
|
+
Raises:
|
|
120
|
+
asyncio.TimeoutError: If execution exceeds the configured timeout.
|
|
121
|
+
Exception: Any unexpected errors during execution are caught and
|
|
122
|
+
converted to an ERROR verification result.
|
|
123
|
+
"""
|
|
124
|
+
if not self.venv_path:
|
|
125
|
+
return VerificationResult(
|
|
126
|
+
status=VerificationOutcome.ERROR,
|
|
127
|
+
result="",
|
|
128
|
+
error_message="Virtual environment is not set up.",
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
script = result.llm_response.strip()
|
|
132
|
+
venv_python = os.path.join(self.venv_path, self.bin_dir, "python")
|
|
133
|
+
|
|
134
|
+
if not os.path.exists(venv_python):
|
|
135
|
+
return VerificationResult(
|
|
136
|
+
status=VerificationOutcome.ERROR,
|
|
137
|
+
result="",
|
|
138
|
+
error_message="Python binary not found in virtual environment",
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
process = await asyncio.create_subprocess_exec(
|
|
143
|
+
venv_python,
|
|
144
|
+
"-c",
|
|
145
|
+
script,
|
|
146
|
+
stdout=asyncio.subprocess.PIPE,
|
|
147
|
+
stderr=asyncio.subprocess.PIPE,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
stdout, stderr = await asyncio.wait_for(
|
|
151
|
+
process.communicate(), timeout=self._timeout
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
output_result = stdout.decode().strip()
|
|
155
|
+
error_output = stderr.decode().strip()
|
|
156
|
+
|
|
157
|
+
if process.returncode == 0:
|
|
158
|
+
# If ground truth is provided, compare it with the result
|
|
159
|
+
if result.ground_truth is not None:
|
|
160
|
+
# Normalize both strings by removing extra whitespace
|
|
161
|
+
normalized_output = ' '.join(output_result.strip().split())
|
|
162
|
+
normalized_truth = ' '.join(
|
|
163
|
+
str(result.ground_truth).strip().split()
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
if normalized_output == normalized_truth:
|
|
167
|
+
return VerificationResult(
|
|
168
|
+
status=VerificationOutcome.SUCCESS,
|
|
169
|
+
result=output_result,
|
|
170
|
+
)
|
|
171
|
+
else:
|
|
172
|
+
return VerificationResult(
|
|
173
|
+
status=VerificationOutcome.FAILURE,
|
|
174
|
+
error_message="Output doesn't match ground truth",
|
|
175
|
+
result=output_result,
|
|
176
|
+
)
|
|
177
|
+
else:
|
|
178
|
+
return VerificationResult(
|
|
179
|
+
status=VerificationOutcome.SUCCESS,
|
|
180
|
+
result=output_result,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
else:
|
|
184
|
+
return VerificationResult(
|
|
185
|
+
status=VerificationOutcome.ERROR,
|
|
186
|
+
error_message=error_output,
|
|
187
|
+
result=output_result,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
except asyncio.TimeoutError:
|
|
191
|
+
return VerificationResult(
|
|
192
|
+
status=VerificationOutcome.TIMEOUT,
|
|
193
|
+
result="",
|
|
194
|
+
error_message="Execution timed out.",
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
except Exception as e:
|
|
198
|
+
return VerificationResult(
|
|
199
|
+
status=VerificationOutcome.ERROR,
|
|
200
|
+
result="",
|
|
201
|
+
error_message=f"Execution error: {e}",
|
|
202
|
+
)
|