Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

feat: Bohrium integrate (#2409)

Tao Sun753116d61dd7
diff --git a/.env b/.env
index c4908c3a3..5cfd49d21 100644
--- a/.env
+++ b/.env
@@ -116,3 +116,6 @@
# ACI API (https://platform.aci.dev/)
# ACI_API_KEY="Fill your API key here"
# LINKED_ACCOUNT_OWNER="Fill your Linked Account Owner here"
+
+#Bohrium API(https://www.bohrium.com/settings/user)
+#BOHRIUM_API_KEY="Fill your API key here"
\ No newline at end of file
diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.yml
index 4f71c02e2..f9bd979e4 100644
--- a/.github/workflows/build_package.yml
+++ b/.github/workflows/build_package.yml
@@ -137,6 +137,7 @@ jobs:
WATSONX_API_KEY: "${{ secrets.WATSONX_API_KEY }}"
WATSONX_PROJECT_ID: "${{ secrets.WATSONX_PROJECT_ID }}"
ACI_API_KEY: "${{ secrets.ACI_API_KEY }}"
+ BOHRIUM_API_KEY: "${{ secrets.BOHRIUM_API_KEY }}"
run: |
source test_venv/bin/activate
pytest --fast-test-mode ./test
diff --git a/.github/workflows/pytest_package.yml b/.github/workflows/pytest_package.yml
index 8f4cffd52..dfe2ffeee 100644
--- a/.github/workflows/pytest_package.yml
+++ b/.github/workflows/pytest_package.yml
@@ -76,6 +76,7 @@ jobs:
WATSONX_API_KEY: "${{ secrets.WATSONX_API_KEY }}"
WATSONX_PROJECT_ID: "${{ secrets.WATSONX_PROJECT_ID }}"
ACI_API_KEY: "${{ secrets.ACI_API_KEY }}"
+ BOHRIUM_API_KEY: "${{ secrets.BOHRIUM_API_KEY }}"
run: |
source .venv/bin/activate
uv pip install -e ".[all, dev, docs]"
@@ -144,6 +145,7 @@ jobs:
WATSONX_API_KEY: "${{ secrets.WATSONX_API_KEY }}"
WATSONX_PROJECT_ID: "${{ secrets.WATSONX_PROJECT_ID }}"
ACI_API_KEY: "${{ secrets.ACI_API_KEY }}"
+ BOHRIUM_API_KEY: "${{ secrets.BOHRIUM_API_KEY }}"
run: |
source .venv/bin/activate
uv pip install -e ".[all, dev, docs]"
@@ -210,6 +212,7 @@ jobs:
WATSONX_API_KEY: "${{ secrets.WATSONX_API_KEY }}"
WATSONX_PROJECT_ID: "${{ secrets.WATSONX_PROJECT_ID }}"
ACI_API_KEY: "${{ secrets.ACI_API_KEY }}"
+ BOHRIUM_API_KEY: "${{ secrets.BOHRIUM_API_KEY }}"
run: |
source .venv/bin/activate
uv pip install -e ".[all, dev, docs]"
diff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.py
index cc266714f..5f93be23b 100644
--- a/camel/toolkits/__init__.py
+++ b/camel/toolkits/__init__.py
@@ -29,6 +29,7 @@ from .linkedin_toolkit import LinkedInToolkit
from .reddit_toolkit import RedditToolkit
from .meshy_toolkit import MeshyToolkit
from .openbb_toolkit import OpenBBToolkit
+from .bohrium_toolkit import BohriumToolkit
from .base import BaseToolkit
from .google_maps_toolkit import GoogleMapsToolkit
@@ -136,4 +137,5 @@ __all__ = [
'ACIToolkit',
'PlaywrightMCPToolkit',
'WolframAlphaToolkit',
+ 'BohriumToolkit',
]
diff --git a/camel/toolkits/bohrium_toolkit.py b/camel/toolkits/bohrium_toolkit.py
new file mode 100644
index 000000000..895ae8a29
--- /dev/null
+++ b/camel/toolkits/bohrium_toolkit.py
@@ -0,0 +1,301 @@
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+import os
+from typing import Any, Dict, List, Optional
+
+try:
+ import yaml
+
+ HAS_YAML = True
+except ImportError:
+ HAS_YAML = False
+
+from camel.logger import get_logger
+from camel.toolkits.base import BaseToolkit
+from camel.toolkits.function_tool import FunctionTool
+from camel.utils import MCPServer, api_keys_required, dependencies_required
+
+logger = get_logger(__name__)
+
+
+@MCPServer()
+class BohriumToolkit(BaseToolkit):
+ r"""A class representing a toolkit for interacting with Bohrium services.
+
+ Args:
+ timeout (Optional[float], optional): The timeout for BohriumToolkit.
+ (default: :obj:`None`)
+ api_key (Optional[str], optional): The API key for Bohrium client.
+ (default: :obj:`None`)
+ project_id (Optional[int], optional): The project ID for Bohrium
+ client. (default: :obj:`None`)
+ yaml_path (Optional[str], optional): The path to the YAML file
+ containing the job parameters. (default: :obj:`None`)
+ """
+
+ @dependencies_required("bohrium")
+ @api_keys_required(
+ [
+ ("api_key", "BOHRIUM_API_KEY"),
+ ]
+ )
+ def __init__(
+ self,
+ timeout: Optional[float] = None,
+ api_key: Optional[str] = None,
+ project_id: Optional[int] = None,
+ yaml_path: Optional[str] = None,
+ ):
+ super().__init__(timeout=timeout)
+
+ from bohrium._client import Bohrium
+ from bohrium.resources import Job
+
+ api_key = api_key or os.environ.get("BOHRIUM_API_KEY")
+ self._client = Bohrium(access_key=api_key, project_id=project_id)
+ self._job = Job(self._client)
+ self._project_id = project_id
+ self._yaml_path = yaml_path
+
+ # refactor insert method
+ self._job.insert = self._custom_insert
+
+ def _custom_insert(self, data):
+ r"""refactor insert method, ensure return jobId information"""
+
+ response = self._client.post("/openapi/v2/job/add", json=data)
+ result = response.json()
+
+ return result
+
+ def submit_job(
+ self,
+ job_name: str = "bohr-job",
+ machine_type: str = "c2_m4_cpu",
+ cmd: str = "mpirun -n 2 lmp_mpi -i in.shear",
+ image_address: str = "registry.dp.tech/dptech/lammps:29Sep2021",
+ ) -> Dict[str, Any]:
+ r"""Submit a job to Bohrium.
+
+ Args:
+ job_name (str): The name of the job. It will be updated when yaml
+ file is provided. The yaml file might be set when initialize
+ BohriumToolkit.
+ (default: :obj:`bohr-job`)
+ machine_type (str): The type of machine to use. It will be updated
+ when yaml file is provided. The yaml file might be set when
+ initialize BohriumToolkit.
+ (default: :obj:`c2_m4_cpu`)
+ cmd (str): The command to run. It will be updated when yaml file
+ is provided. The yaml file might be set when initialize
+ (default: :obj:`mpirun -n 2 lmp_mpi -i in.shear`)
+ image_address (str): The address of the image to use. It will be
+ updated when yaml file is provided. The yaml file might be set
+ when initialize BohriumToolkit.
+ (default: :obj:`registry.dp.tech/dptech/lammps:29Sep2021`)
+
+ Returns:
+ Dict[str, Any]: The result of the job submission.
+ """
+ # Initialize params with default values
+ params: Dict[str, Any] = {
+ "project_id": self._project_id,
+ "job_name": job_name,
+ "machine_type": machine_type,
+ "cmd": cmd,
+ "image_address": image_address,
+ "work_dir": "",
+ "result": "",
+ "dataset_path": [],
+ "log_files": [],
+ "out_files": [],
+ }
+
+ # First load from YAML file if provided
+ if self._yaml_path and HAS_YAML:
+ try:
+ with open(self._yaml_path, 'r') as file:
+ yaml_params = yaml.safe_load(file)
+ if yaml_params:
+ params.update(yaml_params)
+ except yaml.YAMLError as e:
+ logger.error(f"Error parsing YAML file: {e}")
+ return {"error": f"YAML parsing error: {e!s}"}
+ except FileNotFoundError:
+ logger.error(f"YAML file not found: {self._yaml_path}")
+ return {"error": f"File not found: {self._yaml_path}"}
+ except Exception as e:
+ logger.error(f"Error loading YAML file: {e}")
+ return {"error": str(e)}
+ elif self._yaml_path and not HAS_YAML:
+ logger.warning(
+ "PyYAML is not installed. YAML file will be ignored."
+ )
+ return {"warning": "PyYAML is not installed. YAML file ignored."}
+
+ try:
+ result = self._job.submit(
+ project_id=params["project_id"],
+ job_name=params["job_name"],
+ machine_type=params["machine_type"],
+ cmd=params["cmd"],
+ image_address=params["image_address"],
+ job_group_id=params.get("job_group_id", 0),
+ work_dir=params["work_dir"],
+ result=params["result"],
+ dataset_path=params["dataset_path"],
+ log_files=params["log_files"],
+ out_files=params["out_files"],
+ )
+
+ return {"status": "Job submitted successfully", "result": result}
+
+ except Exception as e:
+ logger.error(f"Error submitting job: {e}")
+ return {"error": str(e)}
+
+ def get_job_details(self, job_id: int) -> Dict[str, Any]:
+ r"""Get details for a specific job.
+
+ Args:
+ job_id (int): The ID of the job.
+
+ Returns:
+ Dict[str, Any]: The job details.
+ """
+ try:
+ return self._job.detail(job_id)
+ except Exception as e:
+ logger.error(f"Error getting job details: {e}")
+ return {"error": str(e)}
+
+ def terminate_job(self, job_id: int) -> Dict[str, Any]:
+ r"""Terminate a running job.
+
+ Args:
+ job_id (int): The ID of the job to terminate.
+
+ Returns:
+ Dict[str, Any]: The result of the termination request.
+ """
+ try:
+ self._job.terminate(job_id)
+ return {"status": "Job terminated successfully"}
+ except Exception as e:
+ logger.error(f"Error terminating job: {e}")
+ return {"error": str(e)}
+
+ def kill_job(self, job_id: int) -> Dict[str, Any]:
+ r"""Kill a running job.
+
+ Args:
+ job_id (int): The ID of the job to kill.
+
+ Returns:
+ Dict[str, Any]: The result of the kill request.
+ """
+ try:
+ self._job.kill(job_id)
+ return {"status": "Job killed successfully"}
+ except Exception as e:
+ logger.error(f"Error killing job: {e}")
+ return {"error": str(e)}
+
+ def get_job_logs(
+ self,
+ job_id: int,
+ log_file: str = "STDOUTERR",
+ page: int = -1,
+ page_size: int = 8192,
+ ) -> str:
+ r"""Get logs for a specific job.
+
+ Args:
+ job_id (int): The ID of the job.
+ log_file (str, optional): The log file to get.
+ (default: :obj:`STDOUTERR`)
+ page (int, optional): The page number.
+ (default: :obj:`-1`)
+ page_size (int, optional): The page size.
+ (default: :obj:`8192`)
+
+ Returns:
+ str: The log contents.
+ """
+ try:
+ return self._job.log(
+ job_id, log_file=log_file, page=page, page_size=page_size
+ )
+ except Exception as e:
+ logger.error(f"Error getting job logs: {e}")
+ return f"Error retrieving logs: {e!s}"
+
+ def create_job_group(
+ self, project_id: int, job_group_name: str
+ ) -> Dict[str, Any]:
+ r"""Create a job group.
+
+ Args:
+ project_id (int): The ID of the project.
+ job_group_name (str): The name of the job group.
+
+ Returns:
+ Dict[str, Any]: The result of the job group creation.
+ """
+ try:
+ self._job.create_job_group(project_id, job_group_name)
+ return {"status": "Job group created successfully"}
+ except Exception as e:
+ logger.error(f"Error creating job group: {e}")
+ return {"error": str(e)}
+
+ def download_job_results(
+ self, job_id: int, save_path: str
+ ) -> Dict[str, Any]:
+ r"""Download the results of a job.
+
+ Args:
+ job_id (int): The ID of the job.
+ save_path (str): The path to save the results to.
+
+ Returns:
+ Dict[str, Any]: The result of the download request.
+ """
+ try:
+ self._job.download(job_id, save_path)
+ return {
+ "status": "Job results downloaded successfully",
+ "path": save_path,
+ }
+ except Exception as e:
+ logger.error(f"Error downloading job results: {e}")
+ return {"error": str(e)}
+
+ def get_tools(self) -> List[FunctionTool]:
+ r"""Returns a list of FunctionTool objects representing the
+ functions in the toolkit.
+
+ Returns:
+ List[FunctionTool]: A list of FunctionTool objects
+ representing the functions in the toolkit.
+ """
+ return [
+ FunctionTool(self.submit_job),
+ FunctionTool(self.get_job_details),
+ FunctionTool(self.terminate_job),
+ FunctionTool(self.kill_job),
+ FunctionTool(self.get_job_logs),
+ FunctionTool(self.create_job_group),
+ FunctionTool(self.download_job_results),
+ ]
diff --git a/examples/toolkits/bohrium_toolkit_example.py b/examples/toolkits/bohrium_toolkit_example.py
new file mode 100644
index 000000000..39a4c7614
--- /dev/null
+++ b/examples/toolkits/bohrium_toolkit_example.py
@@ -0,0 +1,70 @@
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+
+from camel.agents import ChatAgent
+from camel.models import ModelFactory
+from camel.toolkits import BohriumToolkit
+from camel.types import ModelPlatformType, ModelType
+
+# Convert the example input into audio and store it locally
+model = ModelFactory.create(
+ model_platform=ModelPlatformType.DEFAULT,
+ model_type=ModelType.DEFAULT,
+)
+# Create the BohriumToolkit with our reasoning model
+bohrium_toolkit = BohriumToolkit(
+ yaml_path="examples/toolkits/bohrium_toolkit_example.yaml",
+ api_key="xxx",
+ project_id=617833,
+)
+
+# Create a ChatAgent with the audio toolkit tools
+agent = ChatAgent(
+ model=model,
+ tools=[*bohrium_toolkit.get_tools()],
+)
+
+response = agent.step(
+ "Submit a job to Bohrium,and help me check the job status"
+)
+print(response.msgs[0].content)
+print("\n")
+
+"""
+==========================================================================
+Your job has been submitted successfully with the following details:
+
+- **Job ID**: 18105226
+- **Bohr Job ID**: 15485870
+- **Job Group ID**: 14695383
+- **Project ID**: 617833
+- **User ID**: 615385
+- **Platform**: Ali
+- **Status**: The job is currently in the initial state (status code 0).
+- **Create Time**: 2025-05-14 14:36:14
+- **Update Time**: 2025-05-14 14:36:15
+- **Job Name**: test-bohr-job
+- **Project Name**: CAMEL-AI
+- **User Name**: CAMEL-AI
+- **Image Name**: registry.dp.tech/dptech/lammps:29Sep2021
+- **Command**: mpirun -n 2 lmp_mpi -i in.shear
+- **Machine Type**: c2_m4_cpu (2 CPU, 4 GB Memory)
+- **Region**: cn-zhangjiakou
+
+The job is currently pending or initializing. I will keep you updated on
+its progress. If you need further assistance, feel free to ask!
+If you want to monitor the job's status or logs, let me know and I can
+assist you with that as well.
+==========================================================================
+"""
diff --git a/examples/toolkits/bohrium_toolkit_example.yaml b/examples/toolkits/bohrium_toolkit_example.yaml
new file mode 100644
index 000000000..3e4afb7ba
--- /dev/null
+++ b/examples/toolkits/bohrium_toolkit_example.yaml
@@ -0,0 +1,4 @@
+job_name: "test-bohr-job"
+machine_type: "c2_m4_cpu"
+cmd: "mpirun -n 2 lmp_mpi -i in.shear"
+image_address: "registry.dp.tech/dptech/lammps:29Sep2021"
diff --git a/pyproject.toml b/pyproject.toml
index 4646121f5..d9cac3001 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -156,6 +156,7 @@ research_tools = [
"arxiv>=2.1.3,<3",
"arxiv2text>=0.1.14,<0.2",
"scholarly[tor]==1.7.11",
+ "bohrium",
]
dev_tools = [
"docker>=7.1.0,<8",
@@ -365,6 +366,7 @@ all = [
"ibm-watsonx-ai>=1.3.11",
"google-genai>=1.13.0",
"aci-sdk>=1.0.0b1",
+ "bohrium",
]
@@ -379,6 +381,9 @@ default-groups = [
"docs",
]
+[tool.uv.sources]
+bohrium = { git = "https://github.com/dptech-corp/bohrium-openapi-python-sdk" }
+
[tool.hatch.build.targets.sdist]
include = ["camel"]
@@ -556,6 +561,8 @@ module = [
"scrapegraph_py.*",
"ibm_watsonx_ai.*",
"google_genai",
+ "aci-sdk.*",
+ "bohrium.*",
]
ignore_missing_imports = true
diff --git a/test/toolkits/test_bohrium_toolkit.py b/test/toolkits/test_bohrium_toolkit.py
new file mode 100644
index 000000000..9cf0317c3
--- /dev/null
+++ b/test/toolkits/test_bohrium_toolkit.py
@@ -0,0 +1,350 @@
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+
+import os
+import tempfile
+from unittest.mock import MagicMock, patch
+
+import pytest
+import yaml
+
+from camel.toolkits import BohriumToolkit
+
+
+def mock_bohrium_client():
+ """Create a mock for Bohrium client."""
+ mock_client = MagicMock()
+ mock_client.post.return_value.json.return_value = {
+ "code": 0,
+ "data": {"jobGroupId": 12345, "jobId": 67890, "bohrJobId": 54321},
+ }
+ mock_client.get.return_value.json.return_value = {
+ "code": 0,
+ "data": {
+ "name": "test_job",
+ "status": "PENDING",
+ "createTime": "2023-01-01T00:00:00Z",
+ },
+ }
+ return mock_client
+
+
+def mock_job(mock_bohrium_client):
+ """Create a mock for Job class."""
+ mock_job = MagicMock()
+ mock_job.submit.return_value = {"jobId": 67890, "jobGroupId": 12345}
+ mock_job.detail.return_value = {
+ "name": "test_job",
+ "status": "PENDING",
+ "createTime": "2023-01-01T00:00:00Z",
+ }
+ return mock_job
+
+
+def sample_yaml_file():
+ """Create a temporary YAML file for testing."""
+ with tempfile.NamedTemporaryFile(
+ suffix=".yaml", delete=False, mode='w'
+ ) as temp_file:
+ yaml_content = {
+ "job_name": "test-bohrium-job",
+ "machine_type": "c2_m4_cpu",
+ "cmd": "mpirun -n 2 lmp_mpi -i in.shear",
+ "image_address": "registry.dp.tech/dptech/lammps:29Sep2021",
+ }
+ yaml.dump(yaml_content, temp_file)
+ temp_path = temp_file.name
+
+ yield temp_path
+
+ # Clean up the temporary file
+ if os.path.exists(temp_path):
+ os.remove(temp_path)
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_init(mock_job_class, mock_bohrium_class):
+ """Test initialization of BohriumToolkit."""
+
+ # Test initialization with all parameters
+ toolkit = BohriumToolkit(
+ api_key="test_api_key",
+ project_id=123456,
+ yaml_path="test_path.yaml",
+ timeout=30.0,
+ )
+
+ # Check that the client and job were initialized correctly
+ mock_bohrium_class.assert_called_once()
+ mock_job_class.assert_called_once()
+
+ # Check that the class attributes were set correctly
+ assert toolkit._project_id == 123456
+ assert toolkit._yaml_path == "test_path.yaml"
+
+ # Check that custom_insert was set up
+ assert hasattr(toolkit, '_custom_insert')
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_submit_job_with_yaml(
+ mock_job_class, mock_bohrium_class, sample_yaml_file
+):
+ """Test submitting a job using a YAML file."""
+ # Setup mocks
+ mock_job = mock_job_class.return_value
+
+ # Setup mock return values
+ mock_job.submit.return_value = {"jobId": 67890, "jobGroupId": 12345}
+
+ # Initialize toolkit with project_id and yaml_path
+ toolkit = BohriumToolkit(
+ api_key="test_api_key", project_id=123456, yaml_path=sample_yaml_file
+ )
+
+ toolkit._job = mock_job
+
+ # Submit the job
+ result = toolkit.submit_job()
+
+ # Check that the job was submitted with the correct parameters
+ mock_job.submit.assert_called_once()
+ args, kwargs = mock_job.submit.call_args
+
+ # Check that the parameters from the YAML file were used
+ assert kwargs["job_name"] == "test-bohrium-job"
+ assert kwargs["machine_type"] == "c2_m4_cpu"
+ assert kwargs["cmd"] == "mpirun -n 2 lmp_mpi -i in.shear"
+ assert (
+ kwargs["image_address"] == "registry.dp.tech/dptech/lammps:29Sep2021"
+ )
+ assert (
+ kwargs["project_id"] == 123456
+ ) # This comes from the toolkit initialization
+
+ # Check the result format
+ assert "status" in result
+ assert result["status"] == "Job submitted successfully"
+
+ # Check if result contains the expected job information
+ # The information might be in the "result" field as a nested structure
+ if "result" in result and isinstance(result["result"], dict):
+ assert "jobId" in result["result"]
+ assert result["result"]["jobId"] == 67890
+ else:
+ raise AssertionError(f"Unexpected result structure: {result}")
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_submit_job_missing_parameters(mock_job_class, mock_bohrium_class):
+ """Test submitting a job with missing parameters."""
+ # Setup mocks
+ mock_job = mock_job_class.return_value
+
+ # Initialize toolkit without yaml_path
+ toolkit = BohriumToolkit(api_key="test_api_key", project_id=123456)
+
+ # Set the method we're patching manually
+ toolkit._job = mock_job
+
+ # Submit the job with project_id but no yaml_path
+ # Now that we have default parameters in submit_job,
+ # it should not fail with missing parameters
+ result = toolkit.submit_job()
+
+ # Check the result contains success status
+ assert "status" in result
+ assert result["status"] == "Job submitted successfully"
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_get_job_details(mock_job_class, mock_bohrium_class):
+ """Test getting job details."""
+ # Setup mocks
+ mock_job = mock_job_class.return_value
+
+ # Setup mock return values
+ mock_job.detail.return_value = {
+ "name": "test_job",
+ "status": "PENDING",
+ "createTime": "2023-01-01T00:00:00Z",
+ }
+
+ # Initialize toolkit
+ toolkit = BohriumToolkit(api_key="test_api_key", project_id=123456)
+
+ # Set the method we're patching manually
+ toolkit._job = mock_job
+
+ # Get job details
+ result = toolkit.get_job_details(67890)
+
+ # Check that the correct job details were returned
+ mock_job.detail.assert_called_once_with(67890)
+ assert result["name"] == "test_job"
+ assert result["status"] == "PENDING"
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_terminate_job(mock_job_class, mock_bohrium_class):
+ """Test terminating a job."""
+ # Setup mocks
+ mock_job = mock_job_class.return_value
+
+ # Initialize toolkit
+ toolkit = BohriumToolkit(api_key="test_api_key", project_id=123456)
+
+ # Set the method we're patching manually
+ toolkit._job = mock_job
+
+ # Terminate job
+ result = toolkit.terminate_job(67890)
+
+ # Check that the job was terminated
+ mock_job.terminate.assert_called_once_with(67890)
+ assert result["status"] == "Job terminated successfully"
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_kill_job(mock_job_class, mock_bohrium_class):
+ """Test killing a job."""
+ # Setup mocks
+ mock_job = mock_job_class.return_value
+
+ # Initialize toolkit
+ toolkit = BohriumToolkit(api_key="test_api_key", project_id=123456)
+
+ # Set the method we're patching manually
+ toolkit._job = mock_job
+
+ # Kill job
+ result = toolkit.kill_job(67890)
+
+ # Check that the job was killed
+ mock_job.kill.assert_called_once_with(67890)
+ assert result["status"] == "Job killed successfully"
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_get_job_logs(mock_job_class, mock_bohrium_class):
+ """Test getting job logs."""
+ # Setup mocks
+ mock_job = mock_job_class.return_value
+ mock_job.log.return_value = "Test log output"
+
+ # Initialize toolkit
+ toolkit = BohriumToolkit(api_key="test_api_key", project_id=123456)
+
+ # Set the method we're patching manually
+ toolkit._job = mock_job
+
+ # Get job logs
+ result = toolkit.get_job_logs(67890)
+
+ # Check that the logs were retrieved
+ mock_job.log.assert_called_once_with(
+ 67890, log_file="STDOUTERR", page=-1, page_size=8192
+ )
+ assert result == "Test log output"
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_create_job_group(mock_job_class, mock_bohrium_class):
+ """Test creating a job group."""
+ # Setup mocks
+ mock_job = mock_job_class.return_value
+
+ # Initialize toolkit
+ toolkit = BohriumToolkit(api_key="test_api_key", project_id=123456)
+
+ # Set the method we're patching manually
+ toolkit._job = mock_job
+
+ # Create job group
+ result = toolkit.create_job_group(123456, "test-group")
+
+ # Check that the job group was created
+ mock_job.create_job_group.assert_called_once_with(123456, "test-group")
+ assert result["status"] == "Job group created successfully"
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_download_job_results(mock_job_class, mock_bohrium_class):
+ """Test downloading job results."""
+ # Setup mocks
+ mock_job = mock_job_class.return_value
+
+ # Initialize toolkit
+ toolkit = BohriumToolkit(api_key="test_api_key", project_id=123456)
+
+ # Set the method we're patching manually
+ toolkit._job = mock_job
+
+ # Download job results
+ result = toolkit.download_job_results(67890, "/tmp/results")
+
+ # Check that the results were downloaded
+ mock_job.download.assert_called_once_with(67890, "/tmp/results")
+ assert result["status"] == "Job results downloaded successfully"
+ assert result["path"] == "/tmp/results"
+
+
+@patch("bohrium._client.Bohrium", autospec=True)
+@patch("bohrium.resources.Job", autospec=True)
+def test_get_tools(mock_job_class, mock_bohrium_class):
+ """Test getting available tools."""
+ # Initialize toolkit
+
+ # Initialize toolkit
+ toolkit = BohriumToolkit(api_key="test_api_key", project_id=123456)
+
+ # Get tools
+ tools = toolkit.get_tools()
+
+ # Check that we have the expected number of tools
+ assert (
+ len(tools) == 7
+ ) # Should have 7 tools based on the current implementation
+
+ # Check that all tools are FunctionTool instances
+ from camel.toolkits.function_tool import FunctionTool
+
+ for tool in tools:
+ assert isinstance(tool, FunctionTool)
+
+ # Check that all expected tool functions are included
+ tool_names = [tool.get_function_name() for tool in tools]
+ expected_names = [
+ "submit_job",
+ "get_job_details",
+ "terminate_job",
+ "kill_job",
+ "get_job_logs",
+ "create_job_group",
+ "download_job_results",
+ ]
+ for name in expected_names:
+ assert name in tool_names
diff --git a/uv.lock b/uv.lock
index efd8feddc..9bbbb1770 100644
--- a/uv.lock
+++ b/uv.lock
@@ -531,6 +531,11 @@ css = [
{ name = "tinycss2" },
]
+[[package]]
+name = "bohrium"
+version = "0.1.0"
+source = { git = "https://github.com/dptech-corp/bohrium-openapi-python-sdk#37bbd97fdfb0fcdee03a1d272325ffbc19906fe3" }
+
[[package]]
name = "botocore"
version = "1.38.19"
@@ -583,6 +588,7 @@ all = [
{ name = "arxiv2text" },
{ name = "azure-storage-blob" },
{ name = "beautifulsoup4" },
+ { name = "bohrium" },
{ name = "botocore" },
{ name = "cohere" },
{ name = "crawl4ai" },
@@ -858,6 +864,7 @@ rag = [
research-tools = [
{ name = "arxiv" },
{ name = "arxiv2text" },
+ { name = "bohrium" },
{ name = "scholarly", extra = ["tor"] },
]
storage = [
@@ -929,6 +936,8 @@ requires-dist = [
{ name = "beautifulsoup4", marker = "extra == 'document-tools'", specifier = ">=4,<5" },
{ name = "beautifulsoup4", marker = "extra == 'owl'", specifier = ">=4,<5" },
{ name = "beautifulsoup4", marker = "extra == 'web-tools'", specifier = ">=4,<5" },
+ { name = "bohrium", marker = "extra == 'all'", git = "https://github.com/dptech-corp/bohrium-openapi-python-sdk" },
+ { name = "bohrium", marker = "extra == 'research-tools'", git = "https://github.com/dptech-corp/bohrium-openapi-python-sdk" },
{ name = "botocore", marker = "extra == 'all'", specifier = ">=1.35.3,<2" },
{ name = "botocore", marker = "extra == 'storage'", specifier = ">=1.35.3,<2" },
{ name = "chunkr-ai", marker = "extra == 'owl'", specifier = ">=0.0.41" },