feat: implement authentication check in image processing model

This commit is contained in:
wxg0103 2025-10-09 18:29:28 +08:00
parent 9c1177759a
commit e8a52c824a
2 changed files with 8 additions and 3 deletions

View File

@ -67,9 +67,7 @@ class QwenVLModelCredential(BaseForm, BaseModelCredential):
try:
model = provider.get_model(model_type, model_name, model_credential, **model_params)
res = model.stream([HumanMessage(content=[{"type": "text", "text": gettext('Hello')}])])
for chunk in res:
maxkb_logger.info(chunk)
model.check_auth(model_credential.get('api_key'))
except Exception as e:
traceback.print_exc()
if isinstance(e, AppApiException):

View File

@ -2,6 +2,9 @@
from typing import Dict
from langchain_community.chat_models import ChatTongyi
from langchain_core.messages import HumanMessage
from django.utils.translation import gettext
from models_provider.base_model_provider import MaxKBBaseModel
from models_provider.impl.base_chat_open_ai import BaseChatOpenAI
@ -25,3 +28,7 @@ class QwenVLChatModel(MaxKBBaseModel, BaseChatOpenAI):
extra_body=optional_params
)
return chat_tong_yi
def check_auth(self, api_key):
chat = ChatTongyi(api_key=api_key, model_name='qwen-max')
chat.invoke([HumanMessage([{"type": "text", "text": gettext('Hello')}])])