mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-23 09:46:53 +08:00
chore: apply ruff E501 line-too-long linter rule (#8275)
Co-authored-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
@@ -8,8 +8,11 @@ PARAMETER_RULE_TEMPLATE: dict[DefaultParameterName, dict] = {
|
||||
},
|
||||
"type": "float",
|
||||
"help": {
|
||||
"en_US": "Controls randomness. Lower temperature results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive. Higher temperature results in more random completions.",
|
||||
"zh_Hans": "温度控制随机性。较低的温度会导致较少的随机完成。随着温度接近零,模型将变得确定性和重复性。较高的温度会导致更多的随机完成。",
|
||||
"en_US": "Controls randomness. Lower temperature results in less random completions."
|
||||
" As the temperature approaches zero, the model will become deterministic and repetitive."
|
||||
" Higher temperature results in more random completions.",
|
||||
"zh_Hans": "温度控制随机性。较低的温度会导致较少的随机完成。随着温度接近零,模型将变得确定性和重复性。"
|
||||
"较高的温度会导致更多的随机完成。",
|
||||
},
|
||||
"required": False,
|
||||
"default": 0.0,
|
||||
@@ -24,7 +27,8 @@ PARAMETER_RULE_TEMPLATE: dict[DefaultParameterName, dict] = {
|
||||
},
|
||||
"type": "float",
|
||||
"help": {
|
||||
"en_US": "Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered.",
|
||||
"en_US": "Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options"
|
||||
" are considered.",
|
||||
"zh_Hans": "通过核心采样控制多样性:0.5表示考虑了一半的所有可能性加权选项。",
|
||||
},
|
||||
"required": False,
|
||||
@@ -88,7 +92,8 @@ PARAMETER_RULE_TEMPLATE: dict[DefaultParameterName, dict] = {
|
||||
},
|
||||
"type": "int",
|
||||
"help": {
|
||||
"en_US": "Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.",
|
||||
"en_US": "Specifies the upper limit on the length of generated results."
|
||||
" If the generated results are truncated, you can increase this parameter.",
|
||||
"zh_Hans": "指定生成结果长度的上限。如果生成结果截断,可以调大该参数。",
|
||||
},
|
||||
"required": False,
|
||||
@@ -104,7 +109,8 @@ PARAMETER_RULE_TEMPLATE: dict[DefaultParameterName, dict] = {
|
||||
},
|
||||
"type": "string",
|
||||
"help": {
|
||||
"en_US": "Set a response format, ensure the output from llm is a valid code block as possible, such as JSON, XML, etc.",
|
||||
"en_US": "Set a response format, ensure the output from llm is a valid code block as possible,"
|
||||
" such as JSON, XML, etc.",
|
||||
"zh_Hans": "设置一个返回格式,确保llm的输出尽可能是有效的代码块,如JSON、XML等",
|
||||
},
|
||||
"required": False,
|
||||
|
||||
@@ -72,7 +72,9 @@ class AIModel(ABC):
|
||||
if isinstance(error, tuple(model_errors)):
|
||||
if invoke_error == InvokeAuthorizationError:
|
||||
return invoke_error(
|
||||
description=f"[{provider_name}] Incorrect model credentials provided, please check and try again. "
|
||||
description=(
|
||||
f"[{provider_name}] Incorrect model credentials provided, please check and try again."
|
||||
)
|
||||
)
|
||||
|
||||
return invoke_error(description=f"[{provider_name}] {invoke_error.description}, {str(error)}")
|
||||
|
||||
@@ -187,7 +187,7 @@ if you are not sure about the structure.
|
||||
<instructions>
|
||||
{{instructions}}
|
||||
</instructions>
|
||||
"""
|
||||
""" # noqa: E501
|
||||
|
||||
code_block = model_parameters.get("response_format", "")
|
||||
if not code_block:
|
||||
@@ -830,7 +830,8 @@ if you are not sure about the structure.
|
||||
else:
|
||||
if parameter_value != round(parameter_value, parameter_rule.precision):
|
||||
raise ValueError(
|
||||
f"Model Parameter {parameter_name} should be round to {parameter_rule.precision} decimal places."
|
||||
f"Model Parameter {parameter_name} should be round to {parameter_rule.precision}"
|
||||
f" decimal places."
|
||||
)
|
||||
|
||||
# validate parameter value range
|
||||
|
||||
@@ -51,7 +51,7 @@ if you are not sure about the structure.
|
||||
<instructions>
|
||||
{{instructions}}
|
||||
</instructions>
|
||||
"""
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
class AnthropicLargeLanguageModel(LargeLanguageModel):
|
||||
|
||||
@@ -16,6 +16,15 @@ from core.model_runtime.entities.model_entities import (
|
||||
|
||||
AZURE_OPENAI_API_VERSION = "2024-02-15-preview"
|
||||
|
||||
AZURE_DEFAULT_PARAM_SEED_HELP = I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,"
|
||||
"您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically,"
|
||||
" such that repeated requests with the same seed and parameters should return the same result."
|
||||
" Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter"
|
||||
" to monitor changes in the backend.",
|
||||
)
|
||||
|
||||
|
||||
def _get_max_tokens(default: int, min_val: int, max_val: int) -> ParameterRule:
|
||||
rule = ParameterRule(
|
||||
@@ -229,10 +238,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -297,10 +303,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -365,10 +368,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -433,10 +433,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -502,10 +499,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -571,10 +565,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -650,10 +641,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -719,10 +707,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -788,10 +773,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -867,10 +849,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -936,10 +915,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
@@ -1000,10 +976,7 @@ LLM_BASE_MODELS = [
|
||||
name="seed",
|
||||
label=I18nObject(zh_Hans="种子", en_US="Seed"),
|
||||
type="int",
|
||||
help=I18nObject(
|
||||
zh_Hans="如果指定,模型将尽最大努力进行确定性采样,使得重复的具有相同种子和参数的请求应该返回相同的结果。不能保证确定性,您应该参考 system_fingerprint 响应参数来监视变化。",
|
||||
en_US="If specified, model will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.",
|
||||
),
|
||||
help=AZURE_DEFAULT_PARAM_SEED_HELP,
|
||||
required=False,
|
||||
precision=2,
|
||||
min=0,
|
||||
|
||||
@@ -15,6 +15,7 @@ class BaichuanTokenizer:
|
||||
|
||||
@classmethod
|
||||
def _get_num_tokens(cls, text: str) -> int:
|
||||
# tokens = number of Chinese characters + number of English words * 1.3 (for estimation only, subject to actual return)
|
||||
# tokens = number of Chinese characters + number of English words * 1.3
|
||||
# (for estimation only, subject to actual return)
|
||||
# https://platform.baichuan-ai.com/docs/text-Embedding
|
||||
return int(cls.count_chinese_characters(text) + cls.count_english_vocabularies(text) * 1.3)
|
||||
|
||||
@@ -52,7 +52,7 @@ if you are not sure about the structure.
|
||||
<instructions>
|
||||
{{instructions}}
|
||||
</instructions>
|
||||
"""
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
class BedrockLargeLanguageModel(LargeLanguageModel):
|
||||
@@ -541,7 +541,9 @@ class BedrockLargeLanguageModel(LargeLanguageModel):
|
||||
"max_tokens": 32,
|
||||
}
|
||||
elif "ai21" in model:
|
||||
# ValidationException: Malformed input request: #/temperature: expected type: Number, found: Null#/maxTokens: expected type: Integer, found: Null#/topP: expected type: Number, found: Null, please reformat your input and try again.
|
||||
# ValidationException: Malformed input request: #/temperature: expected type: Number,
|
||||
# found: Null#/maxTokens: expected type: Integer, found: Null#/topP: expected type: Number, found: Null,
|
||||
# please reformat your input and try again.
|
||||
required_params = {
|
||||
"temperature": 0.7,
|
||||
"topP": 0.9,
|
||||
|
||||
@@ -45,7 +45,7 @@ if you are not sure about the structure.
|
||||
<instructions>
|
||||
{{instructions}}
|
||||
</instructions>
|
||||
"""
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
class GoogleLargeLanguageModel(LargeLanguageModel):
|
||||
|
||||
@@ -54,7 +54,8 @@ class TeiHelper:
|
||||
|
||||
url = str(URL(server_url) / "info")
|
||||
|
||||
# this method is surrounded by a lock, and default requests may hang forever, so we just set a Adapter with max_retries=3
|
||||
# this method is surrounded by a lock, and default requests may hang forever,
|
||||
# so we just set a Adapter with max_retries=3
|
||||
session = Session()
|
||||
session.mount("http://", HTTPAdapter(max_retries=3))
|
||||
session.mount("https://", HTTPAdapter(max_retries=3))
|
||||
|
||||
@@ -131,7 +131,8 @@ class HunyuanLargeLanguageModel(LargeLanguageModel):
|
||||
{
|
||||
"Role": message.role.value,
|
||||
# fix set content = "" while tool_call request
|
||||
# fix [hunyuan] None, [TencentCloudSDKException] code:InvalidParameter message:Messages Content and Contents not allowed empty at the same time.
|
||||
# fix [hunyuan] None, [TencentCloudSDKException] code:InvalidParameter
|
||||
# message:Messages Content and Contents not allowed empty at the same time.
|
||||
"Content": " ", # message.content if (message.content is not None) else "",
|
||||
"ToolCalls": dict_tool_calls,
|
||||
}
|
||||
|
||||
@@ -93,7 +93,8 @@ class NVIDIALargeLanguageModel(OAIAPICompatLargeLanguageModel):
|
||||
|
||||
def _validate_credentials(self, model: str, credentials: dict) -> None:
|
||||
"""
|
||||
Validate model credentials using requests to ensure compatibility with all providers following OpenAI's API standard.
|
||||
Validate model credentials using requests to ensure compatibility with all providers following
|
||||
OpenAI's API standard.
|
||||
|
||||
:param model: model name
|
||||
:param credentials: model credentials
|
||||
|
||||
@@ -239,7 +239,8 @@ class OCILargeLanguageModel(LargeLanguageModel):
|
||||
config_items = oci_config_content.split("/")
|
||||
if len(config_items) != 5:
|
||||
raise CredentialsValidateFailedError(
|
||||
"oci_config_content should be base64.b64encode('user_ocid/fingerprint/tenancy_ocid/region/compartment_ocid'.encode('utf-8'))"
|
||||
"oci_config_content should be base64.b64encode("
|
||||
"'user_ocid/fingerprint/tenancy_ocid/region/compartment_ocid'.encode('utf-8'))"
|
||||
)
|
||||
oci_config["user"] = config_items[0]
|
||||
oci_config["fingerprint"] = config_items[1]
|
||||
|
||||
@@ -146,7 +146,8 @@ class OCITextEmbeddingModel(TextEmbeddingModel):
|
||||
config_items = oci_config_content.split("/")
|
||||
if len(config_items) != 5:
|
||||
raise CredentialsValidateFailedError(
|
||||
"oci_config_content should be base64.b64encode('user_ocid/fingerprint/tenancy_ocid/region/compartment_ocid'.encode('utf-8'))"
|
||||
"oci_config_content should be base64.b64encode("
|
||||
"'user_ocid/fingerprint/tenancy_ocid/region/compartment_ocid'.encode('utf-8'))"
|
||||
)
|
||||
oci_config["user"] = config_items[0]
|
||||
oci_config["fingerprint"] = config_items[1]
|
||||
|
||||
@@ -639,9 +639,10 @@ class OllamaLargeLanguageModel(LargeLanguageModel):
|
||||
type=ParameterType.STRING,
|
||||
help=I18nObject(
|
||||
en_US="Sets how long the model is kept in memory after generating a response. "
|
||||
"This must be a duration string with a unit (e.g., '10m' for 10 minutes or '24h' for 24 hours). "
|
||||
"A negative number keeps the model loaded indefinitely, and '0' unloads the model immediately after generating a response. "
|
||||
"Valid time units are 's','m','h'. (Default: 5m)"
|
||||
"This must be a duration string with a unit (e.g., '10m' for 10 minutes or '24h' for 24 hours)."
|
||||
" A negative number keeps the model loaded indefinitely, and '0' unloads the model"
|
||||
" immediately after generating a response."
|
||||
" Valid time units are 's','m','h'. (Default: 5m)"
|
||||
),
|
||||
),
|
||||
ParameterRule(
|
||||
|
||||
@@ -37,7 +37,7 @@ if you are not sure about the structure.
|
||||
<instructions>
|
||||
{{instructions}}
|
||||
</instructions>
|
||||
"""
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
class OpenAILargeLanguageModel(_CommonOpenAI, LargeLanguageModel):
|
||||
|
||||
@@ -103,7 +103,8 @@ class OAIAPICompatLargeLanguageModel(_CommonOaiApiCompat, LargeLanguageModel):
|
||||
|
||||
def validate_credentials(self, model: str, credentials: dict) -> None:
|
||||
"""
|
||||
Validate model credentials using requests to ensure compatibility with all providers following OpenAI's API standard.
|
||||
Validate model credentials using requests to ensure compatibility with all providers following
|
||||
OpenAI's API standard.
|
||||
|
||||
:param model: model name
|
||||
:param credentials: model credentials
|
||||
@@ -262,7 +263,8 @@ class OAIAPICompatLargeLanguageModel(_CommonOaiApiCompat, LargeLanguageModel):
|
||||
|
||||
return entity
|
||||
|
||||
# validate_credentials method has been rewritten to use the requests library for compatibility with all providers following OpenAI's API standard.
|
||||
# validate_credentials method has been rewritten to use the requests library for compatibility with all providers
|
||||
# following OpenAI's API standard.
|
||||
def _generate(
|
||||
self,
|
||||
model: str,
|
||||
|
||||
@@ -61,7 +61,10 @@ class SparkLLMClient:
|
||||
|
||||
signature_sha_base64 = base64.b64encode(signature_sha).decode(encoding="utf-8")
|
||||
|
||||
authorization_origin = f'api_key="{api_key}", algorithm="hmac-sha256", headers="host date request-line", signature="{signature_sha_base64}"'
|
||||
authorization_origin = (
|
||||
f'api_key="{api_key}", algorithm="hmac-sha256", headers="host date request-line",'
|
||||
f' signature="{signature_sha_base64}"'
|
||||
)
|
||||
|
||||
authorization = base64.b64encode(authorization_origin.encode("utf-8")).decode(encoding="utf-8")
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ if you are not sure about the structure.
|
||||
<instructions>
|
||||
{{instructions}}
|
||||
</instructions>
|
||||
"""
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
class UpstageLargeLanguageModel(_CommonUpstage, LargeLanguageModel):
|
||||
|
||||
@@ -114,7 +114,8 @@ class VertexAiLargeLanguageModel(LargeLanguageModel):
|
||||
credentials.refresh(request)
|
||||
token = credentials.token
|
||||
|
||||
# Vertex AI Anthropic Claude3 Opus model available in us-east5 region, Sonnet and Haiku available in us-central1 region
|
||||
# Vertex AI Anthropic Claude3 Opus model available in us-east5 region, Sonnet and Haiku available
|
||||
# in us-central1 region
|
||||
if "opus" in model or "claude-3-5-sonnet" in model:
|
||||
location = "us-east5"
|
||||
else:
|
||||
@@ -123,7 +124,8 @@ class VertexAiLargeLanguageModel(LargeLanguageModel):
|
||||
# use access token to authenticate
|
||||
if token:
|
||||
client = AnthropicVertex(region=location, project_id=project_id, access_token=token)
|
||||
# When access token is empty, try to use the Google Cloud VM's built-in service account or the GOOGLE_APPLICATION_CREDENTIALS environment variable
|
||||
# When access token is empty, try to use the Google Cloud VM's built-in service account
|
||||
# or the GOOGLE_APPLICATION_CREDENTIALS environment variable
|
||||
else:
|
||||
client = AnthropicVertex(
|
||||
region=location,
|
||||
|
||||
@@ -28,7 +28,7 @@ if you are not sure about the structure.
|
||||
</instructions>
|
||||
|
||||
You should also complete the text started with ``` but not tell ``` directly.
|
||||
"""
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
class ErnieBotLargeLanguageModel(LargeLanguageModel):
|
||||
|
||||
@@ -130,7 +130,8 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
||||
credentials["completion_type"] = "completion"
|
||||
else:
|
||||
raise ValueError(
|
||||
f"xinference model ability {extra_param.model_ability} is not supported, check if you have the right model type"
|
||||
f"xinference model ability {extra_param.model_ability} is not supported,"
|
||||
f" check if you have the right model type"
|
||||
)
|
||||
|
||||
if extra_param.support_function_call:
|
||||
@@ -358,7 +359,8 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
||||
help=I18nObject(
|
||||
en_US="Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they "
|
||||
"appear in the text so far, increasing the model's likelihood to talk about new topics.",
|
||||
zh_Hans="介于 -2.0 和 2.0 之间的数字。正值会根据新词是否已出现在文本中对其进行惩罚,从而增加模型谈论新话题的可能性。",
|
||||
zh_Hans="介于 -2.0 和 2.0 之间的数字。正值会根据新词是否已出现在文本中对其进行惩罚,"
|
||||
"从而增加模型谈论新话题的可能性。",
|
||||
),
|
||||
default=0.0,
|
||||
min=-2.0,
|
||||
@@ -378,7 +380,8 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
||||
en_US="Number between -2.0 and 2.0. Positive values penalize new tokens based on their "
|
||||
"existing frequency in the text so far, decreasing the model's likelihood to repeat the "
|
||||
"same line verbatim.",
|
||||
zh_Hans="介于 -2.0 和 2.0 之间的数字。正值会根据新词在文本中的现有频率对其进行惩罚,从而降低模型逐字重复相同内容的可能性。",
|
||||
zh_Hans="介于 -2.0 和 2.0 之间的数字。正值会根据新词在文本中的现有频率对其进行惩罚,"
|
||||
"从而降低模型逐字重复相同内容的可能性。",
|
||||
),
|
||||
default=0.0,
|
||||
min=-2.0,
|
||||
|
||||
@@ -101,12 +101,16 @@ class XinferenceSpeech2TextModel(Speech2TextModel):
|
||||
|
||||
:param model: model name
|
||||
:param credentials: model credentials
|
||||
:param file: The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, mpe g,mpga, m4a, ogg, wav, or webm.
|
||||
:param file: The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, mpeg,
|
||||
mpga, m4a, ogg, wav, or webm.
|
||||
:param language: The language of the input audio. Supplying the input language in ISO-639-1
|
||||
:param prompt: An optional text to guide the model's style or continue a previous audio segment.
|
||||
The prompt should match the audio language.
|
||||
:param response_format: The format of the transcript output, in one of these options: json, text, srt, verbose _json, or vtt.
|
||||
:param temperature: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output mor e random,while lower values like 0.2 will make it more focused and deterministic.If set to 0, the model wi ll use log probability to automatically increase the temperature until certain thresholds are hit.
|
||||
:param response_format: The format of the transcript output, in one of these options: json, text, srt,
|
||||
verbose_json, or vtt.
|
||||
:param temperature: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more
|
||||
random,while lower values like 0.2 will make it more focused and deterministic.If set to 0, the model will use
|
||||
log probability to automatically increase the temperature until certain thresholds are hit.
|
||||
:return: text for given audio file
|
||||
"""
|
||||
server_url = credentials["server_url"]
|
||||
|
||||
@@ -76,7 +76,8 @@ class XinferenceHelper:
|
||||
|
||||
url = str(URL(server_url) / "v1" / "models" / model_uid)
|
||||
|
||||
# this method is surrounded by a lock, and default requests may hang forever, so we just set a Adapter with max_retries=3
|
||||
# this method is surrounded by a lock, and default requests may hang forever,
|
||||
# so we just set a Adapter with max_retries=3
|
||||
session = Session()
|
||||
session.mount("http://", HTTPAdapter(max_retries=3))
|
||||
session.mount("https://", HTTPAdapter(max_retries=3))
|
||||
@@ -88,7 +89,8 @@ class XinferenceHelper:
|
||||
raise RuntimeError(f"get xinference model extra parameter failed, url: {url}, error: {e}")
|
||||
if response.status_code != 200:
|
||||
raise RuntimeError(
|
||||
f"get xinference model extra parameter failed, status code: {response.status_code}, response: {response.text}"
|
||||
f"get xinference model extra parameter failed, status code: {response.status_code},"
|
||||
f" response: {response.text}"
|
||||
)
|
||||
|
||||
response_json = response.json()
|
||||
|
||||
@@ -31,7 +31,7 @@ And you should always end the block with a "```" to indicate the end of the JSON
|
||||
{{instructions}}
|
||||
</instructions>
|
||||
|
||||
```JSON"""
|
||||
```JSON""" # noqa: E501
|
||||
|
||||
|
||||
class ZhipuAILargeLanguageModel(_CommonZhipuaiAI, LargeLanguageModel):
|
||||
|
||||
@@ -75,7 +75,8 @@ Headers = Mapping[str, Union[str, Omit]]
|
||||
|
||||
ResponseT = TypeVar(
|
||||
"ResponseT",
|
||||
bound="Union[str, None, BaseModel, list[Any], Dict[str, Any], Response, UnknownResponse, ModelBuilderProtocol, BinaryResponseContent]",
|
||||
bound="Union[str, None, BaseModel, list[Any], Dict[str, Any], Response, UnknownResponse, ModelBuilderProtocol,"
|
||||
" BinaryResponseContent]",
|
||||
)
|
||||
|
||||
# for user input files
|
||||
|
||||
@@ -67,7 +67,8 @@ class CommonValidator:
|
||||
if credential_form_schema.max_length:
|
||||
if len(value) > credential_form_schema.max_length:
|
||||
raise ValueError(
|
||||
f"Variable {credential_form_schema.variable} length should not greater than {credential_form_schema.max_length}"
|
||||
f"Variable {credential_form_schema.variable} length should not"
|
||||
f" greater than {credential_form_schema.max_length}"
|
||||
)
|
||||
|
||||
# check the type of value
|
||||
|
||||
Reference in New Issue
Block a user