Skip to content

Commit

Permalink
Modify model parameters in Spark LLMs and zhipuai LLMs (langgenius#8078)
Browse files Browse the repository at this point in the history
Co-authored-by: Charlie.Wei <[email protected]>
  • Loading branch information
2 people authored and JunXu01 committed Nov 9, 2024
1 parent 7941264 commit a04fc52
Show file tree
Hide file tree
Showing 22 changed files with 374 additions and 80 deletions.
25 changes: 14 additions & 11 deletions api/core/model_runtime/model_providers/spark/llm/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@ def __init__(self, model: str, app_id: str, api_key: str, api_secret: str, api_d
endpoint = 'chat'
if api_domain:
domain = api_domain
if model == 'spark-v3':
endpoint = 'multimodal'

model_api_configs = {
'spark-1.5': {
'spark-lite': {
'version': 'v1.1',
'chat_domain': 'general'
},
'spark-2': {
'version': 'v2.1',
'chat_domain': 'generalv2'
},
'spark-3': {
'spark-pro': {
'version': 'v3.1',
'chat_domain': 'generalv3'
},
'spark-3.5': {
'spark-pro-128k': {
'version': 'pro-128k',
'chat_domain': 'pro-128k'
},
'spark-max': {
'version': 'v3.5',
'chat_domain': 'generalv3.5'
},
'spark-4': {
'spark-4.0-ultra': {
'version': 'v4.0',
'chat_domain': '4.0Ultra'
}
Expand All @@ -48,7 +46,12 @@ def __init__(self, model: str, app_id: str, api_key: str, api_secret: str, api_d
api_version = model_api_configs[model]['version']

self.chat_domain = model_api_configs[model]['chat_domain']
self.api_base = f"wss://{domain}/{api_version}/{endpoint}"

if model == 'spark-pro-128k':
self.api_base = f"wss://{domain}/{endpoint}/{api_version}"
else:
self.api_base = f"wss://{domain}/{api_version}/{endpoint}"

self.app_id = app_id
self.ws_url = self.create_url(
urlparse(self.api_base).netloc,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
- spark-4.0-ultra
- spark-max
- spark-pro-128k
- spark-pro
- spark-lite
- spark-4
- spark-3.5
- spark-3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
model: spark-1.5
deprecated: true
label:
en_US: Spark V1.5
model_type: llm
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
model: spark-3.5
deprecated: true
label:
en_US: Spark V3.5
model_type: llm
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
model: spark-3
deprecated: true
label:
en_US: Spark V3.0
model_type: llm
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
model: spark-4.0-ultra
label:
en_US: Spark 4.0 Ultra
model_type: llm
model_properties:
mode: chat
parameter_rules:
- name: temperature
use_template: temperature
default: 0.5
help:
zh_Hans: 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高。
en_US: Kernel sampling threshold. Used to determine the randomness of the results. The higher the value, the stronger the randomness, that is, the higher the possibility of getting different answers to the same question.
- name: max_tokens
use_template: max_tokens
default: 4096
min: 1
max: 8192
help:
zh_Hans: 模型回答的tokens的最大长度。
en_US: Maximum length of tokens for the model response.
- name: top_k
label:
zh_Hans: 取样数量
en_US: Top k
type: int
default: 4
min: 1
max: 6
help:
zh_Hans: 从 k 个候选中随机选择一个(非等概率)。
en_US: Randomly select one from k candidates (non-equal probability).
required: false
- name: show_ref_label
label:
zh_Hans: 联网检索
en_US: web search
type: boolean
default: false
help:
zh_Hans: 该参数仅4.0 Ultra版本支持,当设置为true时,如果输入内容触发联网检索插件,会先返回检索信源列表,然后再返回星火回复结果,否则仅返回星火回复结果
en_US: The parameter is only supported in the 4.0 Ultra version. When set to true, if the input triggers the online search plugin, it will first return a list of search sources and then return the Spark response. Otherwise, it will only return the Spark response.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
model: spark-4
deprecated: true
label:
en_US: Spark V4.0
model_type: llm
Expand Down
33 changes: 33 additions & 0 deletions api/core/model_runtime/model_providers/spark/llm/spark-lite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
model: spark-lite
label:
en_US: Spark Lite
model_type: llm
model_properties:
mode: chat
parameter_rules:
- name: temperature
use_template: temperature
default: 0.5
help:
zh_Hans: 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高。
en_US: Kernel sampling threshold. Used to determine the randomness of the results. The higher the value, the stronger the randomness, that is, the higher the possibility of getting different answers to the same question.
- name: max_tokens
use_template: max_tokens
default: 4096
min: 1
max: 4096
help:
zh_Hans: 模型回答的tokens的最大长度。
en_US: Maximum length of tokens for the model response.
- name: top_k
label:
zh_Hans: 取样数量
en_US: Top k
type: int
default: 4
min: 1
max: 6
help:
zh_Hans: 从 k 个候选中随机选择一个(非等概率)。
en_US: Randomly select one from k candidates (non-equal probability).
required: false
33 changes: 33 additions & 0 deletions api/core/model_runtime/model_providers/spark/llm/spark-max.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
model: spark-max
label:
en_US: Spark Max
model_type: llm
model_properties:
mode: chat
parameter_rules:
- name: temperature
use_template: temperature
default: 0.5
help:
zh_Hans: 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高。
en_US: Kernel sampling threshold. Used to determine the randomness of the results. The higher the value, the stronger the randomness, that is, the higher the possibility of getting different answers to the same question.
- name: max_tokens
use_template: max_tokens
default: 4096
min: 1
max: 8192
help:
zh_Hans: 模型回答的tokens的最大长度。
en_US: Maximum length of tokens for the model response.
- name: top_k
label:
zh_Hans: 取样数量
en_US: Top k
type: int
default: 4
min: 1
max: 6
help:
zh_Hans: 从 k 个候选中随机选择一个(非等概率)。
en_US: Randomly select one from k candidates (non-equal probability).
required: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
model: spark-pro-128k
label:
en_US: Spark Pro-128K
model_type: llm
model_properties:
mode: chat
parameter_rules:
- name: temperature
use_template: temperature
default: 0.5
help:
zh_Hans: 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高。
en_US: Kernel sampling threshold. Used to determine the randomness of the results. The higher the value, the stronger the randomness, that is, the higher the possibility of getting different answers to the same question.
- name: max_tokens
use_template: max_tokens
default: 4096
min: 1
max: 4096
help:
zh_Hans: 模型回答的tokens的最大长度。
en_US: Maximum length of tokens for the model response.
- name: top_k
label:
zh_Hans: 取样数量
en_US: Top k
type: int
default: 4
min: 1
max: 6
help:
zh_Hans: 从 k 个候选中随机选择一个(非等概率)。
en_US: Randomly select one from k candidates (non-equal probability).
required: false
33 changes: 33 additions & 0 deletions api/core/model_runtime/model_providers/spark/llm/spark-pro.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
model: spark-pro
label:
en_US: Spark Pro
model_type: llm
model_properties:
mode: chat
parameter_rules:
- name: temperature
use_template: temperature
default: 0.5
help:
zh_Hans: 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高。
en_US: Kernel sampling threshold. Used to determine the randomness of the results. The higher the value, the stronger the randomness, that is, the higher the possibility of getting different answers to the same question.
- name: max_tokens
use_template: max_tokens
default: 4096
min: 1
max: 8192
help:
zh_Hans: 模型回答的tokens的最大长度。
en_US: Maximum length of tokens for the model response.
- name: top_k
label:
zh_Hans: 取样数量
en_US: Top k
type: int
default: 4
min: 1
max: 6
help:
zh_Hans: 从 k 个候选中随机选择一个(非等概率)。
en_US: Randomly select one from k candidates (non-equal probability).
required: false
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ parameter_rules:
help:
zh_Hans: 用温度取样的另一种方法,称为核取样取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1,默认值为 0.7 模型考虑具有 top_p 概率质量tokens的结果例如:0.1 意味着模型解码器只考虑从前 10% 的概率的候选集中取 tokens 建议您根据应用场景调整 top_p 或 temperature 参数,但不要同时调整两个参数。
en_US: Another method of temperature sampling is called kernel sampling. The value range is (0.0, 1.0) open interval, which cannot be equal to 0 or 1. The default value is 0.7. The model considers the results with top_p probability mass tokens. For example 0.1 means The model decoder only considers tokens from the candidate set with the top 10% probability. It is recommended that you adjust the top_p or temperature parameters according to the application scenario, but do not adjust both parameters at the same time.
- name: incremental
- name: do_sample
label:
zh_Hans: 增量返回
en_US: Incremental
zh_Hans: 采样策略
en_US: Sampling strategy
type: boolean
help:
zh_Hans: SSE接口调用时,用于控制每次返回内容方式是增量还是全量,不提供此参数时默认为增量返回,true 为增量返回,false 为全量返回。
en_US: When the SSE interface is called, it is used to control whether the content is returned incrementally or in full. If this parameter is not provided, the default is incremental return. true means incremental return, false means full return.
required: false
zh_Hans: do_sample 为 true 时启用采样策略,do_sample 为 false 时采样策略 temperature、top_p 将不生效。默认值为 true。
en_US: When `do_sample` is set to true, the sampling strategy is enabled. When `do_sample` is set to false, the sampling strategies such as `temperature` and `top_p` will not take effect. The default value is true.
default: true
- name: stream
label:
zh_Hans: 流处理
en_US: Event Stream
type: boolean
help:
zh_Hans: 使用同步调用时,此参数应当设置为 fasle 或者省略。表示模型生成完所有内容后一次性返回所有内容。默认值为 false。如果设置为 true,模型将通过标准 Event Stream ,逐块返回模型生成内容。Event Stream 结束时会返回一条data:[DONE]消息。注意:在模型流式输出生成内容的过程中,我们会分批对模型生成内容进行检测,当检测到违法及不良信息时,API会返回错误码(1301)。开发者识别到错误码(1301),应及时采取(清屏、重启对话)等措施删除生成内容,并确保不将含有违法及不良信息的内容传递给模型继续生成,避免其造成负面影响。
en_US: When using synchronous invocation, this parameter should be set to false or omitted. It indicates that the model will return all the generated content at once after the generation is complete. The default value is false. If set to true, the model will return the generated content in chunks via the standard Event Stream. A data:[DONE] message will be sent at the end of the Event Stream.Note:During the model's streaming output process, we will batch check the generated content. If illegal or harmful information is detected, the API will return an error code (1301). Developers who identify error code (1301) should promptly take actions such as clearing the screen or restarting the conversation to delete the generated content. They should also ensure that no illegal or harmful content is passed back to the model for continued generation to avoid negative impacts.
default: false
- name: return_type
label:
zh_Hans: 回复类型
Expand Down
23 changes: 16 additions & 7 deletions api/core/model_runtime/model_providers/zhipuai/llm/glm-4-0520.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,29 @@ parameter_rules:
help:
zh_Hans: 用温度取样的另一种方法,称为核取样取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1,默认值为 0.7 模型考虑具有 top_p 概率质量tokens的结果例如:0.1 意味着模型解码器只考虑从前 10% 的概率的候选集中取 tokens 建议您根据应用场景调整 top_p 或 temperature 参数,但不要同时调整两个参数。
en_US: Another method of temperature sampling is called kernel sampling. The value range is (0.0, 1.0) open interval, which cannot be equal to 0 or 1. The default value is 0.7. The model considers the results with top_p probability mass tokens. For example 0.1 means The model decoder only considers tokens from the candidate set with the top 10% probability. It is recommended that you adjust the top_p or temperature parameters according to the application scenario, but do not adjust both parameters at the same time.
- name: incremental
- name: do_sample
label:
zh_Hans: 增量返回
en_US: Incremental
zh_Hans: 采样策略
en_US: Sampling strategy
type: boolean
help:
zh_Hans: SSE接口调用时,用于控制每次返回内容方式是增量还是全量,不提供此参数时默认为增量返回,true 为增量返回,false 为全量返回。
en_US: When the SSE interface is called, it is used to control whether the content is returned incrementally or in full. If this parameter is not provided, the default is incremental return. true means incremental return, false means full return.
required: false
zh_Hans: do_sample 为 true 时启用采样策略,do_sample 为 false 时采样策略 temperature、top_p 将不生效。默认值为 true。
en_US: When `do_sample` is set to true, the sampling strategy is enabled. When `do_sample` is set to false, the sampling strategies such as `temperature` and `top_p` will not take effect. The default value is true.
default: true
- name: stream
label:
zh_Hans: 流处理
en_US: Event Stream
type: boolean
help:
zh_Hans: 使用同步调用时,此参数应当设置为 fasle 或者省略。表示模型生成完所有内容后一次性返回所有内容。默认值为 false。如果设置为 true,模型将通过标准 Event Stream ,逐块返回模型生成内容。Event Stream 结束时会返回一条data:[DONE]消息。注意:在模型流式输出生成内容的过程中,我们会分批对模型生成内容进行检测,当检测到违法及不良信息时,API会返回错误码(1301)。开发者识别到错误码(1301),应及时采取(清屏、重启对话)等措施删除生成内容,并确保不将含有违法及不良信息的内容传递给模型继续生成,避免其造成负面影响。
en_US: When using synchronous invocation, this parameter should be set to false or omitted. It indicates that the model will return all the generated content at once after the generation is complete. The default value is false. If set to true, the model will return the generated content in chunks via the standard Event Stream. A data:[DONE] message will be sent at the end of the Event Stream.Note:During the model's streaming output process, we will batch check the generated content. If illegal or harmful information is detected, the API will return an error code (1301). Developers who identify error code (1301) should promptly take actions such as clearing the screen or restarting the conversation to delete the generated content. They should also ensure that no illegal or harmful content is passed back to the model for continued generation to avoid negative impacts.
default: false
- name: max_tokens
use_template: max_tokens
default: 1024
min: 1
max: 8192
max: 4095
pricing:
input: '0.1'
output: '0.1'
Expand Down
23 changes: 16 additions & 7 deletions api/core/model_runtime/model_providers/zhipuai/llm/glm-4-air.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,29 @@ parameter_rules:
help:
zh_Hans: 用温度取样的另一种方法,称为核取样取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1,默认值为 0.7 模型考虑具有 top_p 概率质量tokens的结果例如:0.1 意味着模型解码器只考虑从前 10% 的概率的候选集中取 tokens 建议您根据应用场景调整 top_p 或 temperature 参数,但不要同时调整两个参数。
en_US: Another method of temperature sampling is called kernel sampling. The value range is (0.0, 1.0) open interval, which cannot be equal to 0 or 1. The default value is 0.7. The model considers the results with top_p probability mass tokens. For example 0.1 means The model decoder only considers tokens from the candidate set with the top 10% probability. It is recommended that you adjust the top_p or temperature parameters according to the application scenario, but do not adjust both parameters at the same time.
- name: incremental
- name: do_sample
label:
zh_Hans: 增量返回
en_US: Incremental
zh_Hans: 采样策略
en_US: Sampling strategy
type: boolean
help:
zh_Hans: SSE接口调用时,用于控制每次返回内容方式是增量还是全量,不提供此参数时默认为增量返回,true 为增量返回,false 为全量返回。
en_US: When the SSE interface is called, it is used to control whether the content is returned incrementally or in full. If this parameter is not provided, the default is incremental return. true means incremental return, false means full return.
required: false
zh_Hans: do_sample 为 true 时启用采样策略,do_sample 为 false 时采样策略 temperature、top_p 将不生效。默认值为 true。
en_US: When `do_sample` is set to true, the sampling strategy is enabled. When `do_sample` is set to false, the sampling strategies such as `temperature` and `top_p` will not take effect. The default value is true.
default: true
- name: stream
label:
zh_Hans: 流处理
en_US: Event Stream
type: boolean
help:
zh_Hans: 使用同步调用时,此参数应当设置为 fasle 或者省略。表示模型生成完所有内容后一次性返回所有内容。默认值为 false。如果设置为 true,模型将通过标准 Event Stream ,逐块返回模型生成内容。Event Stream 结束时会返回一条data:[DONE]消息。注意:在模型流式输出生成内容的过程中,我们会分批对模型生成内容进行检测,当检测到违法及不良信息时,API会返回错误码(1301)。开发者识别到错误码(1301),应及时采取(清屏、重启对话)等措施删除生成内容,并确保不将含有违法及不良信息的内容传递给模型继续生成,避免其造成负面影响。
en_US: When using synchronous invocation, this parameter should be set to false or omitted. It indicates that the model will return all the generated content at once after the generation is complete. The default value is false. If set to true, the model will return the generated content in chunks via the standard Event Stream. A data:[DONE] message will be sent at the end of the Event Stream.Note:During the model's streaming output process, we will batch check the generated content. If illegal or harmful information is detected, the API will return an error code (1301). Developers who identify error code (1301) should promptly take actions such as clearing the screen or restarting the conversation to delete the generated content. They should also ensure that no illegal or harmful content is passed back to the model for continued generation to avoid negative impacts.
default: false
- name: max_tokens
use_template: max_tokens
default: 1024
min: 1
max: 8192
max: 4095
pricing:
input: '0.001'
output: '0.001'
Expand Down
Loading

0 comments on commit a04fc52

Please sign in to comment.