Unverified Commit 0e239a4f authored by newsouther's avatar newsouther Committed by GitHub

fix: read file encoding error (#1902)

Co-authored-by: 's avatarmaple <1071520@gi>
parent ca85b0af
...@@ -61,7 +61,7 @@ class Extensible: ...@@ -61,7 +61,7 @@ class Extensible:
builtin_file_path = os.path.join(subdir_path, '__builtin__') builtin_file_path = os.path.join(subdir_path, '__builtin__')
if os.path.exists(builtin_file_path): if os.path.exists(builtin_file_path):
with open(builtin_file_path, 'r') as f: with open(builtin_file_path, 'r', encoding='utf-8') as f:
position = int(f.read().strip()) position = int(f.read().strip())
if (extension_name + '.py') not in file_names: if (extension_name + '.py') not in file_names:
...@@ -93,7 +93,7 @@ class Extensible: ...@@ -93,7 +93,7 @@ class Extensible:
json_path = os.path.join(subdir_path, 'schema.json') json_path = os.path.join(subdir_path, 'schema.json')
json_data = {} json_data = {}
if os.path.exists(json_path): if os.path.exists(json_path):
with open(json_path, 'r') as f: with open(json_path, 'r', encoding='utf-8') as f:
json_data = json.load(f) json_data = json.load(f)
extensions[extension_name] = ModuleExtension( extensions[extension_name] = ModuleExtension(
......
...@@ -147,13 +147,13 @@ class AIModel(ABC): ...@@ -147,13 +147,13 @@ class AIModel(ABC):
# read _position.yaml file # read _position.yaml file
position_map = {} position_map = {}
if os.path.exists(position_file_path): if os.path.exists(position_file_path):
with open(position_file_path, 'r') as f: with open(position_file_path, 'r', encoding='utf-8') as f:
position_map = yaml.safe_load(f) position_map = yaml.safe_load(f)
# traverse all model_schema_yaml_paths # traverse all model_schema_yaml_paths
for model_schema_yaml_path in model_schema_yaml_paths: for model_schema_yaml_path in model_schema_yaml_paths:
# read yaml data from yaml file # read yaml data from yaml file
with open(model_schema_yaml_path, 'r') as f: with open(model_schema_yaml_path, 'r', encoding='utf-8') as f:
yaml_data = yaml.safe_load(f) yaml_data = yaml.safe_load(f)
new_parameter_rules = [] new_parameter_rules = []
......
...@@ -47,7 +47,7 @@ class ModelProvider(ABC): ...@@ -47,7 +47,7 @@ class ModelProvider(ABC):
yaml_path = os.path.join(current_path, f'{provider_name}.yaml') yaml_path = os.path.join(current_path, f'{provider_name}.yaml')
yaml_data = {} yaml_data = {}
if os.path.exists(yaml_path): if os.path.exists(yaml_path):
with open(yaml_path, 'r') as f: with open(yaml_path, 'r', encoding='utf-8') as f:
yaml_data = yaml.safe_load(f) yaml_data = yaml.safe_load(f)
try: try:
......
...@@ -212,7 +212,7 @@ class ModelProviderFactory: ...@@ -212,7 +212,7 @@ class ModelProviderFactory:
# read _position.yaml file # read _position.yaml file
position_map = {} position_map = {}
if os.path.exists(position_file_path): if os.path.exists(position_file_path):
with open(position_file_path, 'r') as f: with open(position_file_path, 'r', encoding='utf-8') as f:
position_map = yaml.safe_load(f) position_map = yaml.safe_load(f)
# traverse all model_provider_dir_paths # traverse all model_provider_dir_paths
......
...@@ -207,7 +207,7 @@ class PromptTransform: ...@@ -207,7 +207,7 @@ class PromptTransform:
json_file_path = os.path.join(prompt_path, f'{prompt_name}.json') json_file_path = os.path.join(prompt_path, f'{prompt_name}.json')
# Open the JSON file and read its content # Open the JSON file and read its content
with open(json_file_path, 'r') as json_file: with open(json_file_path, 'r', encoding='utf-8') as json_file:
return json.load(json_file) return json.load(json_file)
def _get_simple_chat_app_chat_model_prompt_messages(self, prompt_rules: dict, def _get_simple_chat_app_chat_model_prompt_messages(self, prompt_rules: dict,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment