diff --git a/apps/common/handle/impl/pdf_split_handle.py b/apps/common/handle/impl/pdf_split_handle.py index 8de0129e1..fa8f62fa5 100644 --- a/apps/common/handle/impl/pdf_split_handle.py +++ b/apps/common/handle/impl/pdf_split_handle.py @@ -31,6 +31,16 @@ default_pattern_list = [re.compile('(?<=^)# .*|(?<=\\n)# .*'), max_kb = logging.getLogger("max_kb") +def check_links_in_pdf(doc): + for page_number in range(len(doc)): + page = doc[page_number] + links = page.get_links() + if links: + for link in links: + if link['kind'] == 1: + return True + return False + class PdfSplitHandle(BaseSplitHandle): def handle(self, file, pattern_list: List, with_filter: bool, limit: int, get_buffer, save_image): with tempfile.NamedTemporaryFile(delete=False) as temp_file: @@ -175,6 +185,9 @@ class PdfSplitHandle(BaseSplitHandle): @staticmethod def handle_links(doc, pattern_list, with_filter, limit): + # 检查文档是否包含内部链接 + if not check_links_in_pdf(doc): + return # 创建存储章节内容的数组 chapters = [] toc_start_page = -1 diff --git a/apps/setting/models_provider/impl/zhipu_model_provider/credential/image.py b/apps/setting/models_provider/impl/zhipu_model_provider/credential/image.py new file mode 100644 index 000000000..0eb05bb91 --- /dev/null +++ b/apps/setting/models_provider/impl/zhipu_model_provider/credential/image.py @@ -0,0 +1,47 @@ +# coding=utf-8 +import base64 +import os +from typing import Dict + +from langchain_core.messages import HumanMessage + +from common import forms +from common.exception.app_exception import AppApiException +from common.forms import BaseForm +from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode + + +class ZhiPuImageModelCredential(BaseForm, BaseModelCredential): + api_key = forms.PasswordInputField('API Key', required=True) + + def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], provider, + 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, f'{model_type} 模型类型不支持') + + for key in ['api_key']: + if key not in model_credential: + if raise_exception: + raise AppApiException(ValidCode.valid_error.value, f'{key} 字段为必填字段') + else: + return False + try: + model = provider.get_model(model_type, model_name, model_credential) + res = model.stream([HumanMessage(content=[{"type": "text", "text": "你好"}])]) + for chunk in res: + print(chunk) + except Exception as e: + if isinstance(e, AppApiException): + raise e + if raise_exception: + raise AppApiException(ValidCode.valid_error.value, f'校验失败,请检查参数是否正确: {str(e)}') + else: + return False + return True + + def encryption_dict(self, model: Dict[str, object]): + return {**model, 'api_key': super().encryption(model.get('api_key', ''))} + + def get_model_params_setting_form(self, model_name): + pass diff --git a/apps/setting/models_provider/impl/zhipu_model_provider/model/image.py b/apps/setting/models_provider/impl/zhipu_model_provider/model/image.py new file mode 100644 index 000000000..d1658a0c0 --- /dev/null +++ b/apps/setting/models_provider/impl/zhipu_model_provider/model/image.py @@ -0,0 +1,26 @@ +from typing import Dict + +from langchain_openai.chat_models import ChatOpenAI + +from common.config.tokenizer_manage_config import TokenizerManage +from setting.models_provider.base_model_provider import MaxKBBaseModel + + +def custom_get_token_ids(text: str): + tokenizer = TokenizerManage.get_tokenizer() + return tokenizer.encode(text) + + +class ZhiPuImage(MaxKBBaseModel, ChatOpenAI): + + @staticmethod + def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs): + optional_params = MaxKBBaseModel.filter_optional_params(model_kwargs) + return ZhiPuImage( + model_name=model_name, + openai_api_key=model_credential.get('api_key'), + openai_api_base='https://open.bigmodel.cn/api/paas/v4', + # stream_options={"include_usage": True}, + streaming=True, + **optional_params, + ) diff --git a/apps/setting/models_provider/impl/zhipu_model_provider/zhipu_model_provider.py b/apps/setting/models_provider/impl/zhipu_model_provider/zhipu_model_provider.py index ab19b1567..b24c8dd0d 100644 --- a/apps/setting/models_provider/impl/zhipu_model_provider/zhipu_model_provider.py +++ b/apps/setting/models_provider/impl/zhipu_model_provider/zhipu_model_provider.py @@ -11,18 +11,40 @@ import os from common.util.file_util import get_file_content from setting.models_provider.base_model_provider import ModelProvideInfo, ModelTypeConst, ModelInfo, IModelProvider, \ ModelInfoManage +from setting.models_provider.impl.zhipu_model_provider.credential.image import ZhiPuImageModelCredential from setting.models_provider.impl.zhipu_model_provider.credential.llm import ZhiPuLLMModelCredential +from setting.models_provider.impl.zhipu_model_provider.model.image import ZhiPuImage from setting.models_provider.impl.zhipu_model_provider.model.llm import ZhipuChatModel from smartdoc.conf import PROJECT_DIR qwen_model_credential = ZhiPuLLMModelCredential() +zhipu_image_model_credential = ZhiPuImageModelCredential() + model_info_list = [ ModelInfo('glm-4', '', ModelTypeConst.LLM, qwen_model_credential, ZhipuChatModel), ModelInfo('glm-4v', '', ModelTypeConst.LLM, qwen_model_credential, ZhipuChatModel), ModelInfo('glm-3-turbo', '', ModelTypeConst.LLM, qwen_model_credential, ZhipuChatModel) ] -model_info_manage = ModelInfoManage.builder().append_model_info_list(model_info_list).append_default_model_info( - ModelInfo('glm-4', '', ModelTypeConst.LLM, qwen_model_credential, ZhipuChatModel)).build() + +model_info_image_list = [ + ModelInfo('glm-4v-plus', '具有强大的多模态理解能力。能够同时理解多达五张图像,并支持视频内容理解', + ModelTypeConst.IMAGE, zhipu_image_model_credential, + ZhiPuImage), + ModelInfo('glm-4v', '专注于单图理解。适用于需要高效图像解析的场景', + ModelTypeConst.IMAGE, zhipu_image_model_credential, + ZhiPuImage), + ModelInfo('glm-4v-flash', '专注于单图理解。适用于需要高效图像解析的场景(免费)', + ModelTypeConst.IMAGE, zhipu_image_model_credential, + ZhiPuImage), +] + +model_info_manage = ( + ModelInfoManage.builder() + .append_model_info_list(model_info_list) + .append_default_model_info(ModelInfo('glm-4', '', ModelTypeConst.LLM, qwen_model_credential, ZhipuChatModel)) + .append_model_info_list(model_info_image_list) + .build() +) class ZhiPuModelProvider(IModelProvider): diff --git a/installer/Dockerfile b/installer/Dockerfile index c990f0afe..bc3d8a4b2 100644 --- a/installer/Dockerfile +++ b/installer/Dockerfile @@ -42,7 +42,7 @@ ENV MAXKB_VERSION="${DOCKER_IMAGE_TAG} (build at ${BUILD_AT}, commit: ${GITHUB_C MAXKB_DB_PASSWORD=Password123@postgres \ MAXKB_EMBEDDING_MODEL_NAME=/opt/maxkb/model/embedding/shibing624_text2vec-base-chinese \ MAXKB_EMBEDDING_MODEL_PATH=/opt/maxkb/model/embedding \ - MAXKB_SANDBOX=true \ + MAXKB_SANDBOX=1 \ LANG=en_US.UTF-8 \ PATH=/opt/py3/bin:$PATH \ POSTGRES_USER=root \ diff --git a/ui/src/components/ai-chat/component/chat-input-operate/index.vue b/ui/src/components/ai-chat/component/chat-input-operate/index.vue index 004748175..3670b8537 100644 --- a/ui/src/components/ai-chat/component/chat-input-operate/index.vue +++ b/ui/src/components/ai-chat/component/chat-input-operate/index.vue @@ -6,7 +6,7 @@
+
@@ -200,7 +221,7 @@ const localLoading = computed({ const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp'] const documentExtensions = ['pdf', 'docx', 'txt', 'xls', 'xlsx', 'md', 'html', 'csv'] const videoExtensions = ['mp4', 'avi', 'mov', 'mkv', 'flv'] -const audioExtensions = ['mp3', 'wav', 'aac', 'flac'] +const audioExtensions = ['mp3'] const getAcceptList = () => { const { image, document, audio, video } = props.applicationDetails.file_upload_setting @@ -227,14 +248,14 @@ const getAcceptList = () => { const checkMaxFilesLimit = () => { return ( props.applicationDetails.file_upload_setting.maxFiles <= - uploadImageList.value.length + uploadDocumentList.value.length + uploadImageList.value.length + uploadDocumentList.value.length + uploadAudioList.value.length + uploadVideoList.value.length ) } const uploadFile = async (file: any, fileList: any) => { const { maxFiles, fileLimit } = props.applicationDetails.file_upload_setting // 单次上传文件数量限制 - const file_limit_once = uploadImageList.value.length + uploadDocumentList.value.length + const file_limit_once = uploadImageList.value.length + uploadDocumentList.value.length + uploadAudioList.value.length + uploadVideoList.value.length if (file_limit_once >= maxFiles) { MsgWarning('最多上传' + maxFiles + '个文件') fileList.splice(0, fileList.length) @@ -257,9 +278,9 @@ const uploadFile = async (file: any, fileList: any) => { } else if (documentExtensions.includes(extension)) { uploadDocumentList.value.push(file) } else if (videoExtensions.includes(extension)) { - // videos.push(file) + uploadVideoList.value.push(file) } else if (audioExtensions.includes(extension)) { - // audios.push(file) + uploadAudioList.value.push(file) } @@ -297,7 +318,20 @@ const uploadFile = async (file: any, fileList: any) => { file.file_id = f[0].file_id } }) - console.log(uploadDocumentList.value, uploadImageList.value) + uploadAudioList.value.forEach((file: any) => { + const f = response.data.filter((f: any) => f.name === file.name) + if (f.length > 0) { + file.url = f[0].url + file.file_id = f[0].file_id + } + }) + uploadVideoList.value.forEach((file: any) => { + const f = response.data.filter((f: any) => f.name === file.name) + if (f.length > 0) { + file.url = f[0].url + file.file_id = f[0].file_id + } + }) }) } const recorderTime = ref(0) @@ -306,6 +340,8 @@ const recorderLoading = ref(false) const inputValue = ref('') const uploadImageList = ref>([]) const uploadDocumentList = ref>([]) +const uploadVideoList = ref>([]) +const uploadAudioList = ref>([]) const mediaRecorderStatus = ref(true) const showDelete = ref('') @@ -433,11 +469,15 @@ function sendChatHandle(event: any) { if (inputValue.value.trim()) { props.sendMessage(inputValue.value, { image_list: uploadImageList.value, - document_list: uploadDocumentList.value + document_list: uploadDocumentList.value, + audio_list: uploadAudioList.value, + video_list: uploadVideoList.value, }) inputValue.value = '' uploadImageList.value = [] uploadDocumentList.value = [] + uploadAudioList.value = [] + uploadVideoList.value = [] quickInputRef.value.textareaStyle.height = '45px' } } @@ -452,6 +492,10 @@ function deleteFile(index: number, val: string) { uploadImageList.value.splice(index, 1) } else if (val === 'document') { uploadDocumentList.value.splice(index, 1) + } else if (val === 'video') { + uploadVideoList.value.splice(index, 1) + } else if (val === 'audio') { + uploadAudioList.value.splice(index, 1) } } function mouseenter(row: any) { diff --git a/ui/src/components/common-list/index.vue b/ui/src/components/common-list/index.vue index 3a8194d11..58fb39f55 100644 --- a/ui/src/components/common-list/index.vue +++ b/ui/src/components/common-list/index.vue @@ -73,6 +73,8 @@ defineExpose({ li { padding: 10px 16px; font-weight: 400; + color: var(--el-text-color-regular); + font-size: 14px; &.active { background: var(--el-color-primary-light-9); border-radius: 4px; diff --git a/ui/src/styles/element-plus.scss b/ui/src/styles/element-plus.scss index ef51fa7ba..e0177f493 100644 --- a/ui/src/styles/element-plus.scss +++ b/ui/src/styles/element-plus.scss @@ -133,6 +133,7 @@ .el-card { --el-card-padding: calc(var(--app-base-px) * 2); + color: var(--el-text-color-regular); } .el-dropdown { color: var(--app-text-color); @@ -267,6 +268,9 @@ .el-select-group .el-select-dropdown__item { padding-left: 11px; } +.el-select-dropdown__item { + font-weight: 400; +} .el-select__caret { color: var(--app-text-color-secondary); diff --git a/ui/src/views/authentication/component/EditModal.vue b/ui/src/views/authentication/component/EditModal.vue index 01259e6ab..917bd0147 100644 --- a/ui/src/views/authentication/component/EditModal.vue +++ b/ui/src/views/authentication/component/EditModal.vue @@ -120,8 +120,14 @@ const open = async (platform: Platform) => { let defaultCallbackUrl = window.location.origin switch (platform.key) { case 'wecom': + if (currentPlatform.config.app_key) { + currentPlatform.config.agent_id = currentPlatform.config.app_key + delete currentPlatform.config.app_key + } + currentPlatform.config.callback_url = `${defaultCallbackUrl}/api/wecom` + break case 'dingtalk': - if (currentPlatform.config.agent_id && currentPlatform.key === 'dingtalk') { + if (currentPlatform.config.agent_id) { currentPlatform.config.corp_id = currentPlatform.config.agent_id delete currentPlatform.config.agent_id } diff --git a/ui/src/views/template/index.vue b/ui/src/views/template/index.vue index 20c9a62e5..1216409f1 100644 --- a/ui/src/views/template/index.vue +++ b/ui/src/views/template/index.vue @@ -2,7 +2,7 @@
-

供应商

+

供应商