import base64
from zhipuai import ZhipuAI
client = ZhipuAI(api_key="YOUR API KEY") # 填写您自己的APIKey
response = client.chat.completions.create(
model="glm-4v-plus", # 填写需要调用的模型名称
messages=[
{
"role": "user",
"content": [
{
"type": "video_url",
"video_url": {
"url" : "https://sfile.chatglm.cn/testpath/video/12e68db5-51d4-5570-a704-792f135ce74c_0.mp4"
}
},
{
"type": "text",
"text": "Please describe this video in detail."
}
]
}
]
)
print(response.choices[0].message)
CompletionMessage(content="A vibrant purple parrot with a red beak and ringed eyes is perched on a balcony railing, gazing out over a cityscape at dusk. The scene is serene, with the bird's feathers contrasting against the softly blurred urban backdrop. As time passes, the bird's profile is highlighted against the twilight sky, suggesting a moment of quiet contemplation. The city lights begin to twinkle, adding a warm glow to the cool dusk above. The parrot's demeanor is poised, embodying a serene yet lively spirit against the urban setting.", role='assistant', tool_calls=None)
import base64
from zhipuai import ZhipuAI
client = ZhipuAI(api_key="YOUR API KEY") # 填写您自己的APIKey
response = client.chat.completions.create(
model="glm-4v-plus", # 填写需要调用的模型名称
messages=[
{
"role": "user",
"content": [
{
"type": "video_url",
"video_url": {
"url" : "https://sfile.chatglm.cn/testpath/video/12e68db5-51d4-5570-a704-792f135ce74c_0.mp4"
}
},
{
"type": "text",
"text": "Please describe this video in detail."
}
]
},
{
"content": [
{
"text": "A vibrant purple parrot with a red beak and ringed eyes is perched on a balcony railing, gazing out over a cityscape at dusk. The scene is serene, with the bird's feathers contrasting against the softly blurred urban backdrop. As time passes, the bird's profile is highlighted against the twilight sky, suggesting a moment of quiet contemplation. The city lights begin to twinkle, adding a warm glow to the cool dusk above. The parrot's demeanor is poised, embodying a serene yet lively spirit against the urban setting.",
"type": "text"
}
],
"role": "assistant"
},
{
"content": [
{
"text": "Change the purple parrot to white parrot.",
"type": "text"
}
],
"role": "user"
}
]
)
print(response.choices[0].message)
CompletionMessage(content="A white parrot with a striking red beak and ringed eyes is perched on a balcony railing, gazing out over a cityscape at dusk. The scene is serene, with the bird's feathers contrasting against the softly blurred urban backdrop. As time passes, the bird's profile is highlighted against the twilight sky, suggesting a moment of quiet contemplation. The city lights begin to twinkle, adding a warm glow to the cool dusk above. The parrot's demeanor is poised, embodying a serene yet lively spirit against the urban setting.", role='assistant', tool_calls=None)
import time
from zhipuai import ZhipuAI
client = ZhipuAI(api_key="YOUR API KEY") # 填写您自己的APIKey
def zhipu_cogvideo(prompt_in):
T1 = time.time() #基准时间
response = client.videos.generations(
model="cogvideox",
prompt=prompt_in
)
print(response)
task_id = response.id
task_status = response.task_status
get_cnt = 0
while task_status == 'PROCESSING' and get_cnt <= 40: #超时时间
result_response = client.videos.retrieve_videos_result(
id=task_id
)
T2 =time.time() #运行时间
run_time_s = (T2 - T1)
print("生成视频中,已运行",round(run_time_s,2),"秒:",result_response)
task_status = result_response.task_status
time.sleep(15)
get_cnt += 1
T3 =time.time() #完成响应
finish_time_s = (T3 - T1)
print("视频:【",prompt_in,"】生成完毕\n耗时:",round(finish_time_s,3))
return result_response
if __name__ == '__main__':
text = "A white parrot with a striking red beak and ringed eyes is perched on a balcony railing, gazing out over a cityscape at dusk. The scene is serene, with the bird's feathers contrasting against the softly blurred urban backdrop. As time passes, the bird's profile is highlighted against the twilight sky, suggesting a moment of quiet contemplation. The city lights begin to twinkle, adding a warm glow to the cool dusk above. The parrot's demeanor is poised, embodying a serene yet lively spirit against the urban setting."
print("#####\n",zhipu_cogvideo(text).video_result[0].url)
import base64
from zhipuai import ZhipuAI
client = ZhipuAI(api_key="YOUR API KEY") # 填写您自己的APIKey
response = client.chat.completions.create(
model="glm-4v-plus", # 填写需要调用的模型名称
messages=[
{
"role": "user",
"content": [
{
"type": "video_url",
"video_url": {
"url" : "https://sfile.chatglm.cn/testpath/video/12e68db5-51d4-5570-a704-792f135ce74c_0.mp4"
}
},
{
"type": "text",
"text": "Please describe this video in detail."
}
]
},
{
"content": [
{
"text": "A vibrant purple parrot with a red beak and ringed eyes is perched on a balcony railing, gazing out over a cityscape at dusk. The scene is serene, with the bird's feathers contrasting against the softly blurred urban backdrop. As time passes, the bird's profile is highlighted against the twilight sky, suggesting a moment of quiet contemplation. The city lights begin to twinkle, adding a warm glow to the cool dusk above. The parrot's demeanor is poised, embodying a serene yet lively spirit against the urban setting.",
"type": "text"
}
],
"role": "assistant"
},
{
"content": [
{
"text": "Change the purple parrot to white parrot.",
"type": "text"
}
],
"role": "user"
},
{
"content": [
{
"text": "A white parrot with a striking red beak and ringed eyes is perched on a balcony railing, gazing out over a cityscape at dusk. The scene is serene, with the bird's feathers contrasting against the softly blurred urban backdrop. As time passes, the bird's profile is highlighted against the twilight sky, suggesting a moment of quiet contemplation. The city lights begin to twinkle, adding a warm glow to the cool dusk above. The parrot's demeanor is poised, embodying a serene yet lively spirit against the urban setting.",
"type": "text"
}
],
"role": "assistant"
},
{
"content": [
{
"text": "Change background to a rainy forest.",
"type": "text"
}
],
"role": "user"
}
]
)
print(response.choices[0].message)
CompletionMessage(content="A white parrot with a striking red beak and ringed eyes is perched on a branch in a rainy forest, gazing out over the lush greenery. The scene is serene, with the bird's feathers contrasting against the softly blurred backdrop of the rainy forest. As time passes, the bird's profile is highlighted against the misty sky, suggesting a moment of quiet contemplation. The raindrops begin to fall, adding a soothing sound to the peaceful atmosphere. The parrot's demeanor is poised, embodying a serene yet lively spirit against the natural setting.", role='assistant', tool_calls=None)
Was this page helpful?