Skip to content

Commit e8a52c8

Browse files
committed
feat: implement authentication check in image processing model
1 parent 9c11777 commit e8a52c8

File tree

2 files changed

+8
-3
lines changed
  • apps/models_provider/impl/aliyun_bai_lian_model_provider

2 files changed

+8
-3
lines changed

apps/models_provider/impl/aliyun_bai_lian_model_provider/credential/image.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def is_valid(
6767

6868
try:
6969
model = provider.get_model(model_type, model_name, model_credential, **model_params)
70-
res = model.stream([HumanMessage(content=[{"type": "text", "text": gettext('Hello')}])])
71-
for chunk in res:
72-
maxkb_logger.info(chunk)
70+
model.check_auth(model_credential.get('api_key'))
7371
except Exception as e:
7472
traceback.print_exc()
7573
if isinstance(e, AppApiException):

apps/models_provider/impl/aliyun_bai_lian_model_provider/model/image.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from typing import Dict
44

5+
from langchain_community.chat_models import ChatTongyi
6+
from langchain_core.messages import HumanMessage
7+
from django.utils.translation import gettext
58
from models_provider.base_model_provider import MaxKBBaseModel
69
from models_provider.impl.base_chat_open_ai import BaseChatOpenAI
710

@@ -25,3 +28,7 @@ def new_instance(model_type, model_name, model_credential: Dict[str, object], **
2528
extra_body=optional_params
2629
)
2730
return chat_tong_yi
31+
32+
def check_auth(self, api_key):
33+
chat = ChatTongyi(api_key=api_key, model_name='qwen-max')
34+
chat.invoke([HumanMessage([{"type": "text", "text": gettext('Hello')}])])

0 commit comments

Comments
 (0)