Skip to content

Commit 9de4218

Browse files
authored
feat: set ensure_ascii to false (#1494)
1 parent 4cfa6b1 commit 9de4218

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/ragas/dataset_schema.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ def _to_list(self) -> t.List[t.Dict]:
157157
for sample in rows:
158158
for item in sample["user_input"]:
159159
if not isinstance(item["content"], str):
160-
item["content"] = json.dumps(item["content"])
160+
item["content"] = json.dumps(
161+
item["content"], ensure_ascii=False
162+
)
161163

162164
return rows
163165

@@ -249,7 +251,7 @@ def to_jsonl(self, path: str):
249251
"""Converts the dataset to a JSONL file."""
250252
with open(path, "w") as jsonlfile:
251253
for sample in self.samples:
252-
jsonlfile.write(json.dumps(sample.to_dict()) + "\n")
254+
jsonlfile.write(json.dumps(sample.to_dict(), ensure_ascii=False) + "\n")
253255

254256
@classmethod
255257
def from_jsonl(cls, path: str):

src/ragas/metrics/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def required_columns(self, metric_type: MetricType, columns: t.Set[str]):
8888
def init(self, run_config: RunConfig): ...
8989

9090
@deprecated("0.2", removal="0.3", alternative="single_turn_ascore")
91-
def score(self: t.Self, row: t.Dict, callbacks: Callbacks = None) -> float:
91+
def score(self, row: t.Dict, callbacks: Callbacks = None) -> float:
9292
"""
9393
Calculates the score for a single row of data.
9494
@@ -121,7 +121,7 @@ def score(self: t.Self, row: t.Dict, callbacks: Callbacks = None) -> float:
121121

122122
@deprecated("0.2", removal="0.3", alternative="single_turn_ascore")
123123
async def ascore(
124-
self: t.Self,
124+
self,
125125
row: t.Dict,
126126
callbacks: Callbacks = None,
127127
timeout: t.Optional[float] = None,

src/ragas/prompt/pydantic_prompt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def __str__(self):
260260
"language": self.language,
261261
},
262262
indent=2,
263+
ensure_ascii=False,
263264
)[1:-1]
264265
return f"{self.__class__.__name__}({json_str})"
265266

@@ -315,7 +316,7 @@ def save(self, file_path: str):
315316
if os.path.exists(file_path):
316317
raise FileExistsError(f"The file '{file_path}' already exists.")
317318
with open(file_path, "w") as f:
318-
json.dump(data, f, indent=2)
319+
json.dump(data, f, indent=2, ensure_ascii=False)
319320
print(f"Prompt saved to {file_path}")
320321

321322
@classmethod

0 commit comments

Comments
 (0)