Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: read file encoding error (#1902)

newsouther0e239a4f719a
diff --git a/api/core/extension/extensible.py b/api/core/extension/extensible.py
index 2e879578bf7..6b27062f13f 100644
--- a/api/core/extension/extensible.py
+++ b/api/core/extension/extensible.py
@@ -61,7 +61,7 @@ class Extensible:
builtin_file_path = os.path.join(subdir_path, '__builtin__')
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())
if (extension_name + '.py') not in file_names:
@@ -93,7 +93,7 @@ class Extensible:
json_path = os.path.join(subdir_path, 'schema.json')
json_data = {}
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)
extensions[extension_name] = ModuleExtension(
diff --git a/api/core/model_runtime/model_providers/__base/ai_model.py b/api/core/model_runtime/model_providers/__base/ai_model.py
index e0b1796da73..c5b726237ff 100644
--- a/api/core/model_runtime/model_providers/__base/ai_model.py
+++ b/api/core/model_runtime/model_providers/__base/ai_model.py
@@ -147,13 +147,13 @@ class AIModel(ABC):
# read _position.yaml file
position_map = {}
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)
# traverse all model_schema_yaml_paths
for model_schema_yaml_path in model_schema_yaml_paths:
# 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)
new_parameter_rules = []
diff --git a/api/core/model_runtime/model_providers/__base/model_provider.py b/api/core/model_runtime/model_providers/__base/model_provider.py
index 71d4a0c5d6b..19fff3a39b0 100644
--- a/api/core/model_runtime/model_providers/__base/model_provider.py
+++ b/api/core/model_runtime/model_providers/__base/model_provider.py
@@ -47,7 +47,7 @@ class ModelProvider(ABC):
yaml_path = os.path.join(current_path, f'{provider_name}.yaml')
yaml_data = {}
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)
try:
diff --git a/api/core/model_runtime/model_providers/model_provider_factory.py b/api/core/model_runtime/model_providers/model_provider_factory.py
index 2f13f528025..ad6e7854354 100644
--- a/api/core/model_runtime/model_providers/model_provider_factory.py
+++ b/api/core/model_runtime/model_providers/model_provider_factory.py
@@ -212,7 +212,7 @@ class ModelProviderFactory:
# read _position.yaml file
position_map = {}
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)
# traverse all model_provider_dir_paths
diff --git a/api/core/prompt/prompt_transform.py b/api/core/prompt/prompt_transform.py
index fc92db93555..67ee507627f 100644
--- a/api/core/prompt/prompt_transform.py
+++ b/api/core/prompt/prompt_transform.py
@@ -207,7 +207,7 @@ class PromptTransform:
json_file_path = os.path.join(prompt_path, f'{prompt_name}.json')
# 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)
def _get_simple_chat_app_chat_model_prompt_messages(self, prompt_rules: dict,