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

fix: add ensure_ascii to json dump (#1873)

Wendong-Fan13c7df285c15
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index f6acfed3d..5471b3c14 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -26,7 +26,7 @@ body:
attributes:
label: What version of camel are you using?
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
- placeholder: E.g., 0.2.30
+ placeholder: E.g., 0.2.31
validations:
required: true
diff --git a/camel/__init__.py b/camel/__init__.py
index 573f378e2..342e2e5df 100644
--- a/camel/__init__.py
+++ b/camel/__init__.py
@@ -14,7 +14,7 @@
from camel.logger import disable_logging, enable_logging, set_log_level
-__version__ = '0.2.30'
+__version__ = '0.2.31'
__all__ = [
'__version__',
diff --git a/camel/agents/_utils.py b/camel/agents/_utils.py
index d219b6f3a..4989e1394 100644
--- a/camel/agents/_utils.py
+++ b/camel/agents/_utils.py
@@ -37,7 +37,7 @@ def generate_tool_prompt(tool_schema_list: List[Dict[str, Any]]) -> str:
tool_info = tool["function"]
tool_name = tool_info["name"]
tool_description = tool_info["description"]
- tool_json = json.dumps(tool_info, indent=4)
+ tool_json = json.dumps(tool_info, indent=4, ensure_ascii=False)
prompt = (
f"Use the function '{tool_name}' to '{tool_description}':\n"
diff --git a/camel/benchmarks/apibank.py b/camel/benchmarks/apibank.py
index 284c4c47f..c3bdfc434 100644
--- a/camel/benchmarks/apibank.py
+++ b/camel/benchmarks/apibank.py
@@ -316,7 +316,10 @@ class APIBankBenchmark(BaseBenchmark):
'Correct': correct,
}
)
- f.write(json.dumps(self._results[-1], indent=2) + "\n")
+ json_str = json.dumps(
+ self._results[-1], indent=2, ensure_ascii=False
+ )
+ f.write(json_str + "\n")
elif (
sample.ground_truth['role'] == 'AI'
@@ -361,7 +364,10 @@ class APIBankBenchmark(BaseBenchmark):
'Test': test,
}
)
- f.write(json.dumps(self._results[-1], indent=2) + "\n")
+ json_str = json.dumps(
+ self._results[-1], indent=2, ensure_ascii=False
+ )
+ f.write(json_str + "\n")
f.flush()
diff --git a/camel/benchmarks/apibench.py b/camel/benchmarks/apibench.py
index 284cc2231..7c5c5376f 100644
--- a/camel/benchmarks/apibench.py
+++ b/camel/benchmarks/apibench.py
@@ -323,7 +323,10 @@ class APIBenchBenchmark(BaseBenchmark):
agent.reset()
- f.write(json.dumps(self._results[-1], indent=2) + "\n")
+ json_str = json.dumps(
+ self._results[-1], indent=2, ensure_ascii=False
+ )
+ f.write(json_str + "\n")
f.flush()
total = len(self._results)
diff --git a/camel/benchmarks/gaia.py b/camel/benchmarks/gaia.py
index 0eb5d184f..305ed877e 100644
--- a/camel/benchmarks/gaia.py
+++ b/camel/benchmarks/gaia.py
@@ -332,7 +332,9 @@ class GAIABenchmark(BaseBenchmark):
"history": agent.memory.get_context(),
}
self._results.append(result_data)
- file_obj.write(json.dumps(result_data, indent=2) + "\n")
+ file_obj.write(
+ json.dumps(result_data, indent=2) + "\n", ensure_ascii=False
+ )
file_obj.flush()
def _handle_error(
@@ -351,7 +353,9 @@ class GAIABenchmark(BaseBenchmark):
"score": 0,
}
self._results.append(error_data)
- file_obj.write(json.dumps(error_data, indent=2) + "\n")
+ file_obj.write(
+ json.dumps(error_data, indent=2) + "\n", ensure_ascii=False
+ )
file_obj.flush()
def _generate_summary(self) -> Dict[str, Any]:
diff --git a/camel/benchmarks/nexus.py b/camel/benchmarks/nexus.py
index dc3e65aca..7355fc7ca 100644
--- a/camel/benchmarks/nexus.py
+++ b/camel/benchmarks/nexus.py
@@ -343,7 +343,10 @@ class NexusBenchmark(BaseBenchmark):
agent.reset()
- f.write(json.dumps(self._results[-1], indent=2) + "\n")
+ json_str = json.dumps(
+ self._results[-1], indent=2, ensure_ascii=False
+ )
+ f.write(json_str + "\n")
f.flush()
total = len(self._results)
diff --git a/camel/data_collector/sharegpt_collector.py b/camel/data_collector/sharegpt_collector.py
index 8a5452142..bb2650c70 100644
--- a/camel/data_collector/sharegpt_collector.py
+++ b/camel/data_collector/sharegpt_collector.py
@@ -108,6 +108,7 @@ class ShareGPTDataCollector(BaseDataCollector):
tools=json.dumps(
[t.get_openai_tool_schema()["function"] for t in self.tools]
),
+ ensure_ascii=False,
conversations=[],
)
@@ -124,7 +125,9 @@ class ShareGPTDataCollector(BaseDataCollector):
conversations.append(
{
"from": "function_call",
- "value": json.dumps(message.function_call),
+ "value": json.dumps(
+ message.function_call, ensure_ascii=False
+ ),
}
)
else:
@@ -135,7 +138,9 @@ class ShareGPTDataCollector(BaseDataCollector):
conversations.append(
{
"from": "observation",
- "value": json.dumps(message.message), # type: ignore[attr-defined]
+ "value": json.dumps(
+ message.message, ensure_ascii=False
+ ), # type: ignore[attr-defined]
}
)
data["conversations"] = conversations
@@ -171,7 +176,8 @@ class ShareGPTDataCollector(BaseDataCollector):
context.append(
"Tools: "
+ json.dumps(
- [t.get_openai_tool_schema()["function"] for t in self.tools]
+ [t.get_openai_tool_schema()["function"] for t in self.tools],
+ ensure_ascii=False,
)
)
for _data in self.get_agent_history(str(self.agent_name)):
@@ -180,10 +186,15 @@ class ShareGPTDataCollector(BaseDataCollector):
f"{role}: " if role != "user" else "User: " + f"{_data.name}: "
)
if message.function_call:
- context.append(prefix + json.dumps(message.function_call))
+ context.append(
+ prefix
+ + json.dumps(message.function_call, ensure_ascii=False)
+ )
elif role == "function" or role == "tool":
- context.append(prefix + json.dumps(message.message)) # type: ignore[attr-defined]
+ context.append(
+ prefix + json.dumps(message.message, ensure_ascii=False)
+ ) # type: ignore[attr-defined]
else:
context.append(prefix + str(message.message))
return converter.convert(
diff --git a/camel/datahubs/huggingface.py b/camel/datahubs/huggingface.py
index 8e684fc10..144149b0b 100644
--- a/camel/datahubs/huggingface.py
+++ b/camel/datahubs/huggingface.py
@@ -372,6 +372,7 @@ class HuggingFaceDatasetManager(BaseDatasetManager):
for record in records
],
f,
+ ensure_ascii=False,
)
temp_file_path = f.name
@@ -411,14 +412,14 @@ class HuggingFaceDatasetManager(BaseDatasetManager):
)
else:
try:
- json.dumps(file_content)
+ json.dumps(file_content, ensure_ascii=False)
json_content = file_content
except (TypeError, ValueError):
raise ValueError(
"file_content is not JSON serializable."
)
- json.dump(json_content, f)
+ json.dump(json_content, f, ensure_ascii=False)
elif file_type == "md" or file_type == "txt":
f.write(file_content)
else:
diff --git a/camel/datasets/base_generator.py b/camel/datasets/base_generator.py
index e1f6713cd..6d013d715 100644
--- a/camel/datasets/base_generator.py
+++ b/camel/datasets/base_generator.py
@@ -120,7 +120,7 @@ class BaseGenerator(abc.ABC):
try:
with file_path.open("w", encoding="utf-8") as f:
for datapoint in self._data:
- json.dump(datapoint.to_dict(), f)
+ json.dump(datapoint.to_dict(), f, ensure_ascii=False)
f.write("\n") # Ensure each entry is on a new line
logger.info(f"Dataset saved successfully to {file_path}")
except IOError as e:
diff --git a/camel/loaders/base_io.py b/camel/loaders/base_io.py
index edf55e0d0..7247279ec 100644
--- a/camel/loaders/base_io.py
+++ b/camel/loaders/base_io.py
@@ -276,7 +276,7 @@ class JsonFile(File):
# Parse the JSON data from the file
data = json.load(file)
# Create a dictionary with the parsed data
- doc = {"page_content": json.dumps(data)}
+ doc = {"page_content": json.dumps(data, ensure_ascii=False)}
# Calculate a unique identifier for the file
file_id = md5(file.getvalue()).hexdigest()
# Reset the file pointer to the beginning
diff --git a/camel/loaders/chunkr_reader.py b/camel/loaders/chunkr_reader.py
index e61a99d1d..007ee0764 100644
--- a/camel/loaders/chunkr_reader.py
+++ b/camel/loaders/chunkr_reader.py
@@ -164,4 +164,4 @@ class ChunkrReader:
Returns:
str: Formatted JSON as a string.
"""
- return json.dumps(response_json, indent=4)
+ return json.dumps(response_json, indent=4, ensure_ascii=False)
diff --git a/camel/messages/conversion/conversation_models.py b/camel/messages/conversion/conversation_models.py
index 28dbea5c6..3469d9c16 100644
--- a/camel/messages/conversion/conversation_models.py
+++ b/camel/messages/conversion/conversation_models.py
@@ -113,7 +113,7 @@ class ToolCall(BaseModel):
# Try to serialize arguments to ensure they're JSON-compatible
try:
- json.dumps(v)
+ json.dumps(v, ensure_ascii=False)
except (TypeError, ValueError):
raise ValueError("Arguments must be JSON-serializable")
@@ -155,7 +155,7 @@ class ToolResponse(BaseModel):
# Ensure content is JSON-serializable
try:
- json.dumps(v)
+ json.dumps(v, ensure_ascii=False)
except (TypeError, ValueError):
raise ValueError("Response content must be JSON-serializable")
diff --git a/camel/messages/func_message.py b/camel/messages/func_message.py
index f0a490a58..7745824c2 100644
--- a/camel/messages/func_message.py
+++ b/camel/messages/func_message.py
@@ -133,7 +133,7 @@ class FunctionCallingMessage(BaseMessage):
"type": "function",
"function": {
"name": self.func_name,
- "arguments": json.dumps(self.args),
+ "arguments": json.dumps(self.args, ensure_ascii=False),
},
}
],
diff --git a/camel/models/cohere_model.py b/camel/models/cohere_model.py
index 6d57a617b..eeaebd3ef 100644
--- a/camel/models/cohere_model.py
+++ b/camel/models/cohere_model.py
@@ -176,7 +176,9 @@ class CohereModel(BaseModelBackend):
else:
arguments = function_call.get("arguments") # type: ignore[attr-defined]
arguments_dict = ast.literal_eval(arguments)
- arguments_json = json.dumps(arguments_dict)
+ arguments_json = json.dumps(
+ arguments_dict, ensure_ascii=False
+ )
assis_tool_call_id = str(uuid.uuid4())
tool_call_id = assis_tool_call_id
diff --git a/camel/models/samba_model.py b/camel/models/samba_model.py
index 969df2d48..b0adbc5a9 100644
--- a/camel/models/samba_model.py
+++ b/camel/models/samba_model.py
@@ -307,7 +307,8 @@ class SambaModel(BaseModelBackend):
{
"conversation_id": str(uuid.uuid4()),
"messages": messages,
- }
+ },
+ ensure_ascii=False,
),
"params": {
"do_sample": {"type": "bool", "value": "true"},
@@ -537,7 +538,8 @@ class SambaModel(BaseModelBackend):
{
"conversation_id": str(uuid.uuid4()),
"messages": messages,
- }
+ },
+ ensure_ascii=False,
),
"params": {
"do_sample": {"type": "bool", "value": "true"},
diff --git a/camel/personas/persona.py b/camel/personas/persona.py
index ff2b2aab6..d90d5b215 100644
--- a/camel/personas/persona.py
+++ b/camel/personas/persona.py
@@ -100,4 +100,5 @@ class Persona(BaseModel):
",",
": ",
), # Fine-tune separators for better readability
+ ensure_ascii=False,
)
diff --git a/camel/runtime/api.py b/camel/runtime/api.py
index ad9ed9666..11b18fe17 100644
--- a/camel/runtime/api.py
+++ b/camel/runtime/api.py
@@ -80,10 +80,14 @@ for module_function in modules_functions:
output = sys.stdout.read()
sys.stdout = sys.__stdout__
return {
- "output": json.dumps(response_data),
+ "output": json.dumps(
+ response_data, ensure_ascii=False
+ ),
"stdout": output,
}
- return {"output": json.dumps(response_data)}
+ return {
+ "output": json.dumps(response_data, ensure_ascii=False)
+ }
except (ImportError, AttributeError) as e:
logger.error(f"Error importing {module_function}: {e}")
diff --git a/camel/runtime/docker_runtime.py b/camel/runtime/docker_runtime.py
index c0a38a269..ab1560629 100644
--- a/camel/runtime/docker_runtime.py
+++ b/camel/runtime/docker_runtime.py
@@ -271,7 +271,7 @@ class DockerRuntime(BaseRuntime):
funcs = [funcs]
if arguments is not None:
- entrypoint += json.dumps(arguments)
+ entrypoint += json.dumps(arguments, ensure_ascii=False)
for func in funcs:
inner_func = func.func
diff --git a/camel/runtime/remote_http_runtime.py b/camel/runtime/remote_http_runtime.py
index d3fff2c5e..2e8355396 100644
--- a/camel/runtime/remote_http_runtime.py
+++ b/camel/runtime/remote_http_runtime.py
@@ -100,7 +100,7 @@ class RemoteHttpRuntime(BaseRuntime):
if not isinstance(funcs, list):
funcs = [funcs]
if arguments is not None:
- entrypoint += json.dumps(arguments)
+ entrypoint += json.dumps(arguments, ensure_ascii=False)
for func in funcs:
inner_func = func.func
diff --git a/camel/storages/key_value_storages/json.py b/camel/storages/key_value_storages/json.py
index 50f666029..fcb4d965f 100644
--- a/camel/storages/key_value_storages/json.py
+++ b/camel/storages/key_value_storages/json.py
@@ -75,7 +75,11 @@ class JsonStorage(BaseKeyValueStorage):
"""
with self.json_path.open("a") as f:
f.writelines(
- [json.dumps(r, cls=_CamelJSONEncoder) + "\n" for r in records]
+ [
+ json.dumps(r, cls=_CamelJSONEncoder, ensure_ascii=False)
+ + "\n"
+ for r in records
+ ]
)
def load(self) -> List[Dict[str, Any]]:
diff --git a/camel/storages/key_value_storages/redis.py b/camel/storages/key_value_storages/redis.py
index 30c5c47a4..237e127e0 100644
--- a/camel/storages/key_value_storages/redis.py
+++ b/camel/storages/key_value_storages/redis.py
@@ -133,7 +133,7 @@ class RedisStorage(BaseKeyValueStorage):
if self._client is None:
raise ValueError("Redis client is not initialized")
try:
- value = json.dumps(records)
+ value = json.dumps(records, ensure_ascii=False)
if expire:
await self._client.setex(self._sid, expire, value)
else:
diff --git a/camel/toolkits/file_write_toolkit.py b/camel/toolkits/file_write_toolkit.py
index fc7e8f207..b6dd0c0d1 100644
--- a/camel/toolkits/file_write_toolkit.py
+++ b/camel/toolkits/file_write_toolkit.py
@@ -219,13 +219,13 @@ class FileWriteToolkit(BaseToolkit):
try:
# Try parsing as JSON string first
data = json.loads(content)
- json.dump(data, f)
+ json.dump(data, f, ensure_ascii=False)
except json.JSONDecodeError:
# If not valid JSON string, write as is
f.write(content)
else:
# If not string, dump as JSON
- json.dump(content, f)
+ json.dump(content, f, ensure_ascii=False)
logger.debug(f"Wrote JSON to {file_path} with {encoding} encoding")
def _write_yaml_file(
diff --git a/camel/toolkits/linkedin_toolkit.py b/camel/toolkits/linkedin_toolkit.py
index 4ca6770b0..c1989b64f 100644
--- a/camel/toolkits/linkedin_toolkit.py
+++ b/camel/toolkits/linkedin_toolkit.py
@@ -75,7 +75,9 @@ class LinkedInToolkit(BaseToolkit):
}
response = requests.post(
- url, headers=headers, data=json.dumps(post_data)
+ url,
+ headers=headers,
+ data=json.dumps(post_data, ensure_ascii=False),
)
if response.status_code == 201:
post_response = response.json()
diff --git a/camel/toolkits/networkx_toolkit.py b/camel/toolkits/networkx_toolkit.py
index 10aa692f1..55ffb7628 100644
--- a/camel/toolkits/networkx_toolkit.py
+++ b/camel/toolkits/networkx_toolkit.py
@@ -178,7 +178,7 @@ class NetworkXToolkit(BaseToolkit):
"""
logger.info("Serializing the graph.")
nx = self._get_nx()
- return json.dumps(nx.node_link_data(self.graph))
+ return json.dumps(nx.node_link_data(self.graph), ensure_ascii=False)
def deserialize_graph(self, data: str) -> None:
r"""Loads a graph from a serialized JSON string.
@@ -199,7 +199,7 @@ class NetworkXToolkit(BaseToolkit):
logger.info(f"Exporting graph to file: {file_path}")
nx = self._get_nx()
with open(file_path, "w") as file:
- json.dump(nx.node_link_data(self.graph), file)
+ json.dump(nx.node_link_data(self.graph), file, ensure_ascii=False)
def import_from_file(self, file_path: str) -> None:
r"""Imports a graph from a JSON file.
diff --git a/camel/toolkits/search_toolkit.py b/camel/toolkits/search_toolkit.py
index daa8ab7da..1c7c89ce8 100644
--- a/camel/toolkits/search_toolkit.py
+++ b/camel/toolkits/search_toolkit.py
@@ -751,7 +751,8 @@ class SearchToolkit(BaseToolkit):
"summary": summary,
"count": count,
"page": page,
- }
+ },
+ ensure_ascii=False,
)
try:
response = requests.post(url, headers=headers, data=payload)
diff --git a/camel/toolkits/semantic_scholar_toolkit.py b/camel/toolkits/semantic_scholar_toolkit.py
index 5ab330aa9..0aa043302 100644
--- a/camel/toolkits/semantic_scholar_toolkit.py
+++ b/camel/toolkits/semantic_scholar_toolkit.py
@@ -238,7 +238,7 @@ class SemanticScholarToolkit(BaseToolkit):
papers = response.json()
if save_to_file:
with open('recommended_papers.json', 'w') as output:
- json.dump(papers, output)
+ json.dump(papers, output, ensure_ascii=False)
return papers
except requests.exceptions.RequestException as e:
return {"error": str(e)}
@@ -282,7 +282,7 @@ class SemanticScholarToolkit(BaseToolkit):
response_data = response.json()
if save_to_file:
with open('author_information.json', 'w') as output:
- json.dump(response_data, output)
+ json.dump(response_data, output, ensure_ascii=False)
return response_data
except requests.exceptions.RequestException as e:
return {"error": str(e)}
diff --git a/camel/toolkits/stripe_toolkit.py b/camel/toolkits/stripe_toolkit.py
index b7980d5d1..3b66acea7 100644
--- a/camel/toolkits/stripe_toolkit.py
+++ b/camel/toolkits/stripe_toolkit.py
@@ -85,7 +85,7 @@ class StripeToolkit(BaseToolkit):
self.logger.info(f"Retrieving customer with ID: {customer_id}")
customer = stripe.Customer.retrieve(customer_id)
self.logger.info(f"Retrieved customer: {customer.id}")
- json_string = json.dumps(customer)
+ json_string = json.dumps(customer, ensure_ascii=False)
return json_string
except Exception as e:
return self.handle_exception("customer_get", e)
@@ -109,7 +109,9 @@ class StripeToolkit(BaseToolkit):
self.logger.info(
f"Successfully retrieved {len(customers)} customers."
)
- return json.dumps([customer for customer in customers])
+ return json.dumps(
+ [customer for customer in customers], ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("customer_list", e)
@@ -128,7 +130,7 @@ class StripeToolkit(BaseToolkit):
self.logger.info(
f"Successfully retrieved account balance: {balance}."
)
- return json.dumps(balance)
+ return json.dumps(balance, ensure_ascii=False)
except Exception as e:
return self.handle_exception("balance_get", e)
@@ -154,7 +156,10 @@ class StripeToolkit(BaseToolkit):
f"Successfully retrieved {len(transactions)} "
"balance transactions."
)
- return json.dumps([transaction for transaction in transactions])
+ return json.dumps(
+ [transaction for transaction in transactions],
+ ensure_ascii=False,
+ )
except Exception as e:
return self.handle_exception("balance_transaction_list", e)
@@ -174,7 +179,7 @@ class StripeToolkit(BaseToolkit):
self.logger.info(f"Retrieving payment with ID: {payment_id}")
payment = stripe.PaymentIntent.retrieve(payment_id)
self.logger.info(f"Retrieved payment: {payment.id}")
- return json.dumps(payment)
+ return json.dumps(payment, ensure_ascii=False)
except Exception as e:
return self.handle_exception("payment_get", e)
@@ -197,7 +202,9 @@ class StripeToolkit(BaseToolkit):
self.logger.info(
f"Successfully retrieved {len(payments)} payments."
)
- return json.dumps([payment for payment in payments])
+ return json.dumps(
+ [payment for payment in payments], ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("payment_list", e)
@@ -217,7 +224,7 @@ class StripeToolkit(BaseToolkit):
self.logger.info(f"Retrieving refund with ID: {refund_id}")
refund = stripe.Refund.retrieve(refund_id)
self.logger.info(f"Retrieved refund: {refund.id}")
- return json.dumps(refund)
+ return json.dumps(refund, ensure_ascii=False)
except Exception as e:
return self.handle_exception("refund_get", e)
@@ -238,7 +245,9 @@ class StripeToolkit(BaseToolkit):
self.logger.info(f"Listing refunds with limit={limit}")
refunds = stripe.Refund.list(limit=limit).data
self.logger.info(f"Successfully retrieved {len(refunds)} refunds.")
- return json.dumps([refund for refund in refunds])
+ return json.dumps(
+ [refund for refund in refunds], ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("refund_list", e)
diff --git a/camel/toolkits/sympy_toolkit.py b/camel/toolkits/sympy_toolkit.py
index 17ff41733..90800e14c 100644
--- a/camel/toolkits/sympy_toolkit.py
+++ b/camel/toolkits/sympy_toolkit.py
@@ -61,7 +61,10 @@ class SymPyToolkit(BaseToolkit):
try:
expr = sp.parsing.sympy_parser.parse_expr(expression)
simplified = sp.simplify(expr)
- return json.dumps({"status": "success", "result": str(simplified)})
+ return json.dumps(
+ {"status": "success", "result": str(simplified)},
+ ensure_ascii=False,
+ )
except Exception as e:
return self.handle_exception("simplify_expression", e)
@@ -83,7 +86,9 @@ class SymPyToolkit(BaseToolkit):
try:
expr = sp.parsing.sympy_parser.parse_expr(expression)
expanded_expr = sp.expand(expr)
- return json.dumps({"result": str(expanded_expr)})
+ return json.dumps(
+ {"result": str(expanded_expr)}, ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("expand_expression", e)
@@ -105,7 +110,9 @@ class SymPyToolkit(BaseToolkit):
try:
expr = sp.parsing.sympy_parser.parse_expr(expression)
factored_expr = sp.factor(expr)
- return json.dumps({"result": str(factored_expr)})
+ return json.dumps(
+ {"result": str(factored_expr)}, ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("factor_expression", e)
@@ -133,7 +140,9 @@ class SymPyToolkit(BaseToolkit):
eqs = [sp.sympify(eq) for eq in equations]
vars = sp.symbols(variables)
solution = sp.linsolve(eqs, vars)
- return json.dumps({"result": [str(sol) for sol in solution]})
+ return json.dumps(
+ {"result": [str(sol) for sol in solution]}, ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("solve_linear_system", e)
@@ -164,7 +173,9 @@ class SymPyToolkit(BaseToolkit):
eqs = [sp.sympify(eq) for eq in sympy_equations]
vars = sp.symbols(variables)
solution = sp.nonlinsolve(eqs, vars)
- return json.dumps({"result": [str(sol) for sol in solution]})
+ return json.dumps(
+ {"result": [str(sol) for sol in solution]}, ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("solve_nonlinear_system", e)
@@ -191,7 +202,7 @@ class SymPyToolkit(BaseToolkit):
var = sp.symbols(variable)
ineq = sp.sympify(inequality)
solution = sp.solve_univariate_inequality(ineq, var)
- return json.dumps({"result": str(solution)})
+ return json.dumps({"result": str(solution)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("solve_univariate_inequality", e)
@@ -214,7 +225,7 @@ class SymPyToolkit(BaseToolkit):
try:
ineqs = [sp.sympify(ineq) for ineq in inequalities]
solution = sp.reduce_inequalities(ineqs)
- return json.dumps({"result": str(solution)})
+ return json.dumps({"result": str(solution)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("reduce_inequalities", e)
@@ -241,7 +252,7 @@ class SymPyToolkit(BaseToolkit):
var = sp.symbols(variable)
expr = sp.parsing.sympy_parser.parse_expr(expression)
poly = sp.Poly(expr, var)
- return json.dumps({"result": str(poly)})
+ return json.dumps({"result": str(poly)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("polynomial_representation", e)
@@ -266,7 +277,7 @@ class SymPyToolkit(BaseToolkit):
var = sp.symbols(variable)
expr = sp.parsing.sympy_parser.parse_expr(expression)
degree = int(sp.degree(expr, var))
- return json.dumps({"result": degree})
+ return json.dumps({"result": degree}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("polynomial_degree", e)
@@ -292,7 +303,10 @@ class SymPyToolkit(BaseToolkit):
var = sp.symbols(variable)
expr = sp.parsing.sympy_parser.parse_expr(expression)
coeffs = sp.Poly(expr, var).all_coeffs()
- return json.dumps({"result": [str(coeff) for coeff in coeffs]})
+ return json.dumps(
+ {"result": [str(coeff) for coeff in coeffs]},
+ ensure_ascii=False,
+ )
except Exception as e:
return self.handle_exception("polynomial_coefficients", e)
@@ -323,7 +337,9 @@ class SymPyToolkit(BaseToolkit):
)
eq = sp.sympify(sympy_equation)
solutions = sp.solve(eq, variable)
- return json.dumps({"result": [str(sol) for sol in solutions]})
+ return json.dumps(
+ {"result": [str(sol) for sol in solutions]}, ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("solve_equation", e)
@@ -346,7 +362,9 @@ class SymPyToolkit(BaseToolkit):
try:
expr = sp.parsing.sympy_parser.parse_expr(expression)
roots = sp.solve(expr)
- return json.dumps({"status": "success", "result": str(roots)})
+ return json.dumps(
+ {"status": "success", "result": str(roots)}, ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("find_roots", e)
@@ -379,7 +397,7 @@ class SymPyToolkit(BaseToolkit):
)
expr = sp.parsing.sympy_parser.parse_expr(expression)
derivative = sp.diff(expr, variable)
- return json.dumps({"result": str(derivative)})
+ return json.dumps({"result": str(derivative)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("differentiate", e)
@@ -411,7 +429,7 @@ class SymPyToolkit(BaseToolkit):
)
expr = sp.parsing.sympy_parser.parse_expr(expression)
integral = sp.integrate(expr, variable)
- return json.dumps({"result": str(integral)})
+ return json.dumps({"result": str(integral)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("integrate", e)
@@ -441,7 +459,7 @@ class SymPyToolkit(BaseToolkit):
var = sp.symbols(variable)
expr = sp.parsing.sympy_parser.parse_expr(expression)
integral = sp.integrate(expr, (var, lower, upper))
- return json.dumps({"result": str(integral)})
+ return json.dumps({"result": str(integral)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("definite_integral", e)
@@ -473,7 +491,7 @@ class SymPyToolkit(BaseToolkit):
var = sp.symbols(variable)
expr = sp.parsing.sympy_parser.parse_expr(expression)
series = sp.series(expr, var, point, order)
- return json.dumps({"result": str(series)})
+ return json.dumps({"result": str(series)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("series_expansion", e)
@@ -505,7 +523,7 @@ class SymPyToolkit(BaseToolkit):
var = sp.symbols(variable)
expr = sp.parsing.sympy_parser.parse_expr(expression)
limit = sp.limit(expr, var, point)
- return json.dumps({"result": str(limit)})
+ return json.dumps({"result": str(limit)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("compute_limit", e)
@@ -534,7 +552,8 @@ class SymPyToolkit(BaseToolkit):
derivative = sp.diff(expr, var)
critical_points = sp.solve(derivative, var)
return json.dumps(
- {"result": [str(point) for point in critical_points]}
+ {"result": [str(point) for point in critical_points]},
+ ensure_ascii=False,
)
except Exception as e:
return self.handle_exception("find_critical_points", e)
@@ -568,7 +587,9 @@ class SymPyToolkit(BaseToolkit):
right_limit = sp.limit(expr, var, point, dir='+')
value_at_point = expr.subs(var, point)
is_continuous = left_limit == right_limit == value_at_point
- return json.dumps({"result": str(is_continuous)})
+ return json.dumps(
+ {"result": str(is_continuous)}, ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("check_continuity", e)
@@ -590,7 +611,7 @@ class SymPyToolkit(BaseToolkit):
try:
mat = sp.Matrix(matrix)
determinant = mat.det()
- return json.dumps({"result": str(determinant)})
+ return json.dumps({"result": str(determinant)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("compute_determinant", e)
@@ -613,7 +634,7 @@ class SymPyToolkit(BaseToolkit):
try:
mat = sp.Matrix(matrix)
inverse = mat.inv()
- return json.dumps({"result": str(inverse)})
+ return json.dumps({"result": str(inverse)}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("compute_inverse", e)
@@ -638,7 +659,8 @@ class SymPyToolkit(BaseToolkit):
mat = sp.Matrix(matrix)
eigenvalues = mat.eigenvals()
return json.dumps(
- {"result": {str(k): str(v) for k, v in eigenvalues.items()}}
+ {"result": {str(k): str(v) for k, v in eigenvalues.items()}},
+ ensure_ascii=False,
)
except Exception as e:
return self.handle_exception("compute_eigenvalues", e)
@@ -676,7 +698,7 @@ class SymPyToolkit(BaseToolkit):
}
for eigenvalue, multiplicity, vectors in eigenvectors
]
- return json.dumps({"result": result})
+ return json.dumps({"result": result}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("compute_eigenvectors", e)
@@ -700,7 +722,9 @@ class SymPyToolkit(BaseToolkit):
try:
mat = sp.Matrix(matrix)
nullspace = mat.nullspace()
- return json.dumps({"result": [str(vec) for vec in nullspace]})
+ return json.dumps(
+ {"result": [str(vec) for vec in nullspace]}, ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("compute_nullspace", e)
@@ -722,7 +746,7 @@ class SymPyToolkit(BaseToolkit):
try:
mat = sp.Matrix(matrix)
rank = mat.rank()
- return json.dumps({"result": rank})
+ return json.dumps({"result": rank}, ensure_ascii=False)
except Exception as e:
return self.handle_exception("compute_rank", e)
@@ -759,7 +783,9 @@ class SymPyToolkit(BaseToolkit):
# Compute the dot (inner) product.
inner_product = v1.dot(v2)
- return json.dumps({"result": str(inner_product)})
+ return json.dumps(
+ {"result": str(inner_product)}, ensure_ascii=False
+ )
except Exception as e:
return self.handle_exception("compute_inner_product", e)
@@ -781,7 +807,8 @@ class SymPyToolkit(BaseToolkit):
"""
logger.error(f"Error in {func_name}: {error}")
return json.dumps(
- {"status": "error", "message": f"Error in {func_name}: {error}"}
+ {"status": "error", "message": f"Error in {func_name}: {error}"},
+ ensure_ascii=False,
)
def get_tools(self) -> List[FunctionTool]:
diff --git a/camel/types/enums.py b/camel/types/enums.py
index 27c9784d3..ada14dd7e 100644
--- a/camel/types/enums.py
+++ b/camel/types/enums.py
@@ -166,6 +166,7 @@ class ModelType(UnifiedModelType, Enum):
QWEN_2_5_14B = "qwen2.5-14b-instruct"
QWEN_QWQ_32B = "qwq-32b-preview"
QWEN_QVQ_72B = "qvq-72b-preview"
+ QWEN_QWQ_PLUS = "qwq-plus"
# Yi models (01-ai)
YI_LIGHTNING = "yi-lightning"
@@ -470,6 +471,7 @@ class ModelType(UnifiedModelType, Enum):
ModelType.QWEN_2_5_14B,
ModelType.QWEN_QWQ_32B,
ModelType.QWEN_QVQ_72B,
+ ModelType.QWEN_QWQ_PLUS,
}
@property
@@ -599,6 +601,7 @@ class ModelType(UnifiedModelType, Enum):
ModelType.NVIDIA_MISTRAL_LARGE,
ModelType.NVIDIA_MIXTRAL_8X7B,
ModelType.QWEN_QWQ_32B,
+ ModelType.QWEN_QWQ_PLUS,
ModelType.QWEN_QVQ_72B,
ModelType.INTERNLM3_8B_INSTRUCT,
ModelType.INTERNLM3_LATEST,
diff --git a/docs/conf.py b/docs/conf.py
index f88bfe87c..4758b8273 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -27,7 +27,7 @@ sys.path.insert(0, os.path.abspath('..'))
project = 'CAMEL'
copyright = '2024, CAMEL-AI.org'
author = 'CAMEL-AI.org'
-release = '0.2.30'
+release = '0.2.31'
html_favicon = (
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'
diff --git a/docs/key_modules/loaders.md b/docs/key_modules/loaders.md
index fb79b56e4..3ff7c5ffe 100644
--- a/docs/key_modules/loaders.md
+++ b/docs/key_modules/loaders.md
@@ -340,14 +340,14 @@ response = jina_reader.read_content("https://docs.camel-ai.org/")
print(response)
```
```markdown
->>>Welcome to CAMEL’s documentation! — CAMEL 0.2.30 documentation
+>>>Welcome to CAMEL’s documentation! — CAMEL 0.2.31 documentation
===============
[Skip to main content](https://docs.camel-ai.org/#main-content)
Back to top Ctrl+K
- [![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.30](https://docs.camel-ai.org/#)
+ [![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.31](https://docs.camel-ai.org/#)
Search Ctrl+K
diff --git a/examples/ai_society/role_playing_multiprocess.py b/examples/ai_society/role_playing_multiprocess.py
index c25c4d546..2690cfc6f 100644
--- a/examples/ai_society/role_playing_multiprocess.py
+++ b/examples/ai_society/role_playing_multiprocess.py
@@ -211,7 +211,7 @@ def generate_data(
with open(
f"./camel_data/ai_society/{message_dict['id']}.json", "w"
) as json_file:
- json.dump(message_dict, json_file)
+ json.dump(message_dict, json_file, ensure_ascii=False)
def generate_data_wrapper(args):
diff --git a/examples/code/role_playing_multiprocess.py b/examples/code/role_playing_multiprocess.py
index d6eda3ce0..7c36df145 100644
--- a/examples/code/role_playing_multiprocess.py
+++ b/examples/code/role_playing_multiprocess.py
@@ -225,7 +225,7 @@ def generate_data(
with open(
f"./camel_data/code/{message_dict['id']}.json", "w"
) as json_file:
- json.dump(message_dict, json_file)
+ json.dump(message_dict, json_file, ensure_ascii=False)
def main() -> None:
diff --git a/examples/data_collector/sharegpt_collector.py b/examples/data_collector/sharegpt_collector.py
index 5a12464dd..d6829be8b 100644
--- a/examples/data_collector/sharegpt_collector.py
+++ b/examples/data_collector/sharegpt_collector.py
@@ -46,8 +46,8 @@ collector = ShareGPTDataCollector().record(agent).start()
response = agent.step("Call tools to calculate 17 * 19 = ?")
-print(json.dumps(collector.convert(), indent=4))
-print(json.dumps(collector.llm_convert(), indent=4))
+print(json.dumps(collector.convert(), indent=4, ensure_ascii=False))
+print(json.dumps(collector.llm_convert(), indent=4, ensure_ascii=False))
print(collector.to_sharegpt_conversation(collector.convert()))
# ruff: noqa: E501
diff --git a/examples/deductive_reasoner_agent/deduce_conditions_and_quality.py b/examples/deductive_reasoner_agent/deduce_conditions_and_quality.py
index 6e2bc5a49..145261796 100644
--- a/examples/deductive_reasoner_agent/deduce_conditions_and_quality.py
+++ b/examples/deductive_reasoner_agent/deduce_conditions_and_quality.py
@@ -30,7 +30,8 @@ def main(model=None) -> None:
print(
Fore.GREEN
+ "Conditions and quality from the starting state:\n"
- + f"{json.dumps(conditions_and_quality, indent=4)}",
+ + f"{json.dumps(conditions_and_quality,
+ indent=4, ensure_ascii=False)}",
Fore.RESET,
)
diff --git a/examples/evaluation/single_agent.py b/examples/evaluation/single_agent.py
index 0dcb36c55..d9b49cb66 100644
--- a/examples/evaluation/single_agent.py
+++ b/examples/evaluation/single_agent.py
@@ -75,7 +75,7 @@ def generate_questions(
with open(f"{folder_path}/{save_file_name}.jsonl", "w") as f:
for item in parsed_assistant_msg:
- json.dump(item, f)
+ json.dump(item, f, ensure_ascii=False)
f.write('\n')
diff --git a/examples/generate_text_embedding_data/single_agent.py b/examples/generate_text_embedding_data/single_agent.py
index 81213b21c..f3f2692bb 100644
--- a/examples/generate_text_embedding_data/single_agent.py
+++ b/examples/generate_text_embedding_data/single_agent.py
@@ -81,7 +81,7 @@ def main() -> None:
data = json.loads(content)
os.makedirs("./text_embedding_data/tasks/", exist_ok=True)
with open(f"./text_embedding_data/tasks/{i}.json", "w") as f:
- json.dump(data, f, indent=4)
+ json.dump(data, f, indent=4, ensure_ascii=False)
except Exception as e:
print(f"Error raised during generation of task {task}", e)
diff --git a/examples/misalignment/role_playing_multiprocess.py b/examples/misalignment/role_playing_multiprocess.py
index d33428bd5..20673c3b1 100644
--- a/examples/misalignment/role_playing_multiprocess.py
+++ b/examples/misalignment/role_playing_multiprocess.py
@@ -202,7 +202,7 @@ def generate_data(
with open(
f"./camel_data/misalignment/{message_dict['id']}.json", "w"
) as json_file:
- json.dump(message_dict, json_file)
+ json.dump(message_dict, json_file, ensure_ascii=False)
def main() -> None:
diff --git a/examples/summarization/gpt_solution_extraction.py b/examples/summarization/gpt_solution_extraction.py
index 10c03607b..22c8940d9 100644
--- a/examples/summarization/gpt_solution_extraction.py
+++ b/examples/summarization/gpt_solution_extraction.py
@@ -148,7 +148,7 @@ def solution_extraction(
# Save new dictionary as JSON file
save_path = os.path.join(args.solution_dir, f'{file_name}.json')
with open(save_path, "w") as f:
- json.dump(conversation, f)
+ json.dump(conversation, f, ensure_ascii=False)
def main():
diff --git a/examples/summarization/gpt_solver.py b/examples/summarization/gpt_solver.py
index e19069f32..b5678cec8 100644
--- a/examples/summarization/gpt_solver.py
+++ b/examples/summarization/gpt_solver.py
@@ -46,7 +46,7 @@ def process_file(data: Dict[str, str]) -> None:
# save result as json file
with open(os.path.join(save_dir, data["id"] + ".json"), 'w') as f:
- json.dump(data, f)
+ json.dump(data, f, ensure_ascii=False)
def main():
diff --git a/pyproject.toml b/pyproject.toml
index 5f71f5f8d..110b8e3de 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "camel-ai"
-version = "0.2.30"
+version = "0.2.31"
description = "Communicative Agents for AI Society Study"
authors = [{ name = "CAMEL-AI.org" }]
requires-python = ">=3.10,<3.13"
diff --git a/test/datahubs/test_huggingface.py b/test/datahubs/test_huggingface.py
index 9b9187d6e..013837e3b 100644
--- a/test/datahubs/test_huggingface.py
+++ b/test/datahubs/test_huggingface.py
@@ -160,7 +160,7 @@ def test_update_records(manager):
mock_download.return_value = "/mock/path/records.json"
mock_open.return_value.__enter__.return_value.read.return_value = (
- json.dumps(existing_records)
+ json.dumps(existing_records, ensure_ascii=False)
)
manager.update_records(dataset_name=REPO_ID, records=new_records)
@@ -195,7 +195,7 @@ def test_list_records(manager):
):
mock_download.return_value = "/mock/path/records.json"
mock_open.return_value.__enter__.return_value.read.return_value = (
- json.dumps(mock_records)
+ json.dumps(mock_records, ensure_ascii=False)
)
records = manager.list_records(dataset_name=REPO_ID)
@@ -285,7 +285,10 @@ def test_delete_record(manager):
),
]
mock_open.return_value.__enter__.return_value.read.return_value = (
- json.dumps([record.model_dump() for record in existing_records])
+ json.dumps(
+ [record.model_dump() for record in existing_records],
+ ensure_ascii=False,
+ )
)
manager.delete_record(dataset_name=REPO_ID, record_id="record-1")
diff --git a/test/models/test_qwen_model.py b/test/models/test_qwen_model.py
index e2bdcc01e..9723120dc 100644
--- a/test/models/test_qwen_model.py
+++ b/test/models/test_qwen_model.py
@@ -41,6 +41,7 @@ from camel.types import ModelType
ModelType.QWEN_2_5_14B,
ModelType.QWEN_QWQ_32B,
ModelType.QWEN_QVQ_72B,
+ ModelType.QWEN_QWQ_PLUS,
],
)
def test_qwen_model(model_type: ModelType):
diff --git a/uv.lock b/uv.lock
index 450098dc0..991596d1a 100644
--- a/uv.lock
+++ b/uv.lock
@@ -510,7 +510,7 @@ wheels = [
[[package]]
name = "camel-ai"
-version = "0.2.30"
+version = "0.2.31"
source = { editable = "." }
dependencies = [
{ name = "colorama" },