From 8438d820ad7b46bf03ba310fc0d2f81b796b8ff7 Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:58:06 +0800 Subject: [PATCH] Feat/2070 glm 4 and glm 3 turbo (#2114) --- api/core/file/message_file_parser.py | 4 +- api/core/file/upload_file_parser.py | 6 +-- .../zhipuai/llm/glm_3_turbo.yaml | 42 +++++++++++++++++++ .../model_providers/zhipuai/llm/glm_4.yaml | 42 +++++++++++++++++++ api/requirements.txt | 2 +- api/services/file_service.py | 2 + 6 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 api/core/model_runtime/model_providers/zhipuai/llm/glm_3_turbo.yaml create mode 100644 api/core/model_runtime/model_providers/zhipuai/llm/glm_4.yaml diff --git a/api/core/file/message_file_parser.py b/api/core/file/message_file_parser.py index 8d205f93cb..e651745e29 100644 --- a/api/core/file/message_file_parser.py +++ b/api/core/file/message_file_parser.py @@ -2,7 +2,7 @@ from typing import Dict, List, Optional, Union import requests from core.file.file_obj import FileObj, FileTransferMethod, FileType -from core.file.upload_file_parser import SUPPORT_EXTENSIONS +from services.file_service import IMAGE_EXTENSIONS from extensions.ext_database import db from models.account import Account from models.model import AppModelConfig, EndUser, MessageFile, UploadFile @@ -83,7 +83,7 @@ class MessageFileParser: UploadFile.tenant_id == self.tenant_id, UploadFile.created_by == user.id, UploadFile.created_by_role == ('account' if isinstance(user, Account) else 'end_user'), - UploadFile.extension.in_(SUPPORT_EXTENSIONS) + UploadFile.extension.in_(IMAGE_EXTENSIONS) ).first()) # check upload file is belong to tenant and user diff --git a/api/core/file/upload_file_parser.py b/api/core/file/upload_file_parser.py index 3eba8bb06c..ca63301a59 100644 --- a/api/core/file/upload_file_parser.py +++ b/api/core/file/upload_file_parser.py @@ -9,8 +9,8 @@ from typing import Optional from extensions.ext_storage import storage from flask import current_app -SUPPORT_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'svg'] - +IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'svg'] +IMAGE_EXTENSIONS.extend([ext.upper() for ext in IMAGE_EXTENSIONS]) class UploadFileParser: @classmethod @@ -18,7 +18,7 @@ class UploadFileParser: if not upload_file: return None - if upload_file.extension not in SUPPORT_EXTENSIONS: + if upload_file.extension not in IMAGE_EXTENSIONS: return None if current_app.config['MULTIMODAL_SEND_IMAGE_FORMAT'] == 'url' or force_url: diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm_3_turbo.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm_3_turbo.yaml new file mode 100644 index 0000000000..00e2907db4 --- /dev/null +++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm_3_turbo.yaml @@ -0,0 +1,42 @@ +model: glm-3-turbo +label: + en_US: glm-3-turbo +model_type: llm +model_properties: + mode: chat +parameter_rules: + - name: temperature + use_template: temperature + default: 0.95 + min: 0.0 + max: 1.0 + help: + zh_Hans: 采样温度,控制输出的随机性,必须为正数取值范围是:(0.0,1.0],不能等于 0,默认值为 0.95 值越大,会使输出更随机,更具创造性;值越小,输出会更加稳定或确定建议您根据应用场景调整 top_p 或 temperature 参数,但不要同时调整两个参数。 + en_US: Sampling temperature, controls the randomness of the output, must be a positive number. The value range is (0.0,1.0], which cannot be equal to 0. The default value is 0.95. The larger the value, the more random and creative the output will be; the smaller the value, The output will be more stable or certain. It is recommended that you adjust the top_p or temperature parameters according to the application scenario, but do not adjust both parameters at the same time. + - name: top_p + use_template: top_p + default: 0.7 + help: + zh_Hans: 用温度取样的另一种方法,称为核取样取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1,默认值为 0.7 模型考虑具有 top_p 概率质量tokens的结果例如:0.1 意味着模型解码器只考虑从前 10% 的概率的候选集中取 tokens 建议您根据应用场景调整 top_p 或 temperature 参数,但不要同时调整两个参数。 + en_US: Another method of temperature sampling is called kernel sampling. The value range is (0.0, 1.0) open interval, which cannot be equal to 0 or 1. The default value is 0.7. The model considers the results with top_p probability mass tokens. For example 0.1 means The model decoder only considers tokens from the candidate set with the top 10% probability. It is recommended that you adjust the top_p or temperature parameters according to the application scenario, but do not adjust both parameters at the same time. + - name: incremental + label: + zh_Hans: 增量返回 + en_US: Incremental + type: boolean + help: + zh_Hans: SSE接口调用时,用于控制每次返回内容方式是增量还是全量,不提供此参数时默认为增量返回,true 为增量返回,false 为全量返回。 + en_US: When the SSE interface is called, it is used to control whether the content is returned incrementally or in full. If this parameter is not provided, the default is incremental return. true means incremental return, false means full return. + required: false + - name: return_type + label: + zh_Hans: 回复类型 + en_US: Return Type + type: string + help: + zh_Hans: 用于控制每次返回内容的类型,空或者没有此字段时默认按照 json_string 返回,json_string 返回标准的 JSON 字符串,text 返回原始的文本内容。 + en_US: Used to control the type of content returned each time. When it is empty or does not have this field, it will be returned as json_string by default. json_string returns a standard JSON string, and text returns the original text content. + required: false + options: + - text + - json_string diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4.yaml new file mode 100644 index 0000000000..7aaa454532 --- /dev/null +++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4.yaml @@ -0,0 +1,42 @@ +model: glm-4 +label: + en_US: glm-4 +model_type: llm +model_properties: + mode: chat +parameter_rules: + - name: temperature + use_template: temperature + default: 0.95 + min: 0.0 + max: 1.0 + help: + zh_Hans: 采样温度,控制输出的随机性,必须为正数取值范围是:(0.0,1.0],不能等于 0,默认值为 0.95 值越大,会使输出更随机,更具创造性;值越小,输出会更加稳定或确定建议您根据应用场景调整 top_p 或 temperature 参数,但不要同时调整两个参数。 + en_US: Sampling temperature, controls the randomness of the output, must be a positive number. The value range is (0.0,1.0], which cannot be equal to 0. The default value is 0.95. The larger the value, the more random and creative the output will be; the smaller the value, The output will be more stable or certain. It is recommended that you adjust the top_p or temperature parameters according to the application scenario, but do not adjust both parameters at the same time. + - name: top_p + use_template: top_p + default: 0.7 + help: + zh_Hans: 用温度取样的另一种方法,称为核取样取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1,默认值为 0.7 模型考虑具有 top_p 概率质量tokens的结果例如:0.1 意味着模型解码器只考虑从前 10% 的概率的候选集中取 tokens 建议您根据应用场景调整 top_p 或 temperature 参数,但不要同时调整两个参数。 + en_US: Another method of temperature sampling is called kernel sampling. The value range is (0.0, 1.0) open interval, which cannot be equal to 0 or 1. The default value is 0.7. The model considers the results with top_p probability mass tokens. For example 0.1 means The model decoder only considers tokens from the candidate set with the top 10% probability. It is recommended that you adjust the top_p or temperature parameters according to the application scenario, but do not adjust both parameters at the same time. + - name: incremental + label: + zh_Hans: 增量返回 + en_US: Incremental + type: boolean + help: + zh_Hans: SSE接口调用时,用于控制每次返回内容方式是增量还是全量,不提供此参数时默认为增量返回,true 为增量返回,false 为全量返回。 + en_US: When the SSE interface is called, it is used to control whether the content is returned incrementally or in full. If this parameter is not provided, the default is incremental return. true means incremental return, false means full return. + required: false + - name: return_type + label: + zh_Hans: 回复类型 + en_US: Return Type + type: string + help: + zh_Hans: 用于控制每次返回内容的类型,空或者没有此字段时默认按照 json_string 返回,json_string 返回标准的 JSON 字符串,text 返回原始的文本内容。 + en_US: Used to control the type of content returned each time. When it is empty or does not have this field, it will be returned as json_string by default. json_string returns a standard JSON string, and text returns the original text content. + required: false + options: + - text + - json_string diff --git a/api/requirements.txt b/api/requirements.txt index eaff59ea33..d5103da2bc 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -35,7 +35,7 @@ chardet~=5.1.0 docx2txt==0.8 pypdfium2==4.16.0 resend~=0.7.0 -pyjwt~=2.6.0 +pyjwt~=2.8.0 anthropic~=0.7.7 newspaper3k==0.2.8 google-api-python-client==2.90.0 diff --git a/api/services/file_service.py b/api/services/file_service.py index 2bae71e077..fd95cff74a 100644 --- a/api/services/file_service.py +++ b/api/services/file_service.py @@ -16,6 +16,8 @@ from werkzeug.datastructures import FileStorage from werkzeug.exceptions import NotFound IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'svg'] +IMAGE_EXTENSIONS.extend([ext.upper() for ext in IMAGE_EXTENSIONS]) + ALLOWED_EXTENSIONS = ['txt', 'markdown', 'md', 'pdf', 'html', 'htm', 'xlsx', 'docx', 'doc', 'csv'] + IMAGE_EXTENSIONS UNSTRUSTURED_ALLOWED_EXTENSIONS = ['txt', 'markdown', 'md', 'pdf', 'html', 'htm', 'xlsx', 'docx', 'doc', 'csv', 'eml', 'msg', 'pptx', 'ppt', 'xml'] + IMAGE_EXTENSIONS