Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -40,7 +40,7 @@ def __init__(self, ai_model_path: str, **kwargs) -> None:
raise ImportError("onnxruntime-genai is not installed.")
try:
json_gen_ai_config = os.path.join(ai_model_path + "/genai_config.json")
with open(json_gen_ai_config) as file:
with open(json_gen_ai_config, encoding="utf-8") as file:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added in 3fb8d30: test_onnx_config_is_read_as_utf8 in python/tests/unit/connectors/ai/onnx/services/test_onnx_chat_completion.py.

It filters open.call_args_list down to the genai_config.json call and asserts call.kwargs.get('encoding') == 'utf-8' on every one of them, so removing the explicit encoding fails the assertion rather than passing silently.

config: dict = json.load(file)
enable_multi_modality = "vision" in config.get("model", {})
model = OnnxRuntimeGenAi.Model(ai_model_path)
Expand Down
4 changes: 2 additions & 2 deletions python/semantic_kernel/contents/chat_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def store_chat_history_to_file(self, file_path: str) -> None:
file_path: The path to the file where the serialized data will be stored.
"""
json_str = self.serialize()
with open(file_path, "w") as local_file:
with open(file_path, "w", encoding="utf-8") as local_file:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added in 3fb8d30: test_chat_history_file_round_trip_keeps_non_ascii in python/tests/unit/contents/test_chat_history.py.

It stores héllo — 世界 and then asserts on bytes: 'héllo — 世界'.encode() in file_path.read_bytes(). Reading through read_text() would round-trip under any single-byte codec and prove nothing; the byte comparison is what fails when the encoding='utf-8' on the write is removed on a host whose default is not UTF-8.

local_file.write(json_str)

@classmethod
Expand All @@ -442,6 +442,6 @@ def load_chat_history_from_file(cls: type[_T], file_path: str) -> _T:
Returns:
ChatHistory: The deserialized ChatHistory instance.
"""
with open(file_path) as file:
with open(file_path, encoding="utf-8") as file:
json_str = file.read()
return cls.restore_chat_history(json_str)
Loading