Skip to content

Commit bff6c29

Browse files
committed
refactor: nexus
1 parent c112e07 commit bff6c29

File tree

5 files changed

+213
-523
lines changed

5 files changed

+213
-523
lines changed

camel/benchmarks/_utils.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313
# ========= Copyright 2023-2026 @ CAMEL-AI.org. All Rights Reserved. =========
14-
from typing import Callable
14+
import json
15+
from typing import Any, Callable, Dict
1516

1617
from camel.agents import ChatAgent
1718

@@ -92,3 +93,42 @@ def build_faithfulness_prompt(
9293
- 1.0: Answer is fully faithful
9394
9495
Respond with only the numeric score, nothing else."""
96+
97+
98+
def save_to_jsonl(
99+
file_path: str,
100+
data: Dict[str, Any],
101+
mode: str = "a",
102+
) -> None:
103+
r"""Save a dictionary to a JSONL file.
104+
105+
Args:
106+
file_path (str): Path to the JSONL file.
107+
data (Dict[str, Any]): Dictionary to save as a JSON line.
108+
mode (str): File mode. Defaults to "a" (append).
109+
"""
110+
json_str = json.dumps(data, indent=2, ensure_ascii=False)
111+
with open(file_path, mode) as f:
112+
f.write(json_str + "\n")
113+
f.flush()
114+
115+
116+
TOOL_CALLING_PROMPT = """
117+
You are given multiple functions and a user query.
118+
119+
Please proceed with generating a function call for the function \
120+
with the proper arguments that best answers the given prompt.
121+
122+
Respond with nothing but the function call ONLY, such that I can \
123+
directly execute your function call without any post processing \
124+
necessary from my end. Do not use variables.
125+
If there are more than two function calls, separate them with a semicolon (;).
126+
127+
{tools}
128+
129+
Question: {input}
130+
"""
131+
132+
def construct_prompt(input: str, tools: str) -> str:
133+
r"Construct prompt from tools and input."
134+
return TOOL_CALLING_PROMPT.format(tools=tools, input=input)

camel/benchmarks/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BaseBenchmark(ABC):
3535
processing. :(default: :obj:`1`)
3636
"""
3737

38-
def __init__(self, name: str, data_dir: Optional[str], processes: int = 1):
38+
def __init__(self, name: str, data_dir: Optional[str], save_to: Optional[str], processes: int = 1):
3939
r"""Initialize the benchmark.
4040
4141
Args:
@@ -48,6 +48,7 @@ def __init__(self, name: str, data_dir: Optional[str], processes: int = 1):
4848
"""
4949
self.name = name
5050
self.data_dir = data_dir
51+
self.save_to = save_to
5152
self.processes = processes
5253
self._data: Dict[str, List[Dict[str, Any]]] = dict()
5354
self._results: List[Dict[str, Any]] = []

0 commit comments

Comments
 (0)