web.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # coding=utf-8
  2. """
  3. @project: MaxKB
  4. @Author:虎虎
  5. @file: web.py
  6. @date:2025/11/7 14:03
  7. @desc:
  8. """
  9. from typing import Dict
  10. import requests
  11. from django.utils.translation import gettext_lazy as _
  12. from common import forms
  13. from common.forms import BaseForm
  14. from maxkb.const import CONFIG
  15. from models_provider.base_model_provider import BaseModelCredential
  16. class LocalEmbeddingCredential(BaseForm, BaseModelCredential):
  17. def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
  18. raise_exception=False):
  19. bind = f'{CONFIG.get("LOCAL_MODEL_HOST")}:{CONFIG.get("LOCAL_MODEL_PORT")}'
  20. prefix = CONFIG.get_admin_path()
  21. res = requests.post(
  22. f'{CONFIG.get("LOCAL_MODEL_PROTOCOL")}://{bind}{prefix}/api/model/validate',
  23. json={'model_name': model_name, 'model_type': model_type, 'model_credential': model_credential})
  24. result = res.json()
  25. if result.get('code', 500) == 200:
  26. return result.get('data')
  27. raise Exception(result.get('message'))
  28. def encryption_dict(self, model: Dict[str, object]):
  29. return model
  30. cache_folder = forms.TextInputField(_('Model catalog'), required=True)