z-ai-sdk-python/tests/integration_tests/test_thinking.py
wellenzheng e8a26d53e4
chore: lint fix and test coverage (#19)
Co-authored-by: zhengweijun <weijun.zheng@aminer.cn>
2025-07-27 14:03:32 +08:00

57 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import logging
import logging.config
import time
import zai
from zai import ZaiClient
def test_chat_completion_with_thinking(logging_conf):
logging.config.dictConfig(logging_conf) # type: ignore
client = ZaiClient() # Fill in your own API Key
try:
# Generate request_id
request_id = time.time()
print(f'request_id:{request_id}')
response = client.chat.completions.create(
request_id=request_id,
model='glm-4.5',
messages=[{'role': 'user', 'content': '请介绍一下Agent的原理并给出详细的推理过程'}],
top_p=0.7,
temperature=0.9,
)
print(response)
except zai.core._errors.APIRequestFailedError as err:
print(err)
except zai.core._errors.APIInternalError as err:
print(err)
except zai.core._errors.APIStatusError as err:
print(err)
def test_chat_completion_without_thinking(logging_conf):
logging.config.dictConfig(logging_conf) # type: ignore
client = ZaiClient() # Fill in your own API Key
try:
# Generate request_id
request_id = time.time()
print(f'request_id:{request_id}')
response = client.chat.completions.create(
request_id=request_id,
model='glm-4.5',
messages=[{'role': 'user', 'content': '请介绍一下Agent的原理'}],
top_p=0.7,
temperature=0.9,
thinking={
'type': 'disabled',
},
)
print(response)
except zai.core._errors.APIRequestFailedError as err:
print(err)
except zai.core._errors.APIInternalError as err:
print(err)
except zai.core._errors.APIStatusError as err:
print(err)