Skip to content

Commit 142b4fd

Browse files
authored
feat: add zhipu glm_4v_flash (#11440)
1 parent cc8feaa commit 142b4fd

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
model: glm-4v-flash
2+
label:
3+
en_US: glm-4v-flash
4+
model_type: llm
5+
model_properties:
6+
mode: chat
7+
context_size: 2048
8+
features:
9+
- vision
10+
parameter_rules:
11+
- name: temperature
12+
use_template: temperature
13+
default: 0.95
14+
min: 0.0
15+
max: 1.0
16+
help:
17+
zh_Hans: 采样温度,控制输出的随机性,必须为正数取值范围是:(0.0,1.0],不能等于 0,默认值为 0.95 值越大,会使输出更随机,更具创造性;值越小,输出会更加稳定或确定建议您根据应用场景调整 top_p 或 temperature 参数,但不要同时调整两个参数。
18+
en_US: Sampling temperature, controls the randomness of the output, must be a positive number. The value range is (0.0,1.0], which cannot be equal to 0. The default value is 0.95. The larger the value, the more random and creative the output will be; the smaller the value, The output will be more stable or certain. 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.
19+
- name: top_p
20+
use_template: top_p
21+
default: 0.6
22+
help:
23+
zh_Hans: 用温度取样的另一种方法,称为核取样取值范围是:(0.0, 1.0) 开区间,不能等于 0 或 1,默认值为 0.7 模型考虑具有 top_p 概率质量tokens的结果例如:0.1 意味着模型解码器只考虑从前 10% 的概率的候选集中取 tokens 建议您根据应用场景调整 top_p 或 temperature 参数,但不要同时调整两个参数。
24+
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.
25+
- name: do_sample
26+
label:
27+
zh_Hans: 采样策略
28+
en_US: Sampling strategy
29+
type: boolean
30+
help:
31+
zh_Hans: do_sample 为 true 时启用采样策略,do_sample 为 false 时采样策略 temperature、top_p 将不生效。默认值为 true。
32+
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.
33+
default: true
34+
- name: max_tokens
35+
use_template: max_tokens
36+
default: 1024
37+
min: 1
38+
max: 1024
39+
- name: web_search
40+
type: boolean
41+
label:
42+
zh_Hans: 联网搜索
43+
en_US: Web Search
44+
default: false
45+
help:
46+
zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。
47+
en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.
48+
pricing:
49+
input: '0.00'
50+
output: '0.00'
51+
unit: '0.000001'
52+
currency: RMB

api/core/model_runtime/model_providers/zhipuai/llm/llm.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _generate(
144144
if copy_prompt_message.role in {PromptMessageRole.USER, PromptMessageRole.SYSTEM, PromptMessageRole.TOOL}:
145145
if isinstance(copy_prompt_message.content, list):
146146
# check if model is 'glm-4v'
147-
if model not in {"glm-4v", "glm-4v-plus"}:
147+
if not model.startswith("glm-4v"):
148148
# not support list message
149149
continue
150150
# get image and
@@ -188,7 +188,7 @@ def _generate(
188188
else:
189189
model_parameters["tools"] = [web_search_params]
190190

191-
if model in {"glm-4v", "glm-4v-plus"}:
191+
if model.startswith("glm-4v"):
192192
params = self._construct_glm_4v_parameter(model, new_prompt_messages, model_parameters)
193193
else:
194194
params = {"model": model, "messages": [], **model_parameters}
@@ -412,6 +412,8 @@ def _convert_one_message_to_text(self, message: PromptMessage) -> str:
412412
human_prompt = "\n\nHuman:"
413413
ai_prompt = "\n\nAssistant:"
414414
content = message.content
415+
if isinstance(content, list):
416+
content = "".join(c.data for c in content if c.type == PromptMessageContentType.TEXT)
415417

416418
if isinstance(message, UserPromptMessage):
417419
message_text = f"{human_prompt} {content}"

0 commit comments

Comments
 (0)