Skip to content

Commit 1d35700

Browse files
committed
refactor: enhance model retrieval logic and update optional parameters
1 parent f186b25 commit 1d35700

File tree

4 files changed

+19
-28
lines changed

4 files changed

+19
-28
lines changed

apps/application/chat_pipeline/step/search_dataset_step/impl/base_search_dataset_step.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929

3030
def get_model_by_id(_id, workspace_id):
31-
model = QuerySet(Model).filter(id=_id, model_type="EMBEDDING").first()
31+
model = QuerySet(Model).filter(id=_id, model_type="EMBEDDING")
32+
get_authorized_model = DatabaseModelManage.get_model("get_authorized_model")
33+
if get_authorized_model is not None:
34+
model = get_authorized_model(model, workspace_id)
3235
if model is None:
3336
raise Exception(_("Model does not exist"))
34-
if model.workspace_id is not None:
35-
if model.workspace_id != workspace_id:
36-
raise Exception(_("Model does not exist"))
3737
return model
3838

3939

apps/models_provider/base_model_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def is_cache_model():
9999
def filter_optional_params(model_kwargs):
100100
optional_params = {}
101101
for key, value in model_kwargs.items():
102-
if key not in ['model_id', 'use_local', 'streaming', 'show_ref_label']:
102+
if key not in ['model_id', 'use_local', 'streaming', 'show_ref_label', 'stream']:
103103
if key == 'extra_body' and isinstance(value, dict):
104104
optional_params = {**optional_params, **value}
105105
else:

apps/models_provider/impl/wenxin_model_provider/wenxin_model_provider.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,10 @@
2929
ModelInfo('ERNIE-Bot-turbo',
3030
_('ERNIE-Bot-turbo is a large language model independently developed by Baidu. It covers massive Chinese data, has stronger capabilities in dialogue Q&A, content creation and generation, and has a faster response speed.'),
3131
ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
32-
ModelInfo('BLOOMZ-7B',
33-
_('BLOOMZ-7B is a well-known large language model in the industry. It was developed and open sourced by BigScience and can output text in 46 languages and 13 programming languages.'),
34-
ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
35-
ModelInfo('Llama-2-7b-chat',
36-
'Llama-2-7b-chat was developed by Meta AI and is open source. It performs well in scenarios such as coding, reasoning and knowledge application. Llama-2-7b-chat is a high-performance native open source version suitable for conversation scenarios.',
37-
ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
38-
ModelInfo('Llama-2-13b-chat',
39-
_('Llama-2-13b-chat was developed by Meta AI and is open source. It performs well in scenarios such as coding, reasoning and knowledge application. Llama-2-13b-chat is a native open source version with balanced performance and effect, suitable for conversation scenarios.'),
40-
ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
41-
ModelInfo('Llama-2-70b-chat',
42-
_('Llama-2-70b-chat was developed by Meta AI and is open source. It performs well in scenarios such as coding, reasoning, and knowledge application. Llama-2-70b-chat is a native open source version with high-precision effects.'),
43-
ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
44-
ModelInfo('Qianfan-Chinese-Llama-2-7B',
45-
_('The Chinese enhanced version developed by the Qianfan team based on Llama-2-7b has performed well on Chinese knowledge bases such as CMMLU and C-EVAL.'),
32+
ModelInfo('qianfan-chinese-llama-2-13b',
33+
'',
4634
ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel)
35+
4736
]
4837
embedding_model_info = ModelInfo('Embedding-V1',
4938
_('Embedding-V1 is a text representation model based on Baidu Wenxin large model technology. It can convert text into a vector form represented by numerical values and can be used in text retrieval, information recommendation, knowledge mining and other scenarios. Embedding-V1 provides the Embeddings interface, which can generate corresponding vector representations based on input content. You can call this interface to input text into the model and obtain the corresponding vector representation for subsequent text processing and analysis.'),
@@ -63,6 +52,8 @@ def get_model_info_manage(self):
6352
return model_info_manage
6453

6554
def get_model_provide_info(self):
66-
return ModelProvideInfo(provider='model_wenxin_provider', name=_('Thousand sails large model'), icon=get_file_content(
67-
os.path.join(PROJECT_DIR, "apps", 'models_provider', 'impl', 'wenxin_model_provider', 'icon',
68-
'azure_icon_svg')))
55+
return ModelProvideInfo(provider='model_wenxin_provider', name=_('Thousand sails large model'),
56+
icon=get_file_content(
57+
os.path.join(PROJECT_DIR, "apps", 'models_provider', 'impl',
58+
'wenxin_model_provider', 'icon',
59+
'azure_icon_svg')))

apps/models_provider/tools.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.db.models import QuerySet
1111

1212
from common.config.embedding_config import ModelManage
13+
from common.database_model_manage.database_model_manage import DatabaseModelManage
1314
from models_provider.models import Model
1415
from django.utils.translation import gettext_lazy as _
1516

@@ -104,13 +105,12 @@ def is_valid_credential(provider, model_type, model_name, model_credential: Dict
104105

105106

106107
def get_model_by_id(_id, workspace_id):
107-
model = QuerySet(Model).filter(id=_id).first()
108+
model = QuerySet(Model).filter(id=_id)
109+
get_authorized_model = DatabaseModelManage.get_model("get_authorized_model")
110+
if get_authorized_model is not None:
111+
model = get_authorized_model(model, workspace_id)
108112
if model is None:
109-
raise Exception(_('Model does not exist'))
110-
if model.workspace_id:
111-
if model.workspace_id != workspace_id:
112-
raise Exception(_('Model does not exist'))
113-
113+
raise Exception(_("Model does not exist"))
114114
return model
115115

116116

0 commit comments

Comments
 (0)