|
5 | 5 | from django.utils.translation import gettext as _ |
6 | 6 | from langchain_core.documents import Document |
7 | 7 |
|
| 8 | +from common import forms |
8 | 9 | from common.exception.app_exception import AppApiException |
9 | 10 | from common.forms import BaseForm, PasswordInputField |
10 | 11 | from models_provider.base_model_provider import BaseModelCredential, ValidCode |
11 | 12 | from models_provider.impl.aliyun_bai_lian_model_provider.model.reranker import AliyunBaiLianReranker |
12 | 13 | from common.utils.logger import maxkb_logger |
13 | 14 |
|
| 15 | + |
14 | 16 | class AliyunBaiLianRerankerCredential(BaseForm, BaseModelCredential): |
15 | 17 | """ |
16 | 18 | Credential class for the Aliyun BaiLian Reranker model. |
17 | 19 | Provides validation and encryption for the model credentials. |
18 | 20 | """ |
19 | | - |
| 21 | + api_base = forms.TextInputField(_('API URL'), required=True, |
| 22 | + default_value='https://dashscope.aliyuncs.com/compatible-mode/v1') |
20 | 23 | dashscope_api_key = PasswordInputField('API Key', required=True) |
21 | 24 |
|
22 | 25 | def is_valid( |
23 | | - self, |
24 | | - model_type: str, |
25 | | - model_name: str, |
26 | | - model_credential: Dict[str, Any], |
27 | | - model_params: Dict[str, Any], |
28 | | - provider, |
29 | | - raise_exception: bool = False |
| 26 | + self, |
| 27 | + model_type: str, |
| 28 | + model_name: str, |
| 29 | + model_credential: Dict[str, Any], |
| 30 | + model_params: Dict[str, Any], |
| 31 | + provider, |
| 32 | + raise_exception: bool = False |
30 | 33 | ) -> bool: |
31 | 34 | """ |
32 | 35 | Validate the model credentials. |
@@ -65,7 +68,8 @@ def is_valid( |
65 | 68 | if raise_exception: |
66 | 69 | raise AppApiException( |
67 | 70 | ValidCode.valid_error.value, |
68 | | - _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)) |
| 71 | + _('Verification failed, please check whether the parameters are correct: {error}').format( |
| 72 | + error=str(e)) |
69 | 73 | ) |
70 | 74 | return False |
71 | 75 |
|
|
0 commit comments