Skip to content

Commit 9a48432

Browse files
authored
chore: Remove heavy & unnecessary dependencies (camel-ai#1651)
1 parent c483ea1 commit 9a48432

File tree

13 files changed

+1235
-3019
lines changed

13 files changed

+1235
-3019
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ body:
2626
attributes:
2727
label: What version of camel are you using?
2828
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
29-
placeholder: E.g., 0.2.22
29+
placeholder: E.g., 0.2.23a0
3030
validations:
3131
required: true
3232

camel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from camel.logger import disable_logging, enable_logging, set_log_level
1616

17-
__version__ = '0.2.22'
17+
__version__ = '0.2.23a0'
1818

1919
__all__ = [
2020
'__version__',

camel/models/sglang_model.py

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# limitations under the License.
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1414
import logging
15+
import subprocess
1516
import threading
1617
import time
1718
from typing import Any, Dict, List, Optional, Type, Union
@@ -94,11 +95,6 @@ def __init__(
9495
)
9596

9697
def _start_server(self) -> None:
97-
from sglang.utils import ( # type: ignore[import-untyped]
98-
execute_shell_command,
99-
wait_for_server,
100-
)
101-
10298
try:
10399
if not self._url:
104100
cmd = (
@@ -108,10 +104,10 @@ def _start_server(self) -> None:
108104
f"--host 0.0.0.0"
109105
)
110106

111-
server_process = execute_shell_command(cmd)
112-
wait_for_server("http://localhost:30000")
107+
server_process = _execute_shell_command(cmd)
108+
_wait_for_server("http://localhost:30000")
113109
self._url = "http://127.0.0.1:30000/v1"
114-
self.server_process = server_process
110+
self.server_process = server_process # type: ignore[assignment]
115111
# Start the inactivity monitor in a background thread
116112
self._inactivity_thread = threading.Thread(
117113
target=self._monitor_inactivity, daemon=True
@@ -138,8 +134,6 @@ def _monitor_inactivity(self):
138134
r"""Monitor whether the server process has been inactive for over 10
139135
minutes.
140136
"""
141-
from sglang.utils import terminate_process
142-
143137
while True:
144138
# Check every 10 seconds
145139
time.sleep(10)
@@ -150,7 +144,7 @@ def _monitor_inactivity(self):
150144
time.time() - self.last_run_time > 600
151145
):
152146
if self.server_process:
153-
terminate_process(self.server_process)
147+
_terminate_process(self.server_process)
154148
self.server_process = None
155149
self._client = None # Invalidate the client
156150
logging.info(
@@ -270,3 +264,101 @@ def stream(self) -> bool:
270264
bool: Whether the model is in stream mode.
271265
"""
272266
return self.model_config_dict.get('stream', False)
267+
268+
269+
# Below are helper functions from sglang.utils
270+
def _terminate_process(process):
271+
_kill_process_tree(process.pid)
272+
273+
274+
def _kill_process_tree(
275+
parent_pid, include_parent: bool = True, skip_pid: Optional[int] = None
276+
):
277+
r"""Kill the process and all its child processes."""
278+
import os
279+
import signal
280+
281+
import psutil
282+
283+
if parent_pid is None:
284+
parent_pid = os.getpid()
285+
include_parent = False
286+
287+
try:
288+
itself = psutil.Process(parent_pid)
289+
except psutil.NoSuchProcess:
290+
return
291+
292+
children = itself.children(recursive=True)
293+
for child in children:
294+
if child.pid == skip_pid:
295+
continue
296+
try:
297+
child.kill()
298+
except psutil.NoSuchProcess:
299+
pass
300+
301+
if include_parent:
302+
try:
303+
itself.kill()
304+
305+
# Sometime processes cannot be killed with SIGKILL
306+
# so we send an additional signal to kill them.
307+
itself.send_signal(signal.SIGQUIT)
308+
except psutil.NoSuchProcess:
309+
pass
310+
311+
312+
def _execute_shell_command(command: str) -> subprocess.Popen:
313+
r"""Execute a shell command and return the process handle
314+
315+
Args:
316+
command: Shell command as a string (can include \\ line continuations)
317+
Returns:
318+
subprocess.Popen: Process handle
319+
"""
320+
import subprocess
321+
322+
# Replace \ newline with space and split
323+
command = command.replace("\\\n", " ").replace("\\", " ")
324+
parts = command.split()
325+
326+
return subprocess.Popen(parts, text=True, stderr=subprocess.STDOUT)
327+
328+
329+
def _wait_for_server(base_url: str, timeout: Optional[int] = None) -> None:
330+
r"""Wait for the server to be ready by polling the /v1/models endpoint.
331+
332+
Args:
333+
base_url: The base URL of the server
334+
timeout: Maximum time to wait in seconds. None means wait forever.
335+
"""
336+
import requests
337+
338+
start_time = time.time()
339+
while True:
340+
try:
341+
response = requests.get(
342+
f"{base_url}/v1/models",
343+
headers={"Authorization": "Bearer None"},
344+
)
345+
if response.status_code == 200:
346+
time.sleep(5)
347+
print(
348+
"""\n
349+
NOTE: Typically, the server runs in a separate terminal.
350+
In this notebook, we run the server and notebook code
351+
together, so their outputs are combined.
352+
To improve clarity, the server logs are displayed in the
353+
original black color, while the notebook outputs are
354+
highlighted in blue.
355+
"""
356+
)
357+
break
358+
359+
if timeout and time.time() - start_time > timeout:
360+
raise TimeoutError(
361+
"Server did not become ready within timeout period"
362+
)
363+
except requests.exceptions.RequestException:
364+
time.sleep(1)

camel/toolkits/ask_news_toolkit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def __init__(self, timeout: Optional[float] = None):
6767
credentials are retrieved from environment variables.
6868
"""
6969
super().__init__(timeout=timeout)
70-
from asknews_sdk import AskNewsSDK
70+
71+
from asknews_sdk import AskNewsSDK # type: ignore[import-not-found]
7172

7273
client_id = os.environ.get("ASKNEWS_CLIENT_ID")
7374
client_secret = os.environ.get("ASKNEWS_CLIENT_SECRET")

camel/toolkits/openbb_toolkit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, timeout: Optional[float] = None) -> None:
4646
super().__init__(timeout=timeout)
4747
import os
4848

49-
from openbb import obb
49+
from openbb import obb # type: ignore[import-not-found]
5050

5151
self.client = obb
5252
# Initialize OpenBB Hub account with access token

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
project = 'CAMEL'
2828
copyright = '2024, CAMEL-AI.org'
2929
author = 'CAMEL-AI.org'
30-
release = '0.2.22'
30+
release = '0.2.23a0'
3131

3232
html_favicon = (
3333
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'

docs/get_started/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ conda create --name camel python=3.10
6060
conda activate camel
6161
6262
# Clone github repo
63-
git clone -b v0.2.22 https://github.com/camel-ai/camel.git
63+
git clone -b v0.2.23a0 https://github.com/camel-ai/camel.git
6464
6565
# Change directory into project directory
6666
cd camel

docs/key_modules/loaders.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ response = jina_reader.read_content("https://docs.camel-ai.org/")
340340
print(response)
341341
```
342342
```markdown
343-
>>>Welcome to CAMEL’s documentation! — CAMEL 0.2.22 documentation
343+
>>>Welcome to CAMEL’s documentation! — CAMEL 0.2.23a0 documentation
344344
===============
345345

346346
[Skip to main content](https://docs.camel-ai.org/#main-content)
347347

348348
Back to top Ctrl+K
349349

350-
[![Image 1](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png) ![Image 2](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png)CAMEL 0.2.22](https://docs.camel-ai.org/#)
350+
[![Image 1](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png) ![Image 2](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png)CAMEL 0.2.23a0](https://docs.camel-ai.org/#)
351351

352352
Search Ctrl+K
353353

0 commit comments

Comments
 (0)