Skip to content

Commit 3f620eb

Browse files
author
jinhaiyang
committed
4v-think
1 parent 9ae35ac commit 3f620eb

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import os.path
2+
3+
from zhipuai import ZhipuAI
4+
import zhipuai
5+
import time
6+
7+
import logging
8+
import logging.config
9+
10+
11+
def test_completions_vlm_thinking(logging_conf):
12+
logging.config.dictConfig(logging_conf) # type: ignore
13+
client = ZhipuAI() # 填写您自己的APIKey
14+
try:
15+
# 生成request_id
16+
request_id = time.time()
17+
print(f"request_id:{request_id}")
18+
response = client.chat.completions.create(
19+
request_id=request_id,
20+
model="glm-4.1v-thinking-flash", # 填写需要调用的模型名称
21+
messages=[
22+
{
23+
"role": "user",
24+
"content": [
25+
{
26+
"type": "text",
27+
"text": "图里有什么"
28+
},
29+
30+
{
31+
"type": "image_url",
32+
"image_url": {
33+
"url": "https://img1.baidu.com/it/u=1369931113,3388870256&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1703696400&t=f3028c7a1dca43a080aeb8239f09cc2f"
34+
}
35+
}
36+
]
37+
}
38+
],
39+
temperature=0.5,
40+
max_tokens = 1024,
41+
user_id="12345678"
42+
)
43+
print(response)
44+
45+
46+
except zhipuai.core._errors.APIRequestFailedError as err:
47+
print(err)
48+
except zhipuai.core._errors.APIInternalError as err:
49+
print(err)
50+
except zhipuai.core._errors.APIStatusError as err:
51+
print(err)
52+
53+
54+
55+
def test_completions_vlm_thinking_stream(logging_conf):
56+
logging.config.dictConfig(logging_conf) # type: ignore
57+
client = ZhipuAI() # 填写您自己的APIKey
58+
try:
59+
# 生成request_id
60+
request_id = time.time()
61+
print(f"request_id:{request_id}")
62+
response = client.chat.completions.create(
63+
request_id=request_id,
64+
model="glm-4.1v-thinking-flash", # 填写需要调用的模型名称
65+
messages=[
66+
{
67+
"role": "user",
68+
"content": [
69+
{
70+
"type": "text",
71+
"text": "图里有什么"
72+
},
73+
74+
{
75+
"type": "image_url",
76+
"image_url": {
77+
"url": "https://img1.baidu.com/it/u=1369931113,3388870256&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1703696400&t=f3028c7a1dca43a080aeb8239f09cc2f"
78+
}
79+
}
80+
]
81+
}
82+
],
83+
temperature=0.5,
84+
max_tokens = 1024,
85+
user_id="12345678",
86+
stream=True
87+
)
88+
for item in response:
89+
print(item)
90+
91+
except zhipuai.core._errors.APIRequestFailedError as err:
92+
print(err)
93+
except zhipuai.core._errors.APIInternalError as err:
94+
print(err)
95+
except zhipuai.core._errors.APIStatusError as err:
96+
print(err)
97+

zhipuai/types/chat/chat_completion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CompletionMessageToolCall(BaseModel):
1919
class CompletionMessage(BaseModel):
2020
content: Optional[str] = None
2121
role: str
22+
reasoning_content: Optional[str] = None
2223
tool_calls: Optional[List[CompletionMessageToolCall]] = None
2324

2425

zhipuai/types/chat/chat_completion_chunk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class AudioCompletionChunk(BaseModel):
3939
class ChoiceDelta(BaseModel):
4040
content: Optional[str] = None
4141
role: Optional[str] = None
42+
reasoning_content: Optional[str] = None
4243
tool_calls: Optional[List[ChoiceDeltaToolCall]] = None
4344
audio: Optional[AudioCompletionChunk] = None
4445

0 commit comments

Comments
 (0)