Skip to content

Commit d74be96

Browse files
authored
Fixed an issue where non-ASCII characters were changed to Unicode characters within the prompt (#1490)
- There is an issue where non-ASCII characters are converted to Unicode characters within the prompt. - Due to this issue, Users that use non-English characters will receive an abnormal response when communicating with LLM. - This issue can be resolved by adding the ensure_ascii=False option when using the json.dumps function.
1 parent 1cc92da commit d74be96

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/ragas/llms/output_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get_json_format_instructions(pydantic_object: t.Type[TBaseModel]) -> str:
4747
if "title" in reduced_schema:
4848
del reduced_schema["title"]
4949
# Ensure json in context is well-formed with double quotes.
50-
schema_str = json.dumps(reduced_schema)
50+
schema_str = json.dumps(reduced_schema, ensure_ascii=False)
5151

5252
resp = JSON_FORMAT_INSTRUCTIONS.format(schema=schema_str)
5353
return resp

src/ragas/llms/prompt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def format(self, **kwargs: t.Any) -> PromptValue:
160160
)
161161
for key, value in kwargs.items():
162162
if isinstance(value, str):
163-
kwargs[key] = json.dumps(value)
163+
kwargs[key] = json.dumps(value, ensure_ascii=False).encode("utf8").decode()
164164

165165
prompt = self.to_string()
166166
return PromptValue(prompt_str=prompt.format(**kwargs))

0 commit comments

Comments
 (0)