Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: The Chinese characters in the form data have been transcoded #2192

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def execute(self, form_field_list, form_content_format, form_data, **kwargs) ->
form_setting = {"form_field_list": form_field_list, "runtime_node_id": self.runtime_node_id,
"chat_record_id": self.flow_params_serializer.data.get("chat_record_id"),
"is_submit": self.context.get("is_submit", False)}
form = f'<form_rander>{json.dumps(form_setting)}</form_rander>'
form = f'<form_rander>{json.dumps(form_setting, ensure_ascii=False)}</form_rander>'
context = self.workflow_manage.get_workflow_content()
form_content_format = self.workflow_manage.reset_prompt(form_content_format)
prompt_template = PromptTemplate.from_template(form_content_format, template_format='jinja2')
Expand All @@ -70,7 +70,7 @@ def get_answer_list(self) -> List[Answer] | None:
"chat_record_id": self.flow_params_serializer.data.get("chat_record_id"),
'form_data': self.context.get('form_data', {}),
"is_submit": self.context.get("is_submit", False)}
form = f'<form_rander>{json.dumps(form_setting)}</form_rander>'
form = f'<form_rander>{json.dumps(form_setting,ensure_ascii=False)}</form_rander>'
context = self.workflow_manage.get_workflow_content()
form_content_format = self.workflow_manage.reset_prompt(form_content_format)
prompt_template = PromptTemplate.from_template(form_content_format, template_format='jinja2')
Expand All @@ -85,7 +85,7 @@ def get_details(self, index: int, **kwargs):
"chat_record_id": self.flow_params_serializer.data.get("chat_record_id"),
'form_data': self.context.get('form_data', {}),
"is_submit": self.context.get("is_submit", False)}
form = f'<form_rander>{json.dumps(form_setting)}</form_rander>'
form = f'<form_rander>{json.dumps(form_setting,ensure_ascii=False)}</form_rander>'
context = self.workflow_manage.get_workflow_content()
form_content_format = self.workflow_manage.reset_prompt(form_content_format)
prompt_template = PromptTemplate.from_template(form_content_format, template_format='jinja2')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code has minor issues that can be resolved. Here’s a detailed explanation of the changes needed:

File file_name.py

-        form = f'<form_rander>{json.dumps(form_setting)}</form_rander>'
+        form = f'<form_rander>{json.dumps(form_setting, ensure_ascii=False)}</form_rander>'

Explanation: The ensure_ascii=False parameter is necessary when you want to serialize JSON data with non-ASCII characters properly. If ensure_ascii=True, special characters might not be converted correctly.


General Suggestion

Ensure that within this file (file_name.py) and throughout all related files:

  • Always import necessary modules at the beginning.
  • Use meaningful variable names instead of short ones (e.g., replace context with workflow_context).
  • Ensure there are no typos or unnecessary functions/data structures.
  • Consider adding docstrings if your methods/actions do not have clear descriptions.

If you need further help or modifications, please specify!

Expand Down