Skip to content

Commit

Permalink
Merge branch 'feat/model-runtime' into deploy/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
guchenhe committed Dec 28, 2023
2 parents 0abaa92 + 8207869 commit 77acd31
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 7 deletions.
1 change: 1 addition & 0 deletions api/core/app_runner/generate_task_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def _handle_chunk(self, text: str) -> dict:
"""
response = {
'event': 'message',
'id': self._message.id,
'task_id': self._application_generate_entity.task_id,
'message_id': self._message.id,
'answer': text,
Expand Down
8 changes: 4 additions & 4 deletions api/core/entities/provider_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ def custom_model_credentials_validate(self, model_type: ModelType, model: str, c
credentials=credentials
)

for key, value in credentials.items():
if key in provider_credential_secret_variables:
credentials[key] = encrypter.encrypt_token(self.tenant_id, value)

model_schema = (
model_provider_factory.get_provider_instance(self.provider.provider)
.get_model_instance(model_type).get_customizable_model_schema(
Expand All @@ -275,6 +271,10 @@ def custom_model_credentials_validate(self, model_type: ModelType, model: str, c
if model_schema:
credentials['schema'] = json.dumps(encoders.jsonable_encoder(model_schema))

for key, value in credentials.items():
if key in provider_credential_secret_variables:
credentials[key] = encrypter.encrypt_token(self.tenant_id, value)

return provider_model_record, credentials

def add_or_update_custom_model_credentials(self, model_type: ModelType, model: str, credentials: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion api/core/model_runtime/model_providers/google/google.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ provider: google
label:
en_US: Google
description:
en_US: Google's Gemini mode.
en_US: Google's Gemini model.
zh_Hans: 谷歌提供的 Gemini 模型.
icon_small:
en_US: icon_s_en.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ model_credential_schema:
en_US: Enter full model name
zh_Hans: 输入模型全称
credential_form_schemas:
- variable: require_key
label:
en_US: Does this model need an API key?
zh_Hans: 模型是否需要 API Key
type: radio
required: true
default: false
options:
- value: false
label:
en_US: "No"
zh_Hans: 不需要
- value: true
label:
en_US: "Yes"
zh_Hans: "需要"
- variable: api_key
label:
en_US: API Key
Expand Down Expand Up @@ -53,28 +69,89 @@ model_credential_schema:
- variable: __model_type
value: text-embedding
type: text-input
default: '2048'
default: '1'
placeholder:
zh_Hans: 在此输入您的 Embedding 模型段落上限
en_US: Enter maximum chunks allowed by model
- variable: require_temperature
label:
en_US: Doe the model support adjusting temperature?
zh_Hans: 模型是否支持温度参数
type: radio
required: true
default: false
options:
- value: false
label:
en_US: "No"
zh_Hans: 不支持
- value: true
label:
en_US: "Yes"
zh_Hans: "支持"
show_on:
- variable: __model_type
value: llm
- variable: temperature
label:
zh_Hans: 模型温度 (在 0-2 之间)
en_US: Temperature (between 0-2)
show_on:
- variable: __model_type
value: llm
- variable: require_temperature
value: true
default: '0.7'
type: text-input
- variable: require_top_p
label:
en_US: Doe the model support adjusting Top P?
zh_Hans: 模型是否支持 Top P 参数
type: radio
required: true
default: false
options:
- value: false
label:
en_US: "No"
zh_Hans: 不支持
- value: true
label:
en_US: "Yes"
zh_Hans: "支持"
show_on:
- variable: __model_type
value: llm
- variable: top_p
label:
zh_Hans: Top P (在 0-1 之间)
en_US: Top P (between 0-1)
show_on:
- variable: __model_type
value: llm
- variable: require_top_p
value: true
default: '1'
type: text-input
- variable: require_top_k
label:
en_US: Doe the model support adjusting Top K?
zh_Hans: 模型是否支持 Top K 参数
type: radio
required: true
default: false
options:
- value: false
label:
en_US: "No"
zh_Hans: 不支持
- value: true
label:
en_US: "Yes"
zh_Hans: "支持"
show_on:
- variable: __model_type
value: llm
- variable: top_k
label:
zh_Hans: 取样数量
Expand All @@ -87,33 +164,112 @@ model_credential_schema:
- variable: __model_type
value: llm
default: '1'
- variable: require_frequency_penalty
label:
en_US: Doe the model support adjusting Frequency Penalty?
zh_Hans: 模型是否支持 Frequency Penalty 参数
type: radio
required: true
default: false
options:
- value: false
label:
en_US: "No"
zh_Hans: 不支持
- value: true
label:
en_US: "Yes"
zh_Hans: "支持"
show_on:
- variable: __model_type
value: llm
- variable: frequency_penalty
label:
zh_Hans: 频率惩罚 (在 0 ± 2 之间)
en_US: Frequency Penalty (between 0 ± 2)
show_on:
- variable: __model_type
value: llm
- variable: require_frequency_penalty
value: true
default: '0'
type: text-input
- variable: require_presence_penalty
label:
en_US: Doe the model support adjusting Presence Penalty?
zh_Hans: 模型是否支持 Presence Penalty 参数
type: radio
required: true
default: false
options:
- value: false
label:
en_US: "No"
zh_Hans: 不支持
- value: true
label:
en_US: "Yes"
zh_Hans: "支持"
show_on:
- variable: __model_type
value: llm
- variable: presence_penalty
label:
zh_Hans: 存在惩罚 (在 0 ± 2 之间)
en_US: Presence Penalty (between 0 ± 2)
show_on:
- variable: __model_type
value: llm
- variable: require_presence_penalty
value: true
default: '0'
type: text-input
- variable: require_max_token
label:
en_US: Doe the model support adjusting max token?
zh_Hans: 模型是否支持设置最大 Token 数
type: radio
required: true
default: false
options:
- value: false
label:
en_US: "No"
zh_Hans: 不支持
- value: true
label:
en_US: "Yes"
zh_Hans: "支持"
show_on:
- variable: __model_type
value: llm
- variable: max_tokens_to_sample
label:
zh_Hans: 最大 token 数
en_US: Maximum tokens to sample
show_on:
- variable: __model_type
value: llm
- variable: require_max_token
value: true
default: '4096'
type: text-input
- variable: require_pricing_config
label:
zh_Hans: 是否需要设置价格估计
en_US: Do you need price estimation based on token use?
required: true
default: false
type: radio
options:
- value: false
label:
en_US: "No"
zh_Hans: "不需要"
- value: true
label:
en_US: "Yes"
zh_Hans: "需要"
- variable: input_price
label:
zh_Hans: 输入单价
Expand All @@ -123,6 +279,9 @@ model_credential_schema:
zh_Hans: 模型输入 token 单价。
en_US: Price per token input.
type: text-input
show_on:
- variable: require_pricing_config
value: true
- variable: output_price
label:
zh_Hans: 输出单价
Expand All @@ -134,6 +293,8 @@ model_credential_schema:
show_on:
- variable: __model_type
value: llm
- variable: require_pricing_config
value: true
help:
zh_Hans: 模型输出 token 单价。
en_US: Price per token output.
Expand All @@ -147,9 +308,15 @@ model_credential_schema:
help:
zh_Hans: 价格计算单位。
en_US: Price unit for calculation.
show_on:
- variable: require_pricing_config
value: true
- variable: currency
label:
zh_Hans: 币种
en_US: Currency
default: USD
type: text-input
type: text-input
show_on:
- variable: require_pricing_config
value: true

0 comments on commit 77acd31

Please sign in to comment.