fix: model i18n error (#2055)
parent
1389c581b7
commit
d9c6b6bdb6
|
|
@ -9,19 +9,20 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
import importlib
|
import importlib
|
||||||
import io
|
import io
|
||||||
|
import mimetypes
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import mimetypes
|
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from django.core.files.uploadedfile import InMemoryUploadedFile
|
from django.core.files.uploadedfile import InMemoryUploadedFile
|
||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
from pydub import AudioSegment
|
from pydub import AudioSegment
|
||||||
|
|
||||||
from ..exception.app_exception import AppApiException
|
from ..exception.app_exception import AppApiException
|
||||||
from ..models.db_model_manage import DBModelManage
|
from ..models.db_model_manage import DBModelManage
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
def sub_array(array: List, item_num=10):
|
def sub_array(array: List, item_num=10):
|
||||||
result = []
|
result = []
|
||||||
|
|
@ -215,9 +216,9 @@ def split_and_transcribe(file_path, model, max_segment_length_ms=59000, audio_fo
|
||||||
|
|
||||||
def _remove_empty_lines(text):
|
def _remove_empty_lines(text):
|
||||||
if not isinstance(text, str):
|
if not isinstance(text, str):
|
||||||
raise AppApiException(500, _('Text-to-speech node, the text content must be of string type'))
|
raise AppApiException(500, __('Text-to-speech node, the text content must be of string type'))
|
||||||
if not text:
|
if not text:
|
||||||
raise AppApiException(500, _('Text-to-speech node, the text content cannot be empty'))
|
raise AppApiException(500, __('Text-to-speech node, the text content cannot be empty'))
|
||||||
result = '\n'.join(line for line in text.split('\n') if line.strip())
|
result = '\n'.join(line for line in text.split('\n') if line.strip())
|
||||||
return markdown_to_plain_text(result)
|
return markdown_to_plain_text(result)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,13 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import ValidCode, BaseModelCredential
|
from setting.models_provider.base_model_provider import ValidCode, BaseModelCredential
|
||||||
from setting.models_provider.impl.aliyun_bai_lian_model_provider.model.embedding import AliyunBaiLianEmbedding
|
from setting.models_provider.impl.aliyun_bai_lian_model_provider.model.embedding import AliyunBaiLianEmbedding
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class AliyunBaiLianEmbeddingCredential(BaseForm, BaseModelCredential):
|
class AliyunBaiLianEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -23,21 +24,23 @@ class AliyunBaiLianEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['dashscope_api_key']:
|
for key in ['dashscope_api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model: AliyunBaiLianEmbedding = provider.get_model(model_type, model_name, model_credential)
|
model: AliyunBaiLianEmbedding = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,15 @@
|
||||||
@date:2024/7/11 18:41
|
@date:2024/7/11 18:41
|
||||||
@desc:
|
@desc:
|
||||||
"""
|
"""
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class QwenModelParams(BaseForm):
|
class QwenModelParams(BaseForm):
|
||||||
|
|
@ -45,11 +43,11 @@ class QwenVLModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -62,7 +60,7 @@ class QwenVLModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class BaiLianLLMModelParams(BaseForm):
|
class BaiLianLLMModelParams(BaseForm):
|
||||||
|
|
@ -36,23 +36,23 @@ class BaiLianLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
model.invoke([HumanMessage(content=_('Hello'))])
|
model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
|
|
@ -15,7 +16,6 @@ from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from setting.models_provider.impl.aliyun_bai_lian_model_provider.model.reranker import AliyunBaiLianReranker
|
from setting.models_provider.impl.aliyun_bai_lian_model_provider.model.reranker import AliyunBaiLianReranker
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class AliyunBaiLianRerankerCredential(BaseForm, BaseModelCredential):
|
class AliyunBaiLianRerankerCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -24,22 +24,22 @@ class AliyunBaiLianRerankerCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
if not model_type == 'RERANKER':
|
if not model_type == 'RERANKER':
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['dashscope_api_key']:
|
for key in ['dashscope_api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model: AliyunBaiLianReranker = provider.get_model(model_type, model_name, model_credential)
|
model: AliyunBaiLianReranker = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.compress_documents([Document(page_content=_('Hello'))], _('Hello'))
|
model.compress_documents([Document(page_content=__('Hello'))], __('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class AliyunBaiLianSTTModelCredential(BaseForm, BaseModelCredential):
|
class AliyunBaiLianSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -17,12 +18,12 @@ class AliyunBaiLianSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -33,7 +34,7 @@ class AliyunBaiLianSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class QwenModelParams(BaseForm):
|
class QwenModelParams(BaseForm):
|
||||||
|
|
@ -63,11 +64,11 @@ class QwenTextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -79,7 +80,7 @@ class QwenTextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class AliyunBaiLianTTSModelGeneralParams(BaseForm):
|
class AliyunBaiLianTTSModelGeneralParams(BaseForm):
|
||||||
|
|
@ -51,12 +51,12 @@ class AliyunBaiLianTTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -67,7 +67,7 @@ class AliyunBaiLianTTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,13 @@ from http import HTTPStatus
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from dashscope import ImageSynthesis
|
from dashscope import ImageSynthesis
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
from langchain_community.chat_models import ChatTongyi
|
from langchain_community.chat_models import ChatTongyi
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_tti import BaseTextToImage
|
from setting.models_provider.impl.base_tti import BaseTextToImage
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class QwenTextToImageModel(MaxKBBaseModel, BaseTextToImage):
|
class QwenTextToImageModel(MaxKBBaseModel, BaseTextToImage):
|
||||||
api_key: str
|
api_key: str
|
||||||
|
|
@ -39,7 +40,7 @@ class QwenTextToImageModel(MaxKBBaseModel, BaseTextToImage):
|
||||||
|
|
||||||
def check_auth(self):
|
def check_auth(self):
|
||||||
chat = ChatTongyi(api_key=self.api_key, model_name='qwen-max')
|
chat = ChatTongyi(api_key=self.api_key, model_name='qwen-max')
|
||||||
chat.invoke([HumanMessage([{"type": "text", "text": _('Hello')}])])
|
chat.invoke([HumanMessage([{"type": "text", "text": __('Hello')}])])
|
||||||
|
|
||||||
def generate_image(self, prompt: str, negative_prompt: str = None):
|
def generate_image(self, prompt: str, negative_prompt: str = None):
|
||||||
# api_base='https://dashscope.aliyuncs.com/compatible-mode/v1',
|
# api_base='https://dashscope.aliyuncs.com/compatible-mode/v1',
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@ from typing import Dict
|
||||||
|
|
||||||
import dashscope
|
import dashscope
|
||||||
from dashscope.audio.tts_v2 import *
|
from dashscope.audio.tts_v2 import *
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common.util.common import _remove_empty_lines
|
from common.util.common import _remove_empty_lines
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class AliyunBaiLianTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
class AliyunBaiLianTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
||||||
api_key: str
|
api_key: str
|
||||||
|
|
@ -33,7 +34,7 @@ class AliyunBaiLianTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_auth(self):
|
def check_auth(self):
|
||||||
self.text_to_speech(_('Hello'))
|
self.text_to_speech(__('Hello'))
|
||||||
|
|
||||||
def text_to_speech(self, text):
|
def text_to_speech(self, text):
|
||||||
dashscope.api_key = self.api_key
|
dashscope.api_key = self.api_key
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class AnthropicImageModelParams(BaseForm):
|
class AnthropicImageModelParams(BaseForm):
|
||||||
|
|
@ -39,12 +39,13 @@ class AnthropicImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -56,7 +57,8 @@ class AnthropicImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class AnthropicLLMModelParams(BaseForm):
|
class AnthropicLLMModelParams(BaseForm):
|
||||||
|
|
@ -43,23 +43,23 @@ class AnthropicLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.invoke([HumanMessage(content=_('Hello'))])
|
model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
import os
|
|
||||||
import re
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from setting.models_provider.impl.aws_bedrock_model_provider.model.embedding import BedrockEmbeddingModel
|
from setting.models_provider.impl.aws_bedrock_model_provider.model.embedding import BedrockEmbeddingModel
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class BedrockEmbeddingCredential(BaseForm, BaseModelCredential):
|
class BedrockEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -17,24 +16,29 @@ class BedrockEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(mt.get('value') == model_type for mt in model_type_list):
|
if not any(mt.get('value') == model_type for mt in model_type_list):
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
required_keys = ['region_name', 'access_key_id', 'secret_access_key']
|
required_keys = ['region_name', 'access_key_id', 'secret_access_key']
|
||||||
if not all(key in model_credential for key in required_keys):
|
if not all(key in model_credential for key in required_keys):
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('The following fields are required: {keys}').format(keys=", ".join(required_keys)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('The following fields are required: {keys}').format(
|
||||||
|
keys=", ".join(required_keys)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
model: BedrockEmbeddingModel = provider.get_model(model_type, model_name, model_credential)
|
model: BedrockEmbeddingModel = provider.get_model(model_type, model_name, model_credential)
|
||||||
aa = model.embed_query(_('Hello'))
|
aa = model.embed_query(__('Hello'))
|
||||||
print(aa)
|
print(aa)
|
||||||
except AppApiException:
|
except AppApiException:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import ValidCode, BaseModelCredential
|
from setting.models_provider.base_model_provider import ValidCode, BaseModelCredential
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class BedrockLLMModelParams(BaseForm):
|
class BedrockLLMModelParams(BaseForm):
|
||||||
|
|
@ -36,14 +36,14 @@ class BedrockLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
if not any(mt.get('value') == model_type for mt in model_type_list):
|
if not any(mt.get('value') == model_type for mt in model_type_list):
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
required_keys = ['region_name', 'access_key_id', 'secret_access_key']
|
required_keys = ['region_name', 'access_key_id', 'secret_access_key']
|
||||||
if not all(key in model_credential for key in required_keys):
|
if not all(key in model_credential for key in required_keys):
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('The following fields are required: {keys}').format(
|
__('The following fields are required: {keys}').format(
|
||||||
keys=", ".join(required_keys)))
|
keys=", ".join(required_keys)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ class BedrockLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class AzureOpenAIEmbeddingCredential(BaseForm, BaseModelCredential):
|
class AzureOpenAIEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -22,23 +23,23 @@ class AzureOpenAIEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key', 'api_version']:
|
for key in ['api_base', 'api_key', 'api_version']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct'))
|
__('Verification failed, please check whether the parameters are correct'))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class AzureOpenAIImageModelParams(BaseForm):
|
class AzureOpenAIImageModelParams(BaseForm):
|
||||||
|
|
@ -41,12 +41,12 @@ class AzureOpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key', 'api_version']:
|
for key in ['api_base', 'api_key', 'api_version']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -59,7 +59,7 @@ class AzureOpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class AzureLLMModelParams(BaseForm):
|
class AzureLLMModelParams(BaseForm):
|
||||||
|
|
@ -43,12 +43,12 @@ class AzureLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key', 'deployment_name', 'api_version']:
|
for key in ['api_base', 'api_key', 'deployment_name', 'api_version']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -58,7 +58,8 @@ class AzureLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct'))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct'))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class AzureOpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
class AzureOpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -17,12 +18,13 @@ class AzureOpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key', 'api_version']:
|
for key in ['api_base', 'api_key', 'api_version']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -32,7 +34,9 @@ class AzureOpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class AzureOpenAITTIModelParams(BaseForm):
|
class AzureOpenAITTIModelParams(BaseForm):
|
||||||
|
|
@ -52,12 +53,13 @@ class AzureOpenAITextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key', 'api_version']:
|
for key in ['api_base', 'api_key', 'api_version']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -68,7 +70,9 @@ class AzureOpenAITextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class AzureOpenAITTSModelGeneralParams(BaseForm):
|
class AzureOpenAITTSModelGeneralParams(BaseForm):
|
||||||
# alloy, echo, fable, onyx, nova, shimmer
|
# alloy, echo, fable, onyx, nova, shimmer
|
||||||
|
|
@ -33,12 +35,12 @@ class AzureOpenAITTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value, __('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key', 'api_version']:
|
for key in ['api_base', 'api_key', 'api_version']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -48,7 +50,7 @@ class AzureOpenAITTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value, __('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from openai import OpenAI, AzureOpenAI
|
from openai import AzureOpenAI
|
||||||
|
|
||||||
from common.config.tokenizer_manage_config import TokenizerManage
|
from common.config.tokenizer_manage_config import TokenizerManage
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from dashscope import api_key
|
from openai import AzureOpenAI
|
||||||
from dashscope.common.env import api_version
|
|
||||||
from openai import OpenAI, AzureOpenAI
|
|
||||||
|
|
||||||
from common.config.tokenizer_manage_config import TokenizerManage
|
from common.config.tokenizer_manage_config import TokenizerManage
|
||||||
from common.util.common import _remove_empty_lines
|
from common.util.common import _remove_empty_lines
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,13 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class DeepSeekLLMModelParams(BaseForm):
|
class DeepSeekLLMModelParams(BaseForm):
|
||||||
|
|
@ -43,23 +43,23 @@ class DeepSeekLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
model.invoke([HumanMessage(content=_('Hello'))])
|
model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -8,33 +8,38 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class GeminiEmbeddingCredential(BaseForm, BaseModelCredential):
|
class GeminiEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
|
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
|
||||||
raise_exception=True):
|
raise_exception=True):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,18 @@
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class GeminiImageModelParams(BaseForm):
|
class GeminiImageModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.7,
|
required=True, default_value=0.7,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -18,7 +21,8 @@ class GeminiImageModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=800,
|
required=True, default_value=800,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -26,7 +30,6 @@ class GeminiImageModelParams(BaseForm):
|
||||||
precision=0)
|
precision=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GeminiImageModelCredential(BaseForm, BaseModelCredential):
|
class GeminiImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
api_key = forms.PasswordInputField('API Key', required=True)
|
api_key = forms.PasswordInputField('API Key', required=True)
|
||||||
|
|
||||||
|
|
@ -34,24 +37,27 @@ class GeminiImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
res = model.stream([HumanMessage(content=[{"type": "text", "text": _('Hello')}])])
|
res = model.stream([HumanMessage(content=[{"type": "text", "text": __('Hello')}])])
|
||||||
for chunk in res:
|
for chunk in res:
|
||||||
print(chunk)
|
print(chunk)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,18 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class GeminiLLMModelParams(BaseForm):
|
class GeminiLLMModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.7,
|
required=True, default_value=0.7,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -25,7 +27,8 @@ class GeminiLLMModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=800,
|
required=True, default_value=800,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -39,23 +42,26 @@ class GeminiLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
res = model.invoke([HumanMessage(content=_('Hello'))])
|
res = model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
print(res)
|
print(res)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class GeminiSTTModelCredential(BaseForm, BaseModelCredential):
|
class GeminiSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
api_key = forms.PasswordInputField('API Key', required=True)
|
api_key = forms.PasswordInputField('API Key', required=True)
|
||||||
|
|
@ -14,12 +16,13 @@ class GeminiSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -29,7 +32,9 @@ class GeminiSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
from langchain_google_genai import ChatGoogleGenerativeAI
|
from langchain_google_genai import ChatGoogleGenerativeAI
|
||||||
|
|
||||||
from common.config.tokenizer_manage_config import TokenizerManage
|
from common.config.tokenizer_manage_config import TokenizerManage
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_stt import BaseSpeechToText
|
from setting.models_provider.impl.base_stt import BaseSpeechToText
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
def custom_get_token_ids(text: str):
|
def custom_get_token_ids(text: str):
|
||||||
|
|
@ -41,7 +40,7 @@ class GeminiSpeechToText(MaxKBBaseModel, BaseSpeechToText):
|
||||||
model=self.model,
|
model=self.model,
|
||||||
google_api_key=self.api_key
|
google_api_key=self.api_key
|
||||||
)
|
)
|
||||||
response_list = client.invoke(_('Hello'))
|
response_list = client.invoke(__('Hello'))
|
||||||
# print(response_list)
|
# print(response_list)
|
||||||
|
|
||||||
def speech_to_text(self, audio_file):
|
def speech_to_text(self, audio_file):
|
||||||
|
|
@ -51,7 +50,7 @@ class GeminiSpeechToText(MaxKBBaseModel, BaseSpeechToText):
|
||||||
)
|
)
|
||||||
audio_data = audio_file.read()
|
audio_data = audio_file.read()
|
||||||
msg = HumanMessage(content=[
|
msg = HumanMessage(content=[
|
||||||
{'type': 'text', 'text': _('convert audio to text')},
|
{'type': 'text', 'text': __('convert audio to text')},
|
||||||
{"type": "media", 'mime_type': 'audio/mp3', "data": audio_data}
|
{"type": "media", 'mime_type': 'audio/mp3', "data": audio_data}
|
||||||
])
|
])
|
||||||
res = client.invoke([msg])
|
res = client.invoke([msg])
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,13 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class KimiLLMModelParams(BaseForm):
|
class KimiLLMModelParams(BaseForm):
|
||||||
|
|
@ -40,22 +40,22 @@ class KimiLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value, __('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
model.invoke([HumanMessage(content=_('Hello'))])
|
model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value, __('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,13 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from setting.models_provider.impl.local_model_provider.model.embedding import LocalEmbedding
|
from setting.models_provider.impl.local_model_provider.model.embedding import LocalEmbedding
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class LocalEmbeddingCredential(BaseForm, BaseModelCredential):
|
class LocalEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -21,21 +22,24 @@ class LocalEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
|
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
if not model_type == 'EMBEDDING':
|
if not model_type == 'EMBEDDING':
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['cache_folder']:
|
for key in ['cache_folder']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model: LocalEmbedding = provider.get_model(model_type, model_name, model_credential)
|
model: LocalEmbedding = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from setting.models_provider.impl.local_model_provider.model.reranker import LocalBaseReranker
|
from setting.models_provider.impl.local_model_provider.model.reranker import LocalBaseReranker
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class LocalRerankerCredential(BaseForm, BaseModelCredential):
|
class LocalRerankerCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -23,21 +23,24 @@ class LocalRerankerCredential(BaseForm, BaseModelCredential):
|
||||||
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
|
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
if not model_type == 'RERANKER':
|
if not model_type == 'RERANKER':
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['cache_dir']:
|
for key in ['cache_dir']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model: LocalBaseReranker = provider.get_model(model_type, model_name, model_credential)
|
model: LocalBaseReranker = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.compress_documents([Document(page_content=_('Hello'))], _('Hello'))
|
model.compress_documents([Document(page_content=__('Hello'))], __('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,13 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from setting.models_provider.impl.local_model_provider.model.embedding import LocalEmbedding
|
from setting.models_provider.impl.local_model_provider.model.embedding import LocalEmbedding
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class OllamaEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
class OllamaEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -21,17 +22,19 @@ class OllamaEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
try:
|
try:
|
||||||
model_list = provider.get_base_model_list(model_credential.get('api_base'))
|
model_list = provider.get_base_model_list(model_credential.get('api_base'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('API domain name is invalid'))
|
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||||
exist = [model for model in (model_list.get('models') if model_list.get('models') is not None else []) if
|
exist = [model for model in (model_list.get('models') if model_list.get('models') is not None else []) if
|
||||||
model.get('model') == model_name or model.get('model').replace(":latest", "") == model_name]
|
model.get('model') == model_name or model.get('model').replace(":latest", "") == model_name]
|
||||||
if len(exist) == 0:
|
if len(exist) == 0:
|
||||||
raise AppApiException(ValidCode.model_not_fount, _('The model does not exist, please download the model first'))
|
raise AppApiException(ValidCode.model_not_fount,
|
||||||
|
__('The model does not exist, please download the model first'))
|
||||||
model: LocalEmbedding = provider.get_model(model_type, model_name, model_credential)
|
model: LocalEmbedding = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def encryption_dict(self, model_info: Dict[str, object]):
|
def encryption_dict(self, model_info: Dict[str, object]):
|
||||||
|
|
@ -40,7 +43,7 @@ class OllamaEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
||||||
def build_model(self, model_info: Dict[str, object]):
|
def build_model(self, model_info: Dict[str, object]):
|
||||||
for key in ['model']:
|
for key in ['model']:
|
||||||
if key not in model_info:
|
if key not in model_info:
|
||||||
raise AppApiException(500, _('{key} is required').format(key=key))
|
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
api_base = forms.TextInputField('API Url', required=True)
|
api_base = forms.TextInputField('API Url', required=True)
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,12 @@ from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class OllamaImageModelParams(BaseForm):
|
class OllamaImageModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.7,
|
required=True, default_value=0.7,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -16,7 +18,8 @@ class OllamaImageModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=800,
|
required=True, default_value=800,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -24,7 +27,6 @@ class OllamaImageModelParams(BaseForm):
|
||||||
precision=0)
|
precision=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OllamaImageModelCredential(BaseForm, BaseModelCredential):
|
class OllamaImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
api_base = forms.TextInputField('API Url', required=True)
|
api_base = forms.TextInputField('API Url', required=True)
|
||||||
api_key = forms.PasswordInputField('API Key', required=True)
|
api_key = forms.PasswordInputField('API Key', required=True)
|
||||||
|
|
@ -33,15 +35,17 @@ class OllamaImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
try:
|
try:
|
||||||
model_list = provider.get_base_model_list(model_credential.get('api_base'))
|
model_list = provider.get_base_model_list(model_credential.get('api_base'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('API domain name is invalid'))
|
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||||
exist = [model for model in (model_list.get('models') if model_list.get('models') is not None else []) if
|
exist = [model for model in (model_list.get('models') if model_list.get('models') is not None else []) if
|
||||||
model.get('model') == model_name or model.get('model').replace(":latest", "") == model_name]
|
model.get('model') == model_name or model.get('model').replace(":latest", "") == model_name]
|
||||||
if len(exist) == 0:
|
if len(exist) == 0:
|
||||||
raise AppApiException(ValidCode.model_not_fount, _('The model does not exist, please download the model first'))
|
raise AppApiException(ValidCode.model_not_fount,
|
||||||
|
__('The model does not exist, please download the model first'))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,17 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class OllamaLLMModelParams(BaseForm):
|
class OllamaLLMModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.3,
|
required=True, default_value=0.3,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -24,7 +26,8 @@ class OllamaLLMModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=1024,
|
required=True, default_value=1024,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -37,15 +40,17 @@ class OllamaLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
try:
|
try:
|
||||||
model_list = provider.get_base_model_list(model_credential.get('api_base'))
|
model_list = provider.get_base_model_list(model_credential.get('api_base'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('API domain name is invalid'))
|
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||||
exist = [model for model in (model_list.get('models') if model_list.get('models') is not None else []) if
|
exist = [model for model in (model_list.get('models') if model_list.get('models') is not None else []) if
|
||||||
model.get('model') == model_name or model.get('model').replace(":latest", "") == model_name]
|
model.get('model') == model_name or model.get('model').replace(":latest", "") == model_name]
|
||||||
if len(exist) == 0:
|
if len(exist) == 0:
|
||||||
raise AppApiException(ValidCode.model_not_fount, _('The model does not exist, please download the model first'))
|
raise AppApiException(ValidCode.model_not_fount,
|
||||||
|
__('The model does not exist, please download the model first'))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def encryption_dict(self, model_info: Dict[str, object]):
|
def encryption_dict(self, model_info: Dict[str, object]):
|
||||||
|
|
@ -54,7 +59,7 @@ class OllamaLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
def build_model(self, model_info: Dict[str, object]):
|
def build_model(self, model_info: Dict[str, object]):
|
||||||
for key in ['api_key', 'model']:
|
for key in ['api_key', 'model']:
|
||||||
if key not in model_info:
|
if key not in model_info:
|
||||||
raise AppApiException(500, _('{key} is required').format(key=key))
|
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||||
self.api_key = model_info.get('api_key')
|
self.api_key = model_info.get('api_key')
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class OpenAIEmbeddingCredential(BaseForm, BaseModelCredential):
|
class OpenAIEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -20,22 +21,25 @@ class OpenAIEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=True):
|
raise_exception=True):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,12 @@ from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class OpenAIImageModelParams(BaseForm):
|
class OpenAIImageModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.7,
|
required=True, default_value=0.7,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -20,7 +22,8 @@ class OpenAIImageModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=800,
|
required=True, default_value=800,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -28,7 +31,6 @@ class OpenAIImageModelParams(BaseForm):
|
||||||
precision=0)
|
precision=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
class OpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
api_base = forms.TextInputField('API Url', required=True)
|
api_base = forms.TextInputField('API Url', required=True)
|
||||||
api_key = forms.PasswordInputField('API Key', required=True)
|
api_key = forms.PasswordInputField('API Key', required=True)
|
||||||
|
|
@ -37,12 +39,13 @@ class OpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -54,7 +57,9 @@ class OpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,13 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class OpenAILLMModelParams(BaseForm):
|
class OpenAILLMModelParams(BaseForm):
|
||||||
|
|
@ -40,12 +40,12 @@ class OpenAILLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value, __('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -56,7 +56,7 @@ class OpenAILLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value, __('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class OpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
class OpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
api_base = forms.TextInputField('API Url', required=True)
|
api_base = forms.TextInputField('API Url', required=True)
|
||||||
|
|
@ -15,12 +17,13 @@ class OpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -30,7 +33,9 @@ class OpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from langchain_core.messages import HumanMessage
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class OpenAITTIModelParams(BaseForm):
|
class OpenAITTIModelParams(BaseForm):
|
||||||
size = forms.SingleSelect(
|
size = forms.SingleSelect(
|
||||||
TooltipLabel(_('Image size'), _('The image generation endpoint allows you to create raw images based on text prompts. When using the DALL·E 3, the image size can be 1024x1024, 1024x1792 or 1792x1024 pixels.')),
|
TooltipLabel(_('Image size'),
|
||||||
|
_('The image generation endpoint allows you to create raw images based on text prompts. When using the DALL·E 3, the image size can be 1024x1024, 1024x1792 or 1792x1024 pixels.')),
|
||||||
required=True,
|
required=True,
|
||||||
default_value='1024x1024',
|
default_value='1024x1024',
|
||||||
option_list=[
|
option_list=[
|
||||||
|
|
@ -40,7 +39,8 @@ By default, images are produced in standard quality, but with DALL·E 3 you can
|
||||||
)
|
)
|
||||||
|
|
||||||
n = forms.SliderField(
|
n = forms.SliderField(
|
||||||
TooltipLabel(_('Number of pictures'), _('You can use DALL·E 3 to request 1 image at a time (requesting more images by issuing parallel requests), or use DALL·E 2 with the n parameter to request up to 10 images at a time.')),
|
TooltipLabel(_('Number of pictures'),
|
||||||
|
_('You can use DALL·E 3 to request 1 image at a time (requesting more images by issuing parallel requests), or use DALL·E 2 with the n parameter to request up to 10 images at a time.')),
|
||||||
required=True, default_value=1,
|
required=True, default_value=1,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=10,
|
_max=10,
|
||||||
|
|
@ -56,12 +56,13 @@ class OpenAITextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -72,7 +73,9 @@ class OpenAITextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,19 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class OpenAITTSModelGeneralParams(BaseForm):
|
class OpenAITTSModelGeneralParams(BaseForm):
|
||||||
# alloy, echo, fable, onyx, nova, shimmer
|
# alloy, echo, fable, onyx, nova, shimmer
|
||||||
voice = forms.SingleSelect(
|
voice = forms.SingleSelect(
|
||||||
TooltipLabel('Voice', _('Try out the different sounds (Alloy, Echo, Fable, Onyx, Nova, and Sparkle) to find one that suits your desired tone and audience. The current voiceover is optimized for English.')),
|
TooltipLabel('Voice',
|
||||||
|
_('Try out the different sounds (Alloy, Echo, Fable, Onyx, Nova, and Sparkle) to find one that suits your desired tone and audience. The current voiceover is optimized for English.')),
|
||||||
required=True, default_value='alloy',
|
required=True, default_value='alloy',
|
||||||
text_field='value',
|
text_field='value',
|
||||||
value_field='value',
|
value_field='value',
|
||||||
|
|
@ -32,12 +35,13 @@ class OpenAITTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -47,7 +51,9 @@ class OpenAITTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,20 @@
|
||||||
@date:2024/7/11 18:41
|
@date:2024/7/11 18:41
|
||||||
@desc:
|
@desc:
|
||||||
"""
|
"""
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class QwenModelParams(BaseForm):
|
class QwenModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=1.0,
|
required=True, default_value=1.0,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.9,
|
_max=1.9,
|
||||||
|
|
@ -27,7 +27,8 @@ class QwenModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=800,
|
required=True, default_value=800,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -41,23 +42,26 @@ class QwenVLModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
res = model.stream([HumanMessage(content=[{"type": "text", "text": _('Hello')}])])
|
res = model.stream([HumanMessage(content=[{"type": "text", "text": __('Hello')}])])
|
||||||
for chunk in res:
|
for chunk in res:
|
||||||
print(chunk)
|
print(chunk)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,18 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class QwenModelParams(BaseForm):
|
class QwenModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=1.0,
|
required=True, default_value=1.0,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.9,
|
_max=1.9,
|
||||||
|
|
@ -25,7 +27,8 @@ class QwenModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=800,
|
required=True, default_value=800,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -39,21 +42,24 @@ class OpenAILLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
model.invoke([HumanMessage(content=_('Hello'))])
|
model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,16 @@
|
||||||
@date:2024/7/11 18:41
|
@date:2024/7/11 18:41
|
||||||
@desc:
|
@desc:
|
||||||
"""
|
"""
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from langchain_core.messages import HumanMessage
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class QwenModelParams(BaseForm):
|
class QwenModelParams(BaseForm):
|
||||||
size = forms.SingleSelect(
|
size = forms.SingleSelect(
|
||||||
TooltipLabel(_('Image size'), _('Specify the size of the generated image, such as: 1024x1024')),
|
TooltipLabel(_('Image size'), _('Specify the size of the generated image, such as: 1024x1024')),
|
||||||
|
|
@ -64,11 +63,12 @@ class QwenTextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -79,7 +79,9 @@ class QwenTextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class TencentEmbeddingCredential(BaseForm, BaseModelCredential):
|
class TencentEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
||||||
|
|
@ -12,16 +14,19 @@ class TencentEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=True) -> bool:
|
raise_exception=True) -> bool:
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
self.valid_form(model_credential)
|
self.valid_form(model_credential)
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,20 @@
|
||||||
@date:2024/7/11 18:41
|
@date:2024/7/11 18:41
|
||||||
@desc:
|
@desc:
|
||||||
"""
|
"""
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class QwenModelParams(BaseForm):
|
class QwenModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=1.0,
|
required=True, default_value=1.0,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.9,
|
_max=1.9,
|
||||||
|
|
@ -27,7 +27,8 @@ class QwenModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=800,
|
required=True, default_value=800,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -41,23 +42,26 @@ class TencentVisionModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
res = model.stream([HumanMessage(content=[{"type": "text", "text": _('Hello')}])])
|
res = model.stream([HumanMessage(content=[{"type": "text", "text": __('Hello')}])])
|
||||||
for chunk in res:
|
for chunk in res:
|
||||||
print(chunk)
|
print(chunk)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class TencentLLMModelParams(BaseForm):
|
class TencentLLMModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.5,
|
required=True, default_value=0.5,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=2.0,
|
_max=2.0,
|
||||||
|
|
@ -23,7 +25,8 @@ class TencentLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
def _validate_model_type(cls, model_type, provider, raise_exception=False):
|
def _validate_model_type(cls, model_type, provider, raise_exception=False):
|
||||||
if not any(mt['value'] == model_type for mt in provider.get_model_type_list()):
|
if not any(mt['value'] == model_type for mt in provider.get_model_type_list()):
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -32,20 +35,23 @@ class TencentLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
missing_keys = [key for key in cls.REQUIRED_FIELDS if key not in model_credential]
|
missing_keys = [key for key in cls.REQUIRED_FIELDS if key not in model_credential]
|
||||||
if missing_keys:
|
if missing_keys:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{keys} is required').format(keys=", ".join(missing_keys)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{keys} is required').format(keys=", ".join(missing_keys)))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def is_valid(self, model_type, model_name, model_credential, model_params, provider, raise_exception=False):
|
def is_valid(self, model_type, model_name, model_credential, model_params, provider, raise_exception=False):
|
||||||
if not (self._validate_model_type(model_type, provider, raise_exception) and
|
if not (self._validate_model_type(model_type, provider, raise_exception) and
|
||||||
self._validate_credential_fields(model_credential, raise_exception)):
|
self._validate_credential_fields(model_credential, raise_exception)):
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
model.invoke([HumanMessage(content=_('Hello'))])
|
model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from langchain_core.messages import HumanMessage
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class TencentTTIModelParams(BaseForm):
|
class TencentTTIModelParams(BaseForm):
|
||||||
Style = forms.SingleSelect(
|
Style = forms.SingleSelect(
|
||||||
|
|
@ -72,7 +73,8 @@ class TencentTTIModelCredential(BaseForm, BaseModelCredential):
|
||||||
def _validate_model_type(cls, model_type, provider, raise_exception=False):
|
def _validate_model_type(cls, model_type, provider, raise_exception=False):
|
||||||
if not any(mt['value'] == model_type for mt in provider.get_model_type_list()):
|
if not any(mt['value'] == model_type for mt in provider.get_model_type_list()):
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -81,7 +83,8 @@ class TencentTTIModelCredential(BaseForm, BaseModelCredential):
|
||||||
missing_keys = [key for key in cls.REQUIRED_FIELDS if key not in model_credential]
|
missing_keys = [key for key in cls.REQUIRED_FIELDS if key not in model_credential]
|
||||||
if missing_keys:
|
if missing_keys:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{keys} is required').format(keys=", ".join(missing_keys)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{keys} is required').format(keys=", ".join(missing_keys)))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -94,7 +97,9 @@ class TencentTTIModelCredential(BaseForm, BaseModelCredential):
|
||||||
model.check_auth()
|
model.check_auth()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VllmEmbeddingCredential(BaseForm, BaseModelCredential):
|
class VllmEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -21,22 +21,25 @@ class VllmEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=True):
|
raise_exception=True):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query('你好')
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class VllmImageModelParams(BaseForm):
|
class VllmImageModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
|
@ -30,7 +29,6 @@ class VllmImageModelParams(BaseForm):
|
||||||
precision=0)
|
precision=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VllmImageModelCredential(BaseForm, BaseModelCredential):
|
class VllmImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
api_base = forms.TextInputField('API Url', required=True)
|
api_base = forms.TextInputField('API Url', required=True)
|
||||||
api_key = forms.PasswordInputField('API Key', required=True)
|
api_key = forms.PasswordInputField('API Key', required=True)
|
||||||
|
|
@ -39,12 +37,13 @@ class VllmImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -56,7 +55,9 @@ class VllmImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,18 @@
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class VLLMModelParams(BaseForm):
|
class VLLMModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.7,
|
required=True, default_value=0.7,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -20,7 +21,8 @@ class VLLMModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=800,
|
required=True, default_value=800,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -33,17 +35,19 @@ class VLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
try:
|
try:
|
||||||
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'))
|
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('API domain name is invalid'))
|
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||||
exist = provider.get_model_info_by_name(model_list, model_name)
|
exist = provider.get_model_info_by_name(model_list, model_name)
|
||||||
if len(exist) == 0:
|
if len(exist) == 0:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('The model does not exist, please download the model first'))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('The model does not exist, please download the model first'))
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
try:
|
try:
|
||||||
res = model.invoke([HumanMessage(content=_('Hello'))])
|
res = model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
print(res)
|
print(res)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
@ -55,7 +59,7 @@ class VLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
def build_model(self, model_info: Dict[str, object]):
|
def build_model(self, model_info: Dict[str, object]):
|
||||||
for key in ['api_key', 'model']:
|
for key in ['api_key', 'model']:
|
||||||
if key not in model_info:
|
if key not in model_info:
|
||||||
raise AppApiException(500, _('{key} is required').format(key=key))
|
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||||
self.api_key = model_info.get('api_key')
|
self.api_key = model_info.get('api_key')
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class VolcanicEmbeddingCredential(BaseForm, BaseModelCredential):
|
class VolcanicEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -20,22 +21,25 @@ class VolcanicEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=True):
|
raise_exception=True):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class VolcanicEngineImageModelParams(BaseForm):
|
class VolcanicEngineImageModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.95,
|
required=True, default_value=0.95,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -20,13 +20,15 @@ class VolcanicEngineImageModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=1024,
|
required=True, default_value=1024,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
_step=1,
|
_step=1,
|
||||||
precision=0)
|
precision=0)
|
||||||
|
|
||||||
|
|
||||||
class VolcanicEngineImageModelCredential(BaseForm, BaseModelCredential):
|
class VolcanicEngineImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
api_key = forms.PasswordInputField('API Key', required=True)
|
api_key = forms.PasswordInputField('API Key', required=True)
|
||||||
api_base = forms.TextInputField('API Url', required=True)
|
api_base = forms.TextInputField('API Url', required=True)
|
||||||
|
|
@ -35,24 +37,27 @@ class VolcanicEngineImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key', 'api_base']:
|
for key in ['api_key', 'api_base']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
res = model.stream([HumanMessage(content=[{"type": "text", "text": _('Hello')}])])
|
res = model.stream([HumanMessage(content=[{"type": "text", "text": __('Hello')}])])
|
||||||
for chunk in res:
|
for chunk in res:
|
||||||
print(chunk)
|
print(chunk)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,18 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class VolcanicEngineLLMModelParams(BaseForm):
|
class VolcanicEngineLLMModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.3,
|
required=True, default_value=0.3,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -26,7 +27,8 @@ class VolcanicEngineLLMModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=1024,
|
required=True, default_value=1024,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -40,23 +42,26 @@ class VolcanicEngineLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['access_key_id', 'secret_access_key']:
|
for key in ['access_key_id', 'secret_access_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
res = model.invoke([HumanMessage(content=_('Hello'))])
|
res = model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
print(res)
|
print(res)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,17 @@
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class VolcanicEngineSTTModelCredential(BaseForm, BaseModelCredential):
|
class VolcanicEngineSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
volcanic_api_url = forms.TextInputField('API Url', required=True, default_value='wss://openspeech.bytedance.com/api/v2/asr')
|
volcanic_api_url = forms.TextInputField('API Url', required=True,
|
||||||
|
default_value='wss://openspeech.bytedance.com/api/v2/asr')
|
||||||
volcanic_app_id = forms.TextInputField('App ID', required=True)
|
volcanic_app_id = forms.TextInputField('App ID', required=True)
|
||||||
volcanic_token = forms.PasswordInputField('Access Token', required=True)
|
volcanic_token = forms.PasswordInputField('Access Token', required=True)
|
||||||
volcanic_cluster = forms.TextInputField('Cluster ID', required=True)
|
volcanic_cluster = forms.TextInputField('Cluster ID', required=True)
|
||||||
|
|
@ -19,12 +21,13 @@ class VolcanicEngineSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['volcanic_api_url', 'volcanic_app_id', 'volcanic_token', 'volcanic_cluster']:
|
for key in ['volcanic_api_url', 'volcanic_app_id', 'volcanic_token', 'volcanic_cluster']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -34,7 +37,9 @@ class VolcanicEngineSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class VolcanicEngineTTIModelGeneralParams(BaseForm):
|
class VolcanicEngineTTIModelGeneralParams(BaseForm):
|
||||||
|
|
@ -36,12 +37,12 @@ class VolcanicEngineTTIModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value, __('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['access_key', 'secret_key']:
|
for key in ['access_key', 'secret_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -51,7 +52,7 @@ class VolcanicEngineTTIModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value, __('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
|
|
||||||
class VolcanicEngineTTSModelGeneralParams(BaseForm):
|
class VolcanicEngineTTSModelGeneralParams(BaseForm):
|
||||||
|
|
@ -47,12 +47,12 @@ class VolcanicEngineTTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value, __('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['volcanic_api_url', 'volcanic_app_id', 'volcanic_token', 'volcanic_cluster']:
|
for key in ['volcanic_api_url', 'volcanic_app_id', 'volcanic_token', 'volcanic_cluster']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -62,7 +62,7 @@ class VolcanicEngineTTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value, __('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,16 @@ import copy
|
||||||
import gzip
|
import gzip
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import ssl
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
import ssl
|
|
||||||
import websockets
|
import websockets
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common.util.common import _remove_empty_lines
|
from common.util.common import _remove_empty_lines
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
MESSAGE_TYPES = {11: "audio-only server response", 12: "frontend server response", 15: "error message from server"}
|
MESSAGE_TYPES = {11: "audio-only server response", 12: "frontend server response", 15: "error message from server"}
|
||||||
MESSAGE_TYPE_SPECIFIC_FLAGS = {0: "no sequence number", 1: "sequence number > 0",
|
MESSAGE_TYPE_SPECIFIC_FLAGS = {0: "no sequence number", 1: "sequence number > 0",
|
||||||
|
|
@ -73,7 +74,7 @@ class VolcanicEngineTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_auth(self):
|
def check_auth(self):
|
||||||
self.text_to_speech(_('Hello'))
|
self.text_to_speech(__('Hello'))
|
||||||
|
|
||||||
def text_to_speech(self, text):
|
def text_to_speech(self, text):
|
||||||
request_json = {
|
request_json = {
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class QianfanEmbeddingCredential(BaseForm, BaseModelCredential):
|
class QianfanEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -21,16 +22,19 @@ class QianfanEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
self.valid_form(model_credential)
|
self.valid_form(model_credential)
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,18 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class WenxinLLMModelParams(BaseForm):
|
class WenxinLLMModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.95,
|
required=True, default_value=0.95,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -26,7 +27,8 @@ class WenxinLLMModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=1024,
|
required=True, default_value=1024,
|
||||||
_min=2,
|
_min=2,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -39,20 +41,22 @@ class WenxinLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
model_info = [model.lower() for model in model.client.models()]
|
model_info = [model.lower() for model in model.client.models()]
|
||||||
if not model_info.__contains__(model_name.lower()):
|
if not model_info.__contains__(model_name.lower()):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_name} The model does not support').format(model_name=model_name))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_name} The model does not support').format(model_name=model_name))
|
||||||
for key in ['api_key', 'secret_key']:
|
for key in ['api_key', 'secret_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model.invoke(
|
model.invoke(
|
||||||
[HumanMessage(content=_('Hello'))])
|
[HumanMessage(content=__('Hello'))])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
return True
|
return True
|
||||||
|
|
@ -63,7 +67,7 @@ class WenxinLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
def build_model(self, model_info: Dict[str, object]):
|
def build_model(self, model_info: Dict[str, object]):
|
||||||
for key in ['api_key', 'secret_key', 'model']:
|
for key in ['api_key', 'secret_key', 'model']:
|
||||||
if key not in model_info:
|
if key not in model_info:
|
||||||
raise AppApiException(500, _('{key} is required').format(key=key))
|
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||||
self.api_key = model_info.get('api_key')
|
self.api_key = model_info.get('api_key')
|
||||||
self.secret_key = model_info.get('secret_key')
|
self.secret_key = model_info.get('secret_key')
|
||||||
return self
|
return self
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,13 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class XFEmbeddingCredential(BaseForm, BaseModelCredential):
|
class XFEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
||||||
|
|
@ -20,16 +22,19 @@ class XFEmbeddingCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
self.valid_form(model_credential)
|
self.valid_form(model_credential)
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.embed_query(_('Hello'))
|
model.embed_query(__('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import base64
|
||||||
import os
|
import os
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
|
|
@ -10,10 +11,11 @@ from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from setting.models_provider.impl.xf_model_provider.model.image import ImageMessage
|
from setting.models_provider.impl.xf_model_provider.model.image import ImageMessage
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class XunFeiImageModelCredential(BaseForm, BaseModelCredential):
|
class XunFeiImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
spark_api_url = forms.TextInputField('API Url', required=True, default_value='wss://spark-api.cn-huabei-1.xf-yun.com/v2.1/image')
|
spark_api_url = forms.TextInputField('API Url', required=True,
|
||||||
|
default_value='wss://spark-api.cn-huabei-1.xf-yun.com/v2.1/image')
|
||||||
spark_app_id = forms.TextInputField('APP ID', required=True)
|
spark_app_id = forms.TextInputField('APP ID', required=True)
|
||||||
spark_api_key = forms.PasswordInputField("API Key", required=True)
|
spark_api_key = forms.PasswordInputField("API Key", required=True)
|
||||||
spark_api_secret = forms.PasswordInputField('API Secret', required=True)
|
spark_api_secret = forms.PasswordInputField('API Secret', required=True)
|
||||||
|
|
@ -22,25 +24,29 @@ class XunFeiImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['spark_api_url', 'spark_app_id', 'spark_api_key', 'spark_api_secret']:
|
for key in ['spark_api_url', 'spark_app_id', 'spark_api_key', 'spark_api_secret']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
cwd = os.path.dirname(os.path.abspath(__file__))
|
cwd = os.path.dirname(os.path.abspath(__file__))
|
||||||
with open(f'{cwd}/img_1.png', 'rb') as f:
|
with open(f'{cwd}/img_1.png', 'rb') as f:
|
||||||
message_list = [ImageMessage(str(base64.b64encode(f.read()), 'utf-8')), HumanMessage(_('Please outline this picture'))]
|
message_list = [ImageMessage(str(base64.b64encode(f.read()), 'utf-8')),
|
||||||
|
HumanMessage(__('Please outline this picture'))]
|
||||||
model.stream(message_list)
|
model.stream(message_list)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
@ -48,6 +54,5 @@ class XunFeiImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
def encryption_dict(self, model: Dict[str, object]):
|
def encryption_dict(self, model: Dict[str, object]):
|
||||||
return {**model, 'spark_api_secret': super().encryption(model.get('spark_api_secret', ''))}
|
return {**model, 'spark_api_secret': super().encryption(model.get('spark_api_secret', ''))}
|
||||||
|
|
||||||
|
|
||||||
def get_model_params_setting_form(self, model_name):
|
def get_model_params_setting_form(self, model_name):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,18 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class XunFeiLLMModelGeneralParams(BaseForm):
|
class XunFeiLLMModelGeneralParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.5,
|
required=True, default_value=0.5,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -25,7 +27,8 @@ class XunFeiLLMModelGeneralParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=4096,
|
required=True, default_value=4096,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -34,7 +37,8 @@ class XunFeiLLMModelGeneralParams(BaseForm):
|
||||||
|
|
||||||
|
|
||||||
class XunFeiLLMModelProParams(BaseForm):
|
class XunFeiLLMModelProParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.5,
|
required=True, default_value=0.5,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -42,7 +46,8 @@ class XunFeiLLMModelProParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=4096,
|
required=True, default_value=4096,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -56,22 +61,25 @@ class XunFeiLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['spark_api_url', 'spark_app_id', 'spark_api_key', 'spark_api_secret']:
|
for key in ['spark_api_url', 'spark_app_id', 'spark_api_key', 'spark_api_secret']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
model.invoke([HumanMessage(content=_('Hello'))])
|
model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class XunFeiSTTModelCredential(BaseForm, BaseModelCredential):
|
class XunFeiSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
|
|
@ -19,12 +20,13 @@ class XunFeiSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['spark_api_url', 'spark_app_id', 'spark_api_key', 'spark_api_secret']:
|
for key in ['spark_api_url', 'spark_app_id', 'spark_api_key', 'spark_api_secret']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -34,7 +36,9 @@ class XunFeiSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
@ -42,6 +46,5 @@ class XunFeiSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
def encryption_dict(self, model: Dict[str, object]):
|
def encryption_dict(self, model: Dict[str, object]):
|
||||||
return {**model, 'spark_api_secret': super().encryption(model.get('spark_api_secret', ''))}
|
return {**model, 'spark_api_secret': super().encryption(model.get('spark_api_secret', ''))}
|
||||||
|
|
||||||
|
|
||||||
def get_model_params_setting_form(self, model_name):
|
def get_model_params_setting_form(self, model_name):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,18 @@
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class XunFeiTTSModelGeneralParams(BaseForm):
|
class XunFeiTTSModelGeneralParams(BaseForm):
|
||||||
vcn = forms.SingleSelect(
|
vcn = forms.SingleSelect(
|
||||||
TooltipLabel(_('Speaker'), _('Speaker, optional value: Please go to the console to add a trial or purchase speaker. After adding, the speaker parameter value will be displayed.')),
|
TooltipLabel(_('Speaker'),
|
||||||
|
_('Speaker, optional value: Please go to the console to add a trial or purchase speaker. After adding, the speaker parameter value will be displayed.')),
|
||||||
required=True, default_value='xiaoyan',
|
required=True, default_value='xiaoyan',
|
||||||
text_field='value',
|
text_field='value',
|
||||||
value_field='value',
|
value_field='value',
|
||||||
|
|
@ -41,12 +43,13 @@ class XunFeiTTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['spark_api_url', 'spark_app_id', 'spark_api_key', 'spark_api_secret']:
|
for key in ['spark_api_url', 'spark_app_id', 'spark_api_key', 'spark_api_secret']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -56,7 +59,9 @@ class XunFeiTTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,34 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from setting.models_provider.impl.local_model_provider.model.embedding import LocalEmbedding
|
from setting.models_provider.impl.local_model_provider.model.embedding import LocalEmbedding
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class XinferenceEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
class XinferenceEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
||||||
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object],model_params, provider,
|
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
try:
|
try:
|
||||||
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'),
|
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'),
|
||||||
'embedding')
|
'embedding')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('API domain name is invalid'))
|
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||||
exist = provider.get_model_info_by_name(model_list, model_name)
|
exist = provider.get_model_info_by_name(model_list, model_name)
|
||||||
model: LocalEmbedding = provider.get_model(model_type, model_name, model_credential)
|
model: LocalEmbedding = provider.get_model(model_type, model_name, model_credential)
|
||||||
if len(exist) == 0:
|
if len(exist) == 0:
|
||||||
model.start_down_model_thread()
|
model.start_down_model_thread()
|
||||||
raise AppApiException(ValidCode.model_not_fount, _('The model does not exist, please download the model first'))
|
raise AppApiException(ValidCode.model_not_fount,
|
||||||
model.embed_query(_('Hello'))
|
__('The model does not exist, please download the model first'))
|
||||||
|
model.embed_query(__('Hello'))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def encryption_dict(self, model_info: Dict[str, object]):
|
def encryption_dict(self, model_info: Dict[str, object]):
|
||||||
|
|
@ -34,7 +37,7 @@ class XinferenceEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
||||||
def build_model(self, model_info: Dict[str, object]):
|
def build_model(self, model_info: Dict[str, object]):
|
||||||
for key in ['model']:
|
for key in ['model']:
|
||||||
if key not in model_info:
|
if key not in model_info:
|
||||||
raise AppApiException(500, _('{key} is required').format(key=key))
|
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
api_base = forms.TextInputField('API Url', required=True)
|
api_base = forms.TextInputField('API Url', required=True)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class XinferenceImageModelParams(BaseForm):
|
class XinferenceImageModelParams(BaseForm):
|
||||||
|
|
@ -40,17 +38,17 @@ class XinferenceImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
res = model.stream([HumanMessage(content=[{"type": "text", "text": _('Hello')}])])
|
res = model.stream([HumanMessage(content=[{"type": "text", "text": __('Hello')}])])
|
||||||
for chunk in res:
|
for chunk in res:
|
||||||
print(chunk)
|
print(chunk)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -58,7 +56,7 @@ class XinferenceImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('Verification failed, please check whether the parameters are correct: {error}').format(
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
|
|
@ -9,8 +10,6 @@ from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class XinferenceLLMModelParams(BaseForm):
|
class XinferenceLLMModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
|
@ -37,18 +36,18 @@ class XinferenceLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
try:
|
try:
|
||||||
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'),
|
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'),
|
||||||
model_type)
|
model_type)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('API domain name is invalid'))
|
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||||
exist = provider.get_model_info_by_name(model_list, model_name)
|
exist = provider.get_model_info_by_name(model_list, model_name)
|
||||||
if len(exist) == 0:
|
if len(exist) == 0:
|
||||||
raise AppApiException(ValidCode.valid_error.value,
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
_('The model does not exist, please download the model first'))
|
__('The model does not exist, please download the model first'))
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
model.invoke([HumanMessage(content=_('Hello'))])
|
model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def encryption_dict(self, model_info: Dict[str, object]):
|
def encryption_dict(self, model_info: Dict[str, object]):
|
||||||
|
|
@ -57,7 +56,7 @@ class XinferenceLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
def build_model(self, model_info: Dict[str, object]):
|
def build_model(self, model_info: Dict[str, object]):
|
||||||
for key in ['api_key', 'model']:
|
for key in ['api_key', 'model']:
|
||||||
if key not in model_info:
|
if key not in model_info:
|
||||||
raise AppApiException(500, _('{key} is required').format(key=key))
|
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||||
self.api_key = model_info.get('api_key')
|
self.api_key = model_info.get('api_key')
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,34 +8,37 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class XInferenceRerankerModelCredential(BaseForm, BaseModelCredential):
|
class XInferenceRerankerModelCredential(BaseForm, BaseModelCredential):
|
||||||
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
|
def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
|
||||||
raise_exception=True):
|
raise_exception=True):
|
||||||
if not model_type == 'RERANKER':
|
if not model_type == 'RERANKER':
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['server_url']:
|
for key in ['server_url']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential)
|
model = provider.get_model(model_type, model_name, model_credential)
|
||||||
model.compress_documents([Document(page_content=_('Hello'))], _('Hello'))
|
model.compress_documents([Document(page_content=__('Hello'))], __('Hello'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm
|
from common.forms import BaseForm
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class XInferenceSTTModelCredential(BaseForm, BaseModelCredential):
|
class XInferenceSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
api_base = forms.TextInputField('API Url', required=True)
|
api_base = forms.TextInputField('API Url', required=True)
|
||||||
|
|
@ -16,12 +17,13 @@ class XInferenceSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -31,7 +33,9 @@ class XInferenceSTTModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from langchain_core.messages import HumanMessage
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class XinferenceTTIModelParams(BaseForm):
|
class XinferenceTTIModelParams(BaseForm):
|
||||||
size = forms.SingleSelect(
|
size = forms.SingleSelect(
|
||||||
TooltipLabel(_('Image size'), _('The image generation endpoint allows you to create raw images based on text prompts. The dimensions of the image can be 1024x1024, 1024x1792, or 1792x1024 pixels.')),
|
TooltipLabel(_('Image size'),
|
||||||
|
_('The image generation endpoint allows you to create raw images based on text prompts. The dimensions of the image can be 1024x1024, 1024x1792, or 1792x1024 pixels.')),
|
||||||
required=True,
|
required=True,
|
||||||
default_value='1024x1024',
|
default_value='1024x1024',
|
||||||
option_list=[
|
option_list=[
|
||||||
|
|
@ -27,7 +25,8 @@ class XinferenceTTIModelParams(BaseForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
quality = forms.SingleSelect(
|
quality = forms.SingleSelect(
|
||||||
TooltipLabel(_('Picture quality'), _('By default, images are generated in standard quality, you can set quality: "hd" to enhance detail. Square, standard quality images are generated fastest.')),
|
TooltipLabel(_('Picture quality'),
|
||||||
|
_('By default, images are generated in standard quality, you can set quality: "hd" to enhance detail. Square, standard quality images are generated fastest.')),
|
||||||
required=True,
|
required=True,
|
||||||
default_value='standard',
|
default_value='standard',
|
||||||
option_list=[
|
option_list=[
|
||||||
|
|
@ -39,7 +38,8 @@ class XinferenceTTIModelParams(BaseForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
n = forms.SliderField(
|
n = forms.SliderField(
|
||||||
TooltipLabel(_('Number of pictures'), _('You can request 1 image at a time (requesting more images by making parallel requests), or up to 10 images at a time using the n parameter.')),
|
TooltipLabel(_('Number of pictures'),
|
||||||
|
_('You can request 1 image at a time (requesting more images by making parallel requests), or up to 10 images at a time using the n parameter.')),
|
||||||
required=True, default_value=1,
|
required=True, default_value=1,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=10,
|
_max=10,
|
||||||
|
|
@ -55,12 +55,13 @@ class XinferenceTextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -71,7 +72,9 @@ class XinferenceTextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class XInferenceTTSModelGeneralParams(BaseForm):
|
class XInferenceTTSModelGeneralParams(BaseForm):
|
||||||
|
|
@ -34,12 +35,13 @@ class XInferenceTTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_base', 'api_key']:
|
for key in ['api_base', 'api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -49,7 +51,9 @@ class XInferenceTTSModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class ZhiPuImageModelParams(BaseForm):
|
class ZhiPuImageModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.95,
|
required=True, default_value=0.95,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -20,13 +20,15 @@ class ZhiPuImageModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=1024,
|
required=True, default_value=1024,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
_step=1,
|
_step=1,
|
||||||
precision=0)
|
precision=0)
|
||||||
|
|
||||||
|
|
||||||
class ZhiPuImageModelCredential(BaseForm, BaseModelCredential):
|
class ZhiPuImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
api_key = forms.PasswordInputField('API Key', required=True)
|
api_key = forms.PasswordInputField('API Key', required=True)
|
||||||
|
|
||||||
|
|
@ -34,24 +36,27 @@ class ZhiPuImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
res = model.stream([HumanMessage(content=[{"type": "text", "text": _('Hello')}])])
|
res = model.stream([HumanMessage(content=[{"type": "text", "text": __('Hello')}])])
|
||||||
for chunk in res:
|
for chunk in res:
|
||||||
print(chunk)
|
print(chunk)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,18 @@
|
||||||
"""
|
"""
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class ZhiPuLLMModelParams(BaseForm):
|
class ZhiPuLLMModelParams(BaseForm):
|
||||||
temperature = forms.SliderField(TooltipLabel(_('Temperature'), _('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
temperature = forms.SliderField(TooltipLabel(_('Temperature'),
|
||||||
|
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
|
||||||
required=True, default_value=0.95,
|
required=True, default_value=0.95,
|
||||||
_min=0.1,
|
_min=0.1,
|
||||||
_max=1.0,
|
_max=1.0,
|
||||||
|
|
@ -26,7 +27,8 @@ class ZhiPuLLMModelParams(BaseForm):
|
||||||
precision=2)
|
precision=2)
|
||||||
|
|
||||||
max_tokens = forms.SliderField(
|
max_tokens = forms.SliderField(
|
||||||
TooltipLabel(_('Output the maximum Tokens'), _('Specify the maximum number of tokens that the model can generate')),
|
TooltipLabel(_('Output the maximum Tokens'),
|
||||||
|
_('Specify the maximum number of tokens that the model can generate')),
|
||||||
required=True, default_value=1024,
|
required=True, default_value=1024,
|
||||||
_min=1,
|
_min=1,
|
||||||
_max=100000,
|
_max=100000,
|
||||||
|
|
@ -40,21 +42,24 @@ class ZhiPuLLMModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||||
model.invoke([HumanMessage(content=_('Hello'))])
|
model.invoke([HumanMessage(content=__('Hello'))])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||||
|
|
||||||
from common import forms
|
from common import forms
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
from common.forms import BaseForm, TooltipLabel
|
from common.forms import BaseForm, TooltipLabel
|
||||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
class ZhiPuTTIModelParams(BaseForm):
|
class ZhiPuTTIModelParams(BaseForm):
|
||||||
size = forms.SingleSelect(
|
size = forms.SingleSelect(
|
||||||
|
|
@ -34,12 +35,13 @@ class ZhiPuTextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
raise_exception=False):
|
raise_exception=False):
|
||||||
model_type_list = provider.get_model_type_list()
|
model_type_list = provider.get_model_type_list()
|
||||||
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{model_type} Model type is not supported').format(model_type=model_type))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||||
|
|
||||||
for key in ['api_key']:
|
for key in ['api_key']:
|
||||||
if key not in model_credential:
|
if key not in model_credential:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('{key} is required').format(key=key))
|
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
|
@ -50,7 +52,9 @@ class ZhiPuTextToImageModelCredential(BaseForm, BaseModelCredential):
|
||||||
if isinstance(e, AppApiException):
|
if isinstance(e, AppApiException):
|
||||||
raise e
|
raise e
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AppApiException(ValidCode.valid_error.value, _('Verification failed, please check whether the parameters are correct: {error}').format(error=str(e)))
|
raise AppApiException(ValidCode.valid_error.value,
|
||||||
|
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||||
|
error=str(e)))
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue