Skip to content

Commit a5bbca4

Browse files
author
jinhaiyang
committed
【web_search】web_search
1 parent fa3f4c3 commit a5bbca4

File tree

14 files changed

+1597
-1597
lines changed

14 files changed

+1597
-1597
lines changed

tests/integration_tests/test.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# import time
2-
#
3-
# from zhipuai import ZhipuAI
4-
# client = ZhipuAI() # 填写您自己的APIKey
5-
#
6-
# response = client.videos.generations(
7-
# model="cogvideo",
8-
# prompt="一个年轻的艺术家在一片彩虹上用调色板作画。"
9-
# # prompt="一只卡通狐狸在森林里跳着欢快的爵士舞。"
10-
# # prompt="这是一部汽车广告片,描述了一位30岁的汽车赛车手戴着红色头盔的赛车冒险。背景是蔚蓝的天空和苛刻的沙漠环境,电影风格使用35毫米胶片拍摄,色彩鲜艳夺目。"
11-
# )
12-
# print(response)
13-
# task_id = response.id
14-
# task_status = response.task_status
15-
# get_cnt = 0
16-
#
17-
# while task_status == 'PROCESSING' and get_cnt <= 40:
18-
# result_response = client.videos.retrieve_videos_result(
19-
# id=task_id
20-
# )
21-
# print(result_response)
22-
# task_status = result_response.task_status
23-
#
24-
# time.sleep(2)
25-
# get_cnt += 1
1+
import time
2+
3+
from zhipuai import ZhipuAI
4+
client = ZhipuAI() # 填写您自己的APIKey
5+
6+
response = client.videos.generations(
7+
model="cogvideo",
8+
prompt="一个年轻的艺术家在一片彩虹上用调色板作画。"
9+
# prompt="一只卡通狐狸在森林里跳着欢快的爵士舞。"
10+
# prompt="这是一部汽车广告片,描述了一位30岁的汽车赛车手戴着红色头盔的赛车冒险。背景是蔚蓝的天空和苛刻的沙漠环境,电影风格使用35毫米胶片拍摄,色彩鲜艳夺目。"
11+
)
12+
print(response)
13+
task_id = response.id
14+
task_status = response.task_status
15+
get_cnt = 0
16+
17+
while task_status == 'PROCESSING' and get_cnt <= 40:
18+
result_response = client.videos.retrieve_videos_result(
19+
id=task_id
20+
)
21+
print(result_response)
22+
task_status = result_response.task_status
23+
24+
time.sleep(2)
25+
get_cnt += 1
Lines changed: 111 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,111 @@
1-
# import logging
2-
# import logging.config
3-
# import zhipuai
4-
# from zhipuai import ZhipuAI
5-
# import json
6-
#
7-
# def test_assistant(logging_conf) -> None:
8-
# logging.config.dictConfig(logging_conf) # type: ignore
9-
# client = ZhipuAI() # 填写您自己的APIKey
10-
# try:
11-
#
12-
# generate = client.assistant.conversation(
13-
# assistant_id="659e54b1b8006379b4b2abd6",
14-
# messages=[
15-
# {
16-
# "role": "user",
17-
# "content": [{
18-
# "type": "text",
19-
# "text": "帮我搜索下智谱的cogvideox发布时间"
20-
# }]
21-
# }
22-
# ],
23-
# stream=True,
24-
# attachments=None,
25-
# metadata=None,
26-
# request_id="request_1790291013237211136",
27-
# user_id="12345678"
28-
# )
29-
# for assistant in generate:
30-
# print(assistant)
31-
#
32-
# except zhipuai.core._errors.APIRequestFailedError as err:
33-
# print(err)
34-
# except zhipuai.core._errors.APIInternalError as err:
35-
# print(err)
36-
# except zhipuai.core._errors.APIStatusError as err:
37-
# print(err)
38-
#
39-
# def test_assistant_query_support(logging_conf) -> None:
40-
# logging.config.dictConfig(logging_conf) # type: ignore
41-
# client = ZhipuAI() # 填写您自己的APIKey
42-
# try:
43-
#
44-
# response = client.assistant.query_support(
45-
# assistant_id_list=[],
46-
# request_id="request_1790291013237211136",
47-
# user_id="12345678"
48-
# )
49-
# print(response)
50-
#
51-
# except zhipuai.core._errors.APIRequestFailedError as err:
52-
# print(err)
53-
# except zhipuai.core._errors.APIInternalError as err:
54-
# print(err)
55-
# except zhipuai.core._errors.APIStatusError as err:
56-
# print(err)
57-
#
58-
# def test_assistant_query_conversation_usage(logging_conf) -> None:
59-
# logging.config.dictConfig(logging_conf) # type: ignore
60-
# client = ZhipuAI() # 填写您自己的APIKey
61-
# try:
62-
# response = client.assistant.query_conversation_usage(
63-
# assistant_id="659e54b1b8006379b4b2abd6",
64-
# request_id="request_1790291013237211136",
65-
# user_id="12345678"
66-
# )
67-
# print(response)
68-
# except zhipuai.core._errors.APIRequestFailedError as err:
69-
# print(err)
70-
# except zhipuai.core._errors.APIInternalError as err:
71-
# print(err)
72-
# except zhipuai.core._errors.APIStatusError as err:
73-
# print(err)
74-
#
75-
#
76-
# def test_translate_api(logging_conf) -> None:
77-
# logging.config.dictConfig(logging_conf) # type: ignore
78-
# client = ZhipuAI() # 填写您自己的APIKey
79-
# try:
80-
# translate_response = client.assistant.conversation(
81-
# assistant_id="9996ijk789lmn012o345p999",
82-
# messages=[
83-
# {
84-
# "role": "user",
85-
# "content": [{
86-
# "type": "text",
87-
# "text": "你好呀"
88-
# }]
89-
# }
90-
# ],
91-
# stream=True,
92-
# attachments=None,
93-
# metadata=None,
94-
# request_id="request_1790291013237211136",
95-
# user_id="12345678",
96-
# extra_parameters = {
97-
# "translate": {
98-
# "from": "zh",
99-
# "to": "en"
100-
# }
101-
# }
102-
# )
103-
# for chunk in translate_response:
104-
# print(chunk.choices[0].delta)
105-
# #print(translate_response)
106-
# except zhipuai.core._errors.APIRequestFailedError as err:
107-
# print(err)
108-
# except zhipuai.core._errors.APIInternalError as err:
109-
# print(err)
110-
# except zhipuai.core._errors.APIStatusError as err:
111-
# print(err)
1+
import logging
2+
import logging.config
3+
import zhipuai
4+
from zhipuai import ZhipuAI
5+
import json
6+
7+
def test_assistant(logging_conf) -> None:
8+
logging.config.dictConfig(logging_conf) # type: ignore
9+
client = ZhipuAI() # 填写您自己的APIKey
10+
try:
11+
12+
generate = client.assistant.conversation(
13+
assistant_id="659e54b1b8006379b4b2abd6",
14+
messages=[
15+
{
16+
"role": "user",
17+
"content": [{
18+
"type": "text",
19+
"text": "帮我搜索下智谱的cogvideox发布时间"
20+
}]
21+
}
22+
],
23+
stream=True,
24+
attachments=None,
25+
metadata=None,
26+
request_id="request_1790291013237211136",
27+
user_id="12345678"
28+
)
29+
for assistant in generate:
30+
print(assistant)
31+
32+
except zhipuai.core._errors.APIRequestFailedError as err:
33+
print(err)
34+
except zhipuai.core._errors.APIInternalError as err:
35+
print(err)
36+
except zhipuai.core._errors.APIStatusError as err:
37+
print(err)
38+
39+
def test_assistant_query_support(logging_conf) -> None:
40+
logging.config.dictConfig(logging_conf) # type: ignore
41+
client = ZhipuAI() # 填写您自己的APIKey
42+
try:
43+
44+
response = client.assistant.query_support(
45+
assistant_id_list=[],
46+
request_id="request_1790291013237211136",
47+
user_id="12345678"
48+
)
49+
print(response)
50+
51+
except zhipuai.core._errors.APIRequestFailedError as err:
52+
print(err)
53+
except zhipuai.core._errors.APIInternalError as err:
54+
print(err)
55+
except zhipuai.core._errors.APIStatusError as err:
56+
print(err)
57+
58+
def test_assistant_query_conversation_usage(logging_conf) -> None:
59+
logging.config.dictConfig(logging_conf) # type: ignore
60+
client = ZhipuAI() # 填写您自己的APIKey
61+
try:
62+
response = client.assistant.query_conversation_usage(
63+
assistant_id="659e54b1b8006379b4b2abd6",
64+
request_id="request_1790291013237211136",
65+
user_id="12345678"
66+
)
67+
print(response)
68+
except zhipuai.core._errors.APIRequestFailedError as err:
69+
print(err)
70+
except zhipuai.core._errors.APIInternalError as err:
71+
print(err)
72+
except zhipuai.core._errors.APIStatusError as err:
73+
print(err)
74+
75+
76+
def test_translate_api(logging_conf) -> None:
77+
logging.config.dictConfig(logging_conf) # type: ignore
78+
client = ZhipuAI() # 填写您自己的APIKey
79+
try:
80+
translate_response = client.assistant.conversation(
81+
assistant_id="9996ijk789lmn012o345p999",
82+
messages=[
83+
{
84+
"role": "user",
85+
"content": [{
86+
"type": "text",
87+
"text": "你好呀"
88+
}]
89+
}
90+
],
91+
stream=True,
92+
attachments=None,
93+
metadata=None,
94+
request_id="request_1790291013237211136",
95+
user_id="12345678",
96+
extra_parameters = {
97+
"translate": {
98+
"from": "zh",
99+
"to": "en"
100+
}
101+
}
102+
)
103+
for chunk in translate_response:
104+
print(chunk.choices[0].delta)
105+
#print(translate_response)
106+
except zhipuai.core._errors.APIRequestFailedError as err:
107+
print(err)
108+
except zhipuai.core._errors.APIInternalError as err:
109+
print(err)
110+
except zhipuai.core._errors.APIStatusError as err:
111+
print(err)

0 commit comments

Comments
 (0)