From 53cd125780cfe93db45dc0419cd5cc919f7eb8d5 Mon Sep 17 00:00:00 2001 From: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:27:00 +0800 Subject: [PATCH] fix: deep copy of model-tool label (#2775) --- .../tools/provider/model_tool_provider.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/api/core/tools/provider/model_tool_provider.py b/api/core/tools/provider/model_tool_provider.py index 733b2fd02a3f55..ef47e9aae97afa 100644 --- a/api/core/tools/provider/model_tool_provider.py +++ b/api/core/tools/provider/model_tool_provider.py @@ -1,3 +1,4 @@ +from copy import deepcopy from typing import Any from core.entities.model_entities import ModelStatus @@ -59,10 +60,16 @@ def from_db(configuration: ProviderConfiguration = None) -> 'ModelToolProviderCo # override the configuration if model_tool_configuration.label: - if model_tool_configuration.label.en_US: - configuration.provider.label.en_US = model_tool_configuration.label.en_US - if model_tool_configuration.label.zh_Hans: - configuration.provider.label.zh_Hans = model_tool_configuration.label.zh_Hans + label = deepcopy(model_tool_configuration.label) + if label.en_US: + label.en_US = model_tool_configuration.label.en_US + if label.zh_Hans: + label.zh_Hans = model_tool_configuration.label.zh_Hans + else: + label = I18nObject( + en_US=configuration.provider.label.en_US, + zh_Hans=configuration.provider.label.zh_Hans + ) return ModelToolProviderController( is_active=is_active, @@ -70,12 +77,12 @@ def from_db(configuration: ProviderConfiguration = None) -> 'ModelToolProviderCo author='Dify', name=configuration.provider.provider, description=I18nObject( - zh_Hans=f'{configuration.provider.label.zh_Hans} 模型能力提供商', - en_US=f'{configuration.provider.label.en_US} model capability provider' + zh_Hans=f'{label.zh_Hans} 模型能力提供商', + en_US=f'{label.en_US} model capability provider' ), label=I18nObject( - zh_Hans=configuration.provider.label.zh_Hans, - en_US=configuration.provider.label.en_US + zh_Hans=label.zh_Hans, + en_US=label.en_US ), icon=configuration.provider.icon_small.en_US, ),