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
1617from camel .agents import ChatAgent
1718
@@ -92,3 +93,42 @@ def build_faithfulness_prompt(
9293- 1.0: Answer is fully faithful
9394
9495Respond 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 )
0 commit comments