mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
add Qwen custom add model interface (#8565)
This commit is contained in:
parent
8219f9e090
commit
1a8dcae10e
|
@ -30,7 +30,15 @@ from core.model_runtime.entities.message_entities import (
|
|||
ToolPromptMessage,
|
||||
UserPromptMessage,
|
||||
)
|
||||
from core.model_runtime.entities.model_entities import ModelFeature
|
||||
from core.model_runtime.entities.model_entities import (
|
||||
AIModelEntity,
|
||||
FetchFrom,
|
||||
I18nObject,
|
||||
ModelFeature,
|
||||
ModelType,
|
||||
ParameterRule,
|
||||
ParameterType,
|
||||
)
|
||||
from core.model_runtime.errors.invoke import (
|
||||
InvokeAuthorizationError,
|
||||
InvokeBadRequestError,
|
||||
|
@ -520,3 +528,64 @@ class TongyiLargeLanguageModel(LargeLanguageModel):
|
|||
UnsupportedHTTPMethod,
|
||||
],
|
||||
}
|
||||
|
||||
def get_customizable_model_schema(self, model: str, credentials: dict) -> AIModelEntity | None:
|
||||
"""
|
||||
Architecture for defining customizable models
|
||||
|
||||
:param model: model name
|
||||
:param credentials: model credentials
|
||||
:return: AIModelEntity or None
|
||||
"""
|
||||
rules = [
|
||||
ParameterRule(
|
||||
name="temperature",
|
||||
type=ParameterType.FLOAT,
|
||||
use_template="temperature",
|
||||
label=I18nObject(zh_Hans="温度", en_US="Temperature"),
|
||||
),
|
||||
ParameterRule(
|
||||
name="top_p",
|
||||
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(
|
||||
name="max_tokens",
|
||||
type=ParameterType.INT,
|
||||
min=1,
|
||||
max=128000,
|
||||
default=1024,
|
||||
label=I18nObject(zh_Hans="最大生成长度", en_US="Max Tokens"),
|
||||
),
|
||||
ParameterRule(
|
||||
name="seed",
|
||||
type=ParameterType.INT,
|
||||
default=1234,
|
||||
label=I18nObject(zh_Hans="随机种子", en_US="Random Seed"),
|
||||
),
|
||||
ParameterRule(
|
||||
name="repetition_penalty",
|
||||
type=ParameterType.FLOAT,
|
||||
default=1.1,
|
||||
label=I18nObject(zh_Hans="重复惩罚", en_US="Repetition Penalty"),
|
||||
),
|
||||
]
|
||||
|
||||
entity = AIModelEntity(
|
||||
model=model,
|
||||
label=I18nObject(en_US=model),
|
||||
fetch_from=FetchFrom.CUSTOMIZABLE_MODEL,
|
||||
model_type=ModelType.LLM,
|
||||
model_properties={},
|
||||
parameter_rules=rules,
|
||||
)
|
||||
|
||||
return entity
|
||||
|
|
|
@ -20,6 +20,7 @@ supported_model_types:
|
|||
- text-embedding
|
||||
configurate_methods:
|
||||
- predefined-model
|
||||
- customizable-model
|
||||
provider_credential_schema:
|
||||
credential_form_schemas:
|
||||
- variable: dashscope_api_key
|
||||
|
@ -30,3 +31,20 @@ provider_credential_schema:
|
|||
placeholder:
|
||||
zh_Hans: 在此输入您的 API Key
|
||||
en_US: Enter your API Key
|
||||
model_credential_schema:
|
||||
model:
|
||||
label:
|
||||
en_US: Model Name
|
||||
zh_Hans: 模型名称
|
||||
placeholder:
|
||||
en_US: Enter full model name
|
||||
zh_Hans: 输入模型全称
|
||||
credential_form_schemas:
|
||||
- variable: dashscope_api_key
|
||||
required: true
|
||||
label:
|
||||
en_US: API Key
|
||||
type: secret-input
|
||||
placeholder:
|
||||
zh_Hans: 在此输入您的 API Key
|
||||
en_US: Enter your API Key
|
||||
|
|
Loading…
Reference in New Issue
Block a user