说明
使用mindie1.0部署qwen2_vl_72b模型,可以用来分析图片了。现在想分析视频。看了下mindie文档,支持视频分析的。
错误
错误1:没安装pyav
http返回
Error code: 422 - {'error': 'Messages token length must be in (0, 1048576], but got 0', 'error_type': 'Input Validation Error'}
解决办法:安装pyav,重启mindie
错误2:使用base64
http返回:
Error code: 422 - {'error': '[InferTokenizer::DownloadUrl] Download fail: ValueError: Input type video_url does not match the mm type.', 'error_type': 'Input Validation Error'}
解决办法:不要使用base64传入,使用磁盘目录或者http下载目录
完整的例子
from openai import OpenAI
import os
# import base64
import time
# Base64 编码格式
# def encode_video(video_path):
# with open(video_path, "rb") as video_file:
# return base64.b64encode(video_file.read()).decode("utf-8")
# 将xxxx/test.mp4替换为你本地视频的绝对路径
# base64_video = encode_video("./数据集上传.mp4")
client = OpenAI(
api_key="sk-suibianxie",
base_url="http://10.20.xx.xx:port/v1",
)
start_time = time.time() # 记录开始时间
completion = client.chat.completions.create(
model="qwen_1_0c081946",
messages=[
{
"role": "user",
"content": [{"type":"text","text": "You are a helpful assistant."}]
},
{
"role": "user",
"content": [
{
# 直接传入视频文件时,请将type的值设置为video_url
"type": "video_url",
#"video_url": {"url": f"/in/update.mp4"},
"video_url": {"url": f"http://10.20.xx.xx:9010/%E6%95%B0%E6%8D%AE%E9%9B%86%E4%B8%8A%E4%BC%A0.mp4"},
# "fps": 1.0,
# "max_pixels": 360 * 420,
},
{"type": "text", "text": "这段视频描绘的是什么景象?"},
],
}
],
)
end_time = time.time() # 记录结束时间
print(f"请求耗时: {end_time - start_time:.2f}秒") # 打印耗时
print(completion.choices[0].message.content)
参考资料
使用python访问mindie部署的vl多模态模型