mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: Internationalization of Models (#2068)
This commit is contained in:
parent
f924827c7c
commit
13571ef615
|
|
@ -14,7 +14,7 @@ from typing import List
|
|||
|
||||
from django.db.models import QuerySet
|
||||
from django.http import StreamingHttpResponse
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from langchain.chat_models.base import BaseChatModel
|
||||
from langchain.schema import BaseMessage
|
||||
from langchain.schema.messages import HumanMessage, AIMessage
|
||||
|
|
@ -174,7 +174,7 @@ class BaseChatStep(IChatStep):
|
|||
[AIMessageChunk(content=no_references_setting.get('value').replace('{question}', problem_text))]), False
|
||||
if chat_model is None:
|
||||
return iter([AIMessageChunk(
|
||||
__('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.'))]), False
|
||||
_('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.'))]), False
|
||||
else:
|
||||
return chat_model.stream(message_list), True
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ class BaseChatStep(IChatStep):
|
|||
return AIMessage(no_references_setting.get('value').replace('{question}', problem_text)), False
|
||||
if chat_model is None:
|
||||
return AIMessage(
|
||||
__('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.')), False
|
||||
_('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.')), False
|
||||
else:
|
||||
return chat_model.invoke(message_list), True
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import List
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from langchain.schema import HumanMessage
|
||||
|
||||
from application.chat_pipeline.step.reset_problem_step.i_reset_problem_step import IResetProblemStep
|
||||
|
|
@ -16,7 +16,7 @@ from application.models import ChatRecord
|
|||
from common.util.split_model import flat_map
|
||||
from setting.models_provider.tools import get_model_instance_by_model_user_id
|
||||
|
||||
prompt = __(
|
||||
prompt = _(
|
||||
"() contains the user's question. Answer the guessed user's question based on the context ({question}) Requirement: Output a complete question and put it in the <data></data> tag")
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -24,22 +24,22 @@ class AliyunBaiLianEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['dashscope_api_key']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
model: AliyunBaiLianEmbedding = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -43,11 +43,11 @@ class QwenVLModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -60,7 +60,8 @@ class QwenVLModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from common import forms
|
|||
from common.exception.app_exception import AppApiException
|
||||
from common.forms import BaseForm, TooltipLabel
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
|
||||
class BaiLianLLMModelParams(BaseForm):
|
||||
|
|
@ -36,23 +36,24 @@ class BaiLianLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from langchain_core.documents import Document
|
||||
|
||||
from common import forms
|
||||
|
|
@ -24,22 +24,22 @@ class AliyunBaiLianRerankerCredential(BaseForm, BaseModelCredential):
|
|||
raise_exception=False):
|
||||
if not model_type == 'RERANKER':
|
||||
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']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
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:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -18,12 +18,12 @@ class AliyunBaiLianSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -34,7 +34,7 @@ class AliyunBaiLianSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -64,11 +64,11 @@ class QwenTextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -80,7 +80,8 @@ class QwenTextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
from common.forms import BaseForm, TooltipLabel
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
|
||||
|
||||
class AliyunBaiLianTTSModelGeneralParams(BaseForm):
|
||||
|
|
@ -51,12 +52,12 @@ class AliyunBaiLianTTSModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -67,7 +68,8 @@ class AliyunBaiLianTTSModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from http import HTTPStatus
|
|||
from typing import Dict
|
||||
|
||||
from dashscope import ImageSynthesis
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from langchain_community.chat_models import ChatTongyi
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ class QwenTextToImageModel(MaxKBBaseModel, BaseTextToImage):
|
|||
|
||||
def check_auth(self):
|
||||
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):
|
||||
# api_base='https://dashscope.aliyuncs.com/compatible-mode/v1',
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from typing import Dict
|
|||
|
||||
import dashscope
|
||||
from dashscope.audio.tts_v2 import *
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common.util.common import _remove_empty_lines
|
||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||
|
|
@ -34,7 +34,7 @@ class AliyunBaiLianTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||
)
|
||||
|
||||
def check_auth(self):
|
||||
self.text_to_speech(__('Hello'))
|
||||
self.text_to_speech(_('Hello'))
|
||||
|
||||
def text_to_speech(self, text):
|
||||
dashscope.api_key = self.api_key
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
# coding=utf-8
|
||||
import base64
|
||||
import os
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
from common.forms import BaseForm, TooltipLabel
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
|
||||
|
||||
class AnthropicImageModelParams(BaseForm):
|
||||
|
|
@ -40,12 +38,12 @@ class AnthropicImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -58,7 +56,8 @@ class AnthropicImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from common import forms
|
|||
from common.exception.app_exception import AppApiException
|
||||
from common.forms import BaseForm, TooltipLabel
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
|
||||
class AnthropicLLMModelParams(BaseForm):
|
||||
|
|
@ -43,23 +43,24 @@ class AnthropicLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -17,27 +17,27 @@ class BedrockEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
if not any(mt.get('value') == model_type for mt in model_type_list):
|
||||
if raise_exception:
|
||||
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
|
||||
|
||||
required_keys = ['region_name', 'access_key_id', 'secret_access_key']
|
||||
if not all(key in model_credential for key in required_keys):
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('The following fields are required: {keys}').format(
|
||||
_('The following fields are required: {keys}').format(
|
||||
keys=", ".join(required_keys)))
|
||||
return False
|
||||
|
||||
try:
|
||||
model: BedrockEmbeddingModel = provider.get_model(model_type, model_name, model_credential)
|
||||
aa = model.embed_query(__('Hello'))
|
||||
aa = model.embed_query(_('Hello'))
|
||||
print(aa)
|
||||
except AppApiException:
|
||||
raise
|
||||
except Exception as e:
|
||||
if raise_exception:
|
||||
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)))
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -36,14 +36,14 @@ class BedrockLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
if not any(mt.get('value') == model_type for mt in model_type_list):
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
return False
|
||||
|
||||
required_keys = ['region_name', 'access_key_id', 'secret_access_key']
|
||||
if not all(key in model_credential for key in required_keys):
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('The following fields are required: {keys}').format(
|
||||
gettext('The following fields are required: {keys}').format(
|
||||
keys=", ".join(required_keys)))
|
||||
return False
|
||||
|
||||
|
|
@ -55,7 +55,8 @@ class BedrockLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
except Exception as e:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -23,23 +23,23 @@ class AzureOpenAIEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key', 'api_version']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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:
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from common import forms
|
|||
from common.exception.app_exception import AppApiException
|
||||
from common.forms import BaseForm, TooltipLabel
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
|
||||
class AzureOpenAIImageModelParams(BaseForm):
|
||||
|
|
@ -41,12 +41,12 @@ class AzureOpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key', 'api_version']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -59,7 +59,8 @@ class AzureOpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from common import forms
|
|||
from common.exception.app_exception import AppApiException
|
||||
from common.forms import BaseForm, TooltipLabel
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
|
||||
class AzureLLMModelParams(BaseForm):
|
||||
|
|
@ -43,12 +43,12 @@ class AzureLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key', 'deployment_name', 'api_version']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -59,7 +59,7 @@ class AzureLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct'))
|
||||
gettext('Verification failed, please check whether the parameters are correct'))
|
||||
else:
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -19,12 +19,12 @@ class AzureOpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key', 'api_version']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -35,7 +35,7 @@ class AzureOpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -54,12 +54,12 @@ class AzureOpenAITextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key', 'api_version']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -71,7 +71,8 @@ class AzureOpenAITextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -12,7 +12,8 @@ from setting.models_provider.base_model_provider import BaseModelCredential, Val
|
|||
class AzureOpenAITTSModelGeneralParams(BaseForm):
|
||||
# alloy, echo, fable, onyx, nova, shimmer
|
||||
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',
|
||||
text_field='value',
|
||||
value_field='value',
|
||||
|
|
@ -35,12 +36,13 @@ class AzureOpenAITTSModelCredential(BaseForm, BaseModelCredential):
|
|||
raise_exception=False):
|
||||
model_type_list = provider.get_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,
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key', 'api_version']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -50,7 +52,9 @@ class AzureOpenAITTSModelCredential(BaseForm, BaseModelCredential):
|
|||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
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, gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -43,23 +43,24 @@ class DeepSeekLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -22,23 +22,23 @@ class GeminiEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -38,17 +38,17 @@ class GeminiImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
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": gettext('Hello')}])])
|
||||
for chunk in res:
|
||||
print(chunk)
|
||||
except Exception as e:
|
||||
|
|
@ -56,7 +56,8 @@ class GeminiImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -43,24 +43,25 @@ class GeminiLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
res = model.invoke([HumanMessage(content=__('Hello'))])
|
||||
res = model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
print(res)
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -17,12 +17,12 @@ class GeminiSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -33,7 +33,7 @@ class GeminiSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from langchain_core.messages import HumanMessage
|
||||
from langchain_google_genai import ChatGoogleGenerativeAI
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ class GeminiSpeechToText(MaxKBBaseModel, BaseSpeechToText):
|
|||
model=self.model,
|
||||
google_api_key=self.api_key
|
||||
)
|
||||
response_list = client.invoke(__('Hello'))
|
||||
response_list = client.invoke(_('Hello'))
|
||||
# print(response_list)
|
||||
|
||||
def speech_to_text(self, audio_file):
|
||||
|
|
@ -50,7 +50,7 @@ class GeminiSpeechToText(MaxKBBaseModel, BaseSpeechToText):
|
|||
)
|
||||
audio_data = audio_file.read()
|
||||
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}
|
||||
])
|
||||
res = client.invoke([msg])
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -18,7 +18,8 @@ from setting.models_provider.base_model_provider import BaseModelCredential, Val
|
|||
|
||||
|
||||
class KimiLLMModelParams(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,
|
||||
_min=0.1,
|
||||
_max=1.0,
|
||||
|
|
@ -26,7 +27,8 @@ class KimiLLMModelParams(BaseForm):
|
|||
precision=2)
|
||||
|
||||
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,
|
||||
_min=1,
|
||||
_max=100000,
|
||||
|
|
@ -40,22 +42,25 @@ class KimiLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
raise_exception=False):
|
||||
model_type_list = provider.get_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,
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
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, gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -23,22 +23,23 @@ class LocalEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
raise_exception=False):
|
||||
if not model_type == 'EMBEDDING':
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['cache_folder']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model: LocalEmbedding = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(gettext('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from common.exception.app_exception import AppApiException
|
|||
from common.forms import BaseForm
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from setting.models_provider.impl.local_model_provider.model.reranker import LocalBaseReranker
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
|
||||
class LocalRerankerCredential(BaseForm, BaseModelCredential):
|
||||
|
|
@ -24,22 +24,23 @@ class LocalRerankerCredential(BaseForm, BaseModelCredential):
|
|||
raise_exception=False):
|
||||
if not model_type == 'RERANKER':
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['cache_dir']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
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=gettext('Hello'))], gettext('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -23,18 +23,18 @@ class OllamaEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
try:
|
||||
model_list = provider.get_base_model_list(model_credential.get('api_base'))
|
||||
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
|
||||
model.get('model') == model_name or model.get('model').replace(":latest", "") == model_name]
|
||||
if len(exist) == 0:
|
||||
raise AppApiException(ValidCode.model_not_fount,
|
||||
__('The model does not exist, please download the model first'))
|
||||
_('The model does not exist, please download the model first'))
|
||||
model: LocalEmbedding = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
return True
|
||||
|
||||
def encryption_dict(self, model_info: Dict[str, object]):
|
||||
|
|
@ -43,7 +43,7 @@ class OllamaEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
|||
def build_model(self, model_info: Dict[str, object]):
|
||||
for key in ['model']:
|
||||
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
|
||||
|
||||
api_base = forms.TextInputField('API URL', required=True)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from common import forms
|
|||
from common.exception.app_exception import AppApiException
|
||||
from common.forms import BaseForm, TooltipLabel
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
|
||||
class OllamaImageModelParams(BaseForm):
|
||||
|
|
@ -36,16 +36,16 @@ class OllamaImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
try:
|
||||
model_list = provider.get_base_model_list(model_credential.get('api_base'))
|
||||
except Exception as e:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('API domain name is invalid'))
|
||||
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]
|
||||
if len(exist) == 0:
|
||||
raise AppApiException(ValidCode.model_not_fount,
|
||||
__('The model does not exist, please download the model first'))
|
||||
gettext('The model does not exist, please download the model first'))
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -41,16 +41,16 @@ class OllamaLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
try:
|
||||
model_list = provider.get_base_model_list(model_credential.get('api_base'))
|
||||
except Exception as e:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('API domain name is invalid'))
|
||||
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]
|
||||
if len(exist) == 0:
|
||||
raise AppApiException(ValidCode.model_not_fount,
|
||||
__('The model does not exist, please download the model first'))
|
||||
gettext('The model does not exist, please download the model first'))
|
||||
return True
|
||||
|
||||
def encryption_dict(self, model_info: Dict[str, object]):
|
||||
|
|
@ -59,7 +59,7 @@ class OllamaLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
def build_model(self, model_info: Dict[str, object]):
|
||||
for key in ['api_key', 'model']:
|
||||
if key not in model_info:
|
||||
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||
raise AppApiException(500, gettext('{key} is required').format(key=key))
|
||||
self.api_key = model_info.get('api_key')
|
||||
return self
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -22,23 +22,23 @@ class OpenAIEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from common import forms
|
|||
from common.exception.app_exception import AppApiException
|
||||
from common.forms import BaseForm, TooltipLabel
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
|
||||
class OpenAIImageModelParams(BaseForm):
|
||||
|
|
@ -40,12 +40,12 @@ class OpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -58,7 +58,8 @@ class OpenAIImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -43,24 +43,25 @@ class OpenAILLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -18,12 +18,12 @@ class OpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -34,7 +34,7 @@ class OpenAISTTModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -57,12 +57,12 @@ class OpenAITextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -74,7 +74,8 @@ class OpenAITextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -36,12 +36,12 @@ class OpenAITTSModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -52,7 +52,8 @@ class OpenAITTSModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -43,16 +43,16 @@ class QwenVLModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
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": gettext('Hello')}])])
|
||||
for chunk in res:
|
||||
print(chunk)
|
||||
except Exception as e:
|
||||
|
|
@ -60,7 +60,8 @@ class QwenVLModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -43,22 +43,23 @@ class OpenAILLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -64,11 +64,11 @@ class QwenTextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -80,7 +80,8 @@ class QwenTextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from http import HTTPStatus
|
|||
from typing import Dict
|
||||
|
||||
from dashscope import ImageSynthesis
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from langchain_community.chat_models import ChatTongyi
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ class QwenTextToImageModel(MaxKBBaseModel, BaseTextToImage):
|
|||
|
||||
def check_auth(self):
|
||||
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):
|
||||
# api_base='https://dashscope.aliyuncs.com/compatible-mode/v1',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -15,17 +15,17 @@ class TencentEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
self.valid_form(model_credential)
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -43,16 +43,16 @@ class TencentVisionModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
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": gettext('Hello')}])])
|
||||
for chunk in res:
|
||||
print(chunk)
|
||||
except Exception as e:
|
||||
|
|
@ -60,7 +60,8 @@ class TencentVisionModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# coding=utf-8
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -26,7 +26,7 @@ class TencentLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
if not any(mt['value'] == model_type for mt in provider.get_model_type_list()):
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ class TencentLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
if missing_keys:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('{keys} is required').format(keys=", ".join(missing_keys)))
|
||||
gettext('{keys} is required').format(keys=", ".join(missing_keys)))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -46,11 +46,12 @@ class TencentLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
return False
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# coding=utf-8
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -74,7 +74,7 @@ class TencentTTIModelCredential(BaseForm, BaseModelCredential):
|
|||
if not any(mt['value'] == model_type for mt in provider.get_model_type_list()):
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ class TencentTTIModelCredential(BaseForm, BaseModelCredential):
|
|||
if missing_keys:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('{keys} is required').format(keys=", ".join(missing_keys)))
|
||||
gettext('{keys} is required').format(keys=", ".join(missing_keys)))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -98,7 +98,8 @@ class TencentTTIModelCredential(BaseForm, BaseModelCredential):
|
|||
except Exception as e:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
return False
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
import json
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from tencentcloud.common import credential
|
||||
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
|
||||
from tencentcloud.common.profile.client_profile import ClientProfile
|
||||
|
|
@ -51,7 +51,7 @@ class TencentTextToImageModel(MaxKBBaseModel, BaseTextToImage):
|
|||
hunyuan_secret_id=self.hunyuan_secret_id,
|
||||
hunyuan_secret_key=self.hunyuan_secret_key,
|
||||
model="hunyuan-standard")
|
||||
res = chat.invoke(__('Hello'))
|
||||
res = chat.invoke(_('Hello'))
|
||||
# print(res)
|
||||
|
||||
def generate_image(self, prompt: str, negative_prompt: str = None):
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -22,23 +22,23 @@ class VllmEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -38,12 +38,12 @@ class VllmImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -56,7 +56,8 @@ class VllmImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -36,18 +36,18 @@ class VLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
try:
|
||||
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'))
|
||||
except Exception as e:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('API domain name is invalid'))
|
||||
exist = provider.get_model_info_by_name(model_list, model_name)
|
||||
if len(exist) == 0:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('The model does not exist, please download the model first'))
|
||||
gettext('The model does not exist, please download the model first'))
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
try:
|
||||
res = model.invoke([HumanMessage(content=__('Hello'))])
|
||||
res = model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
print(res)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
|
@ -59,7 +59,7 @@ class VLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
def build_model(self, model_info: Dict[str, object]):
|
||||
for key in ['api_key', 'model']:
|
||||
if key not in model_info:
|
||||
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||
raise AppApiException(500, gettext('{key} is required').format(key=key))
|
||||
self.api_key = model_info.get('api_key')
|
||||
return self
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -22,23 +22,23 @@ class VolcanicEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -38,17 +38,17 @@ class VolcanicEngineImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key', 'api_base']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
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": gettext('Hello')}])])
|
||||
for chunk in res:
|
||||
print(chunk)
|
||||
except Exception as e:
|
||||
|
|
@ -56,7 +56,8 @@ class VolcanicEngineImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -43,24 +43,25 @@ class VolcanicEngineLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['access_key_id', 'secret_access_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
res = model.invoke([HumanMessage(content=__('Hello'))])
|
||||
res = model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
print(res)
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -22,12 +22,12 @@ class VolcanicEngineSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{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']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -38,7 +38,7 @@ class VolcanicEngineSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -37,12 +37,13 @@ class VolcanicEngineTTIModelCredential(BaseForm, BaseModelCredential):
|
|||
raise_exception=False):
|
||||
model_type_list = provider.get_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,
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['access_key', 'secret_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -52,7 +53,9 @@ class VolcanicEngineTTIModelCredential(BaseForm, BaseModelCredential):
|
|||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
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, gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
from common.forms import BaseForm, TooltipLabel
|
||||
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
|
||||
|
||||
class VolcanicEngineTTSModelGeneralParams(BaseForm):
|
||||
|
|
@ -38,7 +39,8 @@ class VolcanicEngineTTSModelGeneralParams(BaseForm):
|
|||
|
||||
|
||||
class VolcanicEngineTTSModelCredential(BaseForm, BaseModelCredential):
|
||||
volcanic_api_url = forms.TextInputField('API URL', required=True, default_value='wss://openspeech.bytedance.com/api/v1/tts/ws_binary')
|
||||
volcanic_api_url = forms.TextInputField('API URL', required=True,
|
||||
default_value='wss://openspeech.bytedance.com/api/v1/tts/ws_binary')
|
||||
volcanic_app_id = forms.TextInputField('App ID', required=True)
|
||||
volcanic_token = forms.PasswordInputField('Access Token', required=True)
|
||||
volcanic_cluster = forms.TextInputField('Cluster ID', required=True)
|
||||
|
|
@ -47,12 +49,13 @@ class VolcanicEngineTTSModelCredential(BaseForm, BaseModelCredential):
|
|||
raise_exception=False):
|
||||
model_type_list = provider.get_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,
|
||||
gettext('{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']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -62,7 +65,9 @@ class VolcanicEngineTTSModelCredential(BaseForm, BaseModelCredential):
|
|||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
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, gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import uuid
|
|||
from typing import Dict
|
||||
|
||||
import websockets
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common.util.common import _remove_empty_lines
|
||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||
|
|
@ -74,7 +74,7 @@ class VolcanicEngineTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||
)
|
||||
|
||||
def check_auth(self):
|
||||
self.text_to_speech(__('Hello'))
|
||||
self.text_to_speech(_('Hello'))
|
||||
|
||||
def text_to_speech(self, text):
|
||||
request_json = {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -23,17 +23,17 @@ class QianfanEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
self.valid_form(model_credential)
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -42,21 +42,21 @@ class WenxinLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{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_info = [model.lower() for model in model.client.models()]
|
||||
if not model_info.__contains__(model_name.lower()):
|
||||
if not model_info.__containsgettext(model_name.lower()):
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('{model_name} The model does not support').format(model_name=model_name))
|
||||
gettext('{model_name} The model does not support').format(model_name=model_name))
|
||||
for key in ['api_key', 'secret_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model.invoke(
|
||||
[HumanMessage(content=__('Hello'))])
|
||||
[HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
raise e
|
||||
return True
|
||||
|
|
@ -67,7 +67,7 @@ class WenxinLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
def build_model(self, model_info: Dict[str, object]):
|
||||
for key in ['api_key', 'secret_key', 'model']:
|
||||
if key not in model_info:
|
||||
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||
raise AppApiException(500, gettext('{key} is required').format(key=key))
|
||||
self.api_key = model_info.get('api_key')
|
||||
self.secret_key = model_info.get('secret_key')
|
||||
return self
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -23,17 +23,17 @@ class XFEmbeddingCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
self.valid_form(model_credential)
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential)
|
||||
model.embed_query(__('Hello'))
|
||||
model.embed_query(_('Hello'))
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import base64
|
|||
import os
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -25,12 +25,12 @@ class XunFeiImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{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']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -38,14 +38,14 @@ class XunFeiImageModelCredential(BaseForm, BaseModelCredential):
|
|||
cwd = os.path.dirname(os.path.abspath(__file__))
|
||||
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'))]
|
||||
HumanMessage(_('Please outline this picture'))]
|
||||
model.stream(message_list)
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -62,23 +62,24 @@ class XunFeiLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{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']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -21,12 +21,12 @@ class XunFeiSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{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']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -37,7 +37,7 @@ class XunFeiSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -44,12 +44,12 @@ class XunFeiTTSModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{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']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -60,7 +60,8 @@ class XunFeiTTSModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ from typing import Dict
|
|||
from urllib.parse import urlencode, urlparse
|
||||
|
||||
import websockets
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common.util.common import _remove_empty_lines
|
||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||
|
|
@ -98,7 +98,7 @@ class XFSparkTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||
return url
|
||||
|
||||
def check_auth(self):
|
||||
self.text_to_speech(__('Hello'))
|
||||
self.text_to_speech(_('Hello'))
|
||||
|
||||
def text_to_speech(self, text):
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -16,19 +16,19 @@ class XinferenceEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
try:
|
||||
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'),
|
||||
'embedding')
|
||||
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)
|
||||
model: LocalEmbedding = provider.get_model(model_type, model_name, model_credential)
|
||||
if len(exist) == 0:
|
||||
model.start_down_model_thread()
|
||||
raise AppApiException(ValidCode.model_not_fount,
|
||||
__('The model does not exist, please download the model first'))
|
||||
model.embed_query(__('Hello'))
|
||||
_('The model does not exist, please download the model first'))
|
||||
model.embed_query(_('Hello'))
|
||||
return True
|
||||
|
||||
def encryption_dict(self, model_info: Dict[str, object]):
|
||||
|
|
@ -37,7 +37,7 @@ class XinferenceEmbeddingModelCredential(BaseForm, BaseModelCredential):
|
|||
def build_model(self, model_info: Dict[str, object]):
|
||||
for key in ['model']:
|
||||
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
|
||||
|
||||
api_base = forms.TextInputField('API URL', required=True)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -38,17 +38,17 @@ class XinferenceImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
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": gettext('Hello')}])])
|
||||
for chunk in res:
|
||||
print(chunk)
|
||||
except Exception as e:
|
||||
|
|
@ -56,7 +56,8 @@ class XinferenceImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -36,18 +36,18 @@ class XinferenceLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
try:
|
||||
model_list = provider.get_base_model_list(model_credential.get('api_base'), model_credential.get('api_key'),
|
||||
model_type)
|
||||
except Exception as e:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('API domain name is invalid'))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('API domain name is invalid'))
|
||||
exist = provider.get_model_info_by_name(model_list, model_name)
|
||||
if len(exist) == 0:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('The model does not exist, please download the model first'))
|
||||
gettext('The model does not exist, please download the model first'))
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
return True
|
||||
|
||||
def encryption_dict(self, model_info: Dict[str, object]):
|
||||
|
|
@ -56,7 +56,7 @@ class XinferenceLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
def build_model(self, model_info: Dict[str, object]):
|
||||
for key in ['api_key', 'model']:
|
||||
if key not in model_info:
|
||||
raise AppApiException(500, __('{key} is required').format(key=key))
|
||||
raise AppApiException(500, gettext('{key} is required').format(key=key))
|
||||
self.api_key = model_info.get('api_key')
|
||||
return self
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from langchain_core.documents import Document
|
||||
|
||||
from common import forms
|
||||
|
|
@ -22,22 +22,22 @@ class XInferenceRerankerModelCredential(BaseForm, BaseModelCredential):
|
|||
raise_exception=True):
|
||||
if not model_type == 'RERANKER':
|
||||
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 ['server_url']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
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:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -18,12 +18,12 @@ class XInferenceSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
_('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
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:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -34,7 +34,7 @@ class XInferenceSTTModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
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)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -56,12 +56,12 @@ class XinferenceTextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -73,7 +73,8 @@ class XinferenceTextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -36,12 +36,12 @@ class XInferenceTTSModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_base', 'api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -52,7 +52,8 @@ class XInferenceTTSModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from common.config.tokenizer_manage_config import TokenizerManage
|
|||
from common.util.common import _remove_empty_lines
|
||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
|
||||
def custom_get_token_ids(text: str):
|
||||
|
|
@ -41,7 +41,7 @@ class XInferenceTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||
)
|
||||
|
||||
def check_auth(self):
|
||||
self.text_to_speech(__('Hello'))
|
||||
self.text_to_speech(_('Hello'))
|
||||
|
||||
def text_to_speech(self, text):
|
||||
client = OpenAI(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -37,17 +37,17 @@ class ZhiPuImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
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": gettext('Hello')}])])
|
||||
for chunk in res:
|
||||
print(chunk)
|
||||
except Exception as e:
|
||||
|
|
@ -55,7 +55,8 @@ class ZhiPuImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"""
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from common import forms
|
||||
|
|
@ -43,22 +43,23 @@ class ZhiPuLLMModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
model = provider.get_model(model_type, model_name, model_credential, **model_params)
|
||||
model.invoke([HumanMessage(content=__('Hello'))])
|
||||
model.invoke([HumanMessage(content=gettext('Hello'))])
|
||||
except Exception as e:
|
||||
if isinstance(e, AppApiException):
|
||||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# coding=utf-8
|
||||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext_lazy as _, gettext as __
|
||||
from django.utils.translation import gettext_lazy as _, gettext
|
||||
|
||||
from common import forms
|
||||
from common.exception.app_exception import AppApiException
|
||||
|
|
@ -36,12 +36,12 @@ class ZhiPuTextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
model_type_list = provider.get_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))
|
||||
gettext('{model_type} Model type is not supported').format(model_type=model_type))
|
||||
|
||||
for key in ['api_key']:
|
||||
if key not in model_credential:
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value, __('{key} is required').format(key=key))
|
||||
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
|
|
@ -53,7 +53,8 @@ class ZhiPuTextToImageModelCredential(BaseForm, BaseModelCredential):
|
|||
raise e
|
||||
if raise_exception:
|
||||
raise AppApiException(ValidCode.valid_error.value,
|
||||
__('Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
gettext(
|
||||
'Verification failed, please check whether the parameters are correct: {error}').format(
|
||||
error=str(e)))
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Dict
|
||||
|
||||
from django.utils.translation import gettext as __
|
||||
from django.utils.translation import gettext as _
|
||||
from langchain_community.chat_models import ChatZhipuAI
|
||||
from langchain_core.messages import HumanMessage
|
||||
from zhipuai import ZhipuAI
|
||||
|
|
@ -46,7 +46,7 @@ class ZhiPuTextToImage(MaxKBBaseModel, BaseTextToImage):
|
|||
zhipuai_api_key=self.api_key,
|
||||
model_name=self.model,
|
||||
)
|
||||
chat.invoke([HumanMessage([{"type": "text", "text": __('Hello')}])])
|
||||
chat.invoke([HumanMessage([{"type": "text", "text": _('Hello')}])])
|
||||
|
||||
# self.generate_image('生成一个小猫图片')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue