Skip to content

Commit

Permalink
add Qwen custom add model interface (langgenius#8565)
Browse files Browse the repository at this point in the history
  • Loading branch information
AAEE86 authored and cuiks committed Sep 26, 2024
1 parent a74382a commit f41513e
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
71 changes: 70 additions & 1 deletion api/core/model_runtime/model_providers/tongyi/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@
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,
Expand Down Expand Up @@ -520,3 +528,64 @@ def _invoke_error_mapping(self) -> dict[type[InvokeError], list[type[Exception]]
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
18 changes: 18 additions & 0 deletions api/core/model_runtime/model_providers/tongyi/tongyi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit f41513e

Please sign in to comment.