mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 16:38:58 +08:00
feat: add qwen to add custom model parameters (#8759)
This commit is contained in:
parent
3d2cb25a67
commit
03edfbe6f5
@ -18,7 +18,7 @@ from dashscope.common.error import (
|
|||||||
UnsupportedModel,
|
UnsupportedModel,
|
||||||
)
|
)
|
||||||
|
|
||||||
from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta
|
from core.model_runtime.entities.llm_entities import LLMMode, LLMResult, LLMResultChunk, LLMResultChunkDelta
|
||||||
from core.model_runtime.entities.message_entities import (
|
from core.model_runtime.entities.message_entities import (
|
||||||
AssistantPromptMessage,
|
AssistantPromptMessage,
|
||||||
ImagePromptMessageContent,
|
ImagePromptMessageContent,
|
||||||
@ -35,6 +35,7 @@ from core.model_runtime.entities.model_entities import (
|
|||||||
FetchFrom,
|
FetchFrom,
|
||||||
I18nObject,
|
I18nObject,
|
||||||
ModelFeature,
|
ModelFeature,
|
||||||
|
ModelPropertyKey,
|
||||||
ModelType,
|
ModelType,
|
||||||
ParameterRule,
|
ParameterRule,
|
||||||
ParameterType,
|
ParameterType,
|
||||||
@ -97,6 +98,11 @@ class TongyiLargeLanguageModel(LargeLanguageModel):
|
|||||||
:param tools: tools for tool calling
|
:param tools: tools for tool calling
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
# Check if the model was added via get_customizable_model_schema
|
||||||
|
if self.get_customizable_model_schema(model, credentials) is not None:
|
||||||
|
# For custom models, tokens are not calculated.
|
||||||
|
return 0
|
||||||
|
|
||||||
if model in {"qwen-turbo-chat", "qwen-plus-chat"}:
|
if model in {"qwen-turbo-chat", "qwen-plus-chat"}:
|
||||||
model = model.replace("-chat", "")
|
model = model.replace("-chat", "")
|
||||||
if model == "farui-plus":
|
if model == "farui-plus":
|
||||||
@ -537,55 +543,51 @@ class TongyiLargeLanguageModel(LargeLanguageModel):
|
|||||||
:param credentials: model credentials
|
:param credentials: model credentials
|
||||||
:return: AIModelEntity or None
|
:return: AIModelEntity or None
|
||||||
"""
|
"""
|
||||||
rules = [
|
return AIModelEntity(
|
||||||
|
model=model,
|
||||||
|
label=I18nObject(en_US=model, zh_Hans=model),
|
||||||
|
model_type=ModelType.LLM,
|
||||||
|
features=[ModelFeature.TOOL_CALL, ModelFeature.MULTI_TOOL_CALL, ModelFeature.STREAM_TOOL_CALL]
|
||||||
|
if credentials.get("function_calling_type") == "tool_call"
|
||||||
|
else [],
|
||||||
|
fetch_from=FetchFrom.CUSTOMIZABLE_MODEL,
|
||||||
|
model_properties={
|
||||||
|
ModelPropertyKey.CONTEXT_SIZE: int(credentials.get("context_size", 8000)),
|
||||||
|
ModelPropertyKey.MODE: LLMMode.CHAT.value,
|
||||||
|
},
|
||||||
|
parameter_rules=[
|
||||||
ParameterRule(
|
ParameterRule(
|
||||||
name="temperature",
|
name="temperature",
|
||||||
type=ParameterType.FLOAT,
|
|
||||||
use_template="temperature",
|
use_template="temperature",
|
||||||
label=I18nObject(zh_Hans="温度", en_US="Temperature"),
|
label=I18nObject(en_US="Temperature", zh_Hans="温度"),
|
||||||
),
|
|
||||||
ParameterRule(
|
|
||||||
name="top_p",
|
|
||||||
type=ParameterType.FLOAT,
|
type=ParameterType.FLOAT,
|
||||||
use_template="top_p",
|
|
||||||
label=I18nObject(zh_Hans="Top P", en_US="Top P"),
|
|
||||||
),
|
|
||||||
ParameterRule(
|
|
||||||
name="top_k",
|
|
||||||
type=ParameterType.INT,
|
|
||||||
min=0,
|
|
||||||
max=99,
|
|
||||||
label=I18nObject(zh_Hans="top_k", en_US="top_k"),
|
|
||||||
),
|
),
|
||||||
ParameterRule(
|
ParameterRule(
|
||||||
name="max_tokens",
|
name="max_tokens",
|
||||||
type=ParameterType.INT,
|
use_template="max_tokens",
|
||||||
|
default=512,
|
||||||
min=1,
|
min=1,
|
||||||
max=128000,
|
max=int(credentials.get("max_tokens", 1024)),
|
||||||
default=1024,
|
label=I18nObject(en_US="Max Tokens", zh_Hans="最大标记"),
|
||||||
label=I18nObject(zh_Hans="最大生成长度", en_US="Max Tokens"),
|
|
||||||
),
|
|
||||||
ParameterRule(
|
|
||||||
name="seed",
|
|
||||||
type=ParameterType.INT,
|
type=ParameterType.INT,
|
||||||
default=1234,
|
|
||||||
label=I18nObject(zh_Hans="随机种子", en_US="Random Seed"),
|
|
||||||
),
|
),
|
||||||
ParameterRule(
|
ParameterRule(
|
||||||
name="repetition_penalty",
|
name="top_p",
|
||||||
|
use_template="top_p",
|
||||||
|
label=I18nObject(en_US="Top P", zh_Hans="Top P"),
|
||||||
type=ParameterType.FLOAT,
|
type=ParameterType.FLOAT,
|
||||||
default=1.1,
|
|
||||||
label=I18nObject(zh_Hans="重复惩罚", en_US="Repetition Penalty"),
|
|
||||||
),
|
),
|
||||||
]
|
ParameterRule(
|
||||||
|
name="top_k",
|
||||||
entity = AIModelEntity(
|
use_template="top_k",
|
||||||
model=model,
|
label=I18nObject(en_US="Top K", zh_Hans="Top K"),
|
||||||
label=I18nObject(en_US=model),
|
type=ParameterType.FLOAT,
|
||||||
fetch_from=FetchFrom.CUSTOMIZABLE_MODEL,
|
),
|
||||||
model_type=ModelType.LLM,
|
ParameterRule(
|
||||||
model_properties={},
|
name="frequency_penalty",
|
||||||
parameter_rules=rules,
|
use_template="frequency_penalty",
|
||||||
|
label=I18nObject(en_US="Frequency Penalty", zh_Hans="重复惩罚"),
|
||||||
|
type=ParameterType.FLOAT,
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
return entity
|
|
||||||
|
@ -37,14 +37,51 @@ model_credential_schema:
|
|||||||
en_US: Model Name
|
en_US: Model Name
|
||||||
zh_Hans: 模型名称
|
zh_Hans: 模型名称
|
||||||
placeholder:
|
placeholder:
|
||||||
en_US: Enter full model name
|
en_US: Enter your model name
|
||||||
zh_Hans: 输入模型全称
|
zh_Hans: 输入模型名称
|
||||||
credential_form_schemas:
|
credential_form_schemas:
|
||||||
- variable: dashscope_api_key
|
- variable: dashscope_api_key
|
||||||
required: true
|
|
||||||
label:
|
label:
|
||||||
en_US: API Key
|
en_US: API Key
|
||||||
type: secret-input
|
type: secret-input
|
||||||
|
required: true
|
||||||
placeholder:
|
placeholder:
|
||||||
zh_Hans: 在此输入您的 API Key
|
zh_Hans: 在此输入您的 API Key
|
||||||
en_US: Enter your API Key
|
en_US: Enter your API Key
|
||||||
|
- variable: context_size
|
||||||
|
label:
|
||||||
|
zh_Hans: 模型上下文长度
|
||||||
|
en_US: Model context size
|
||||||
|
required: true
|
||||||
|
type: text-input
|
||||||
|
default: '4096'
|
||||||
|
placeholder:
|
||||||
|
zh_Hans: 在此输入您的模型上下文长度
|
||||||
|
en_US: Enter your Model context size
|
||||||
|
- variable: max_tokens
|
||||||
|
label:
|
||||||
|
zh_Hans: 最大 token 上限
|
||||||
|
en_US: Upper bound for max tokens
|
||||||
|
default: '4096'
|
||||||
|
type: text-input
|
||||||
|
show_on:
|
||||||
|
- variable: __model_type
|
||||||
|
value: llm
|
||||||
|
- variable: function_calling_type
|
||||||
|
label:
|
||||||
|
en_US: Function calling
|
||||||
|
type: select
|
||||||
|
required: false
|
||||||
|
default: no_call
|
||||||
|
options:
|
||||||
|
- value: no_call
|
||||||
|
label:
|
||||||
|
en_US: Not Support
|
||||||
|
zh_Hans: 不支持
|
||||||
|
- value: function_call
|
||||||
|
label:
|
||||||
|
en_US: Support
|
||||||
|
zh_Hans: 支持
|
||||||
|
show_on:
|
||||||
|
- variable: __model_type
|
||||||
|
value: llm
|
||||||
|
Loading…
x
Reference in New Issue
Block a user