2025-08-20 10:10:28 +08:00
|
|
|
|
import json
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
from JiMeng.Kit.VolcanoConst import VOLCANO_API_KEY
|
|
|
|
|
|
|
|
|
|
# API请求URL
|
|
|
|
|
url = 'https://ark.cn-beijing.volces.com/api/v3/chat/completions'
|
|
|
|
|
|
|
|
|
|
# 请求头
|
|
|
|
|
headers = {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': f'Bearer {VOLCANO_API_KEY}'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 请求体数据
|
|
|
|
|
payload = {
|
|
|
|
|
'model': 'doubao-1-5-vision-pro-32k-250115',
|
|
|
|
|
'messages': [
|
|
|
|
|
{
|
|
|
|
|
'content': [
|
|
|
|
|
{
|
|
|
|
|
'image_url': {
|
|
|
|
|
'url': 'https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/Text2Img.jpg'
|
|
|
|
|
},
|
|
|
|
|
'type': 'image_url'
|
|
|
|
|
},
|
|
|
|
|
{
|
2025-08-20 10:14:11 +08:00
|
|
|
|
'text': '以这张图片为首帧,帮我生成一个5秒的视频提示词。提示词包括:镜号、运镜、画面内容',
|
2025-08-20 10:10:28 +08:00
|
|
|
|
'type': 'text'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
'role': 'user'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 发送POST请求
|
|
|
|
|
try:
|
2025-08-20 10:35:52 +08:00
|
|
|
|
response = requests.post(url, headers=headers, data=json.dumps(payload), timeout=60)
|
2025-08-20 10:10:28 +08:00
|
|
|
|
# 检查响应状态码
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
# 解析响应数据
|
|
|
|
|
result = response.json()
|
2025-08-20 10:35:52 +08:00
|
|
|
|
|
2025-08-20 10:14:11 +08:00
|
|
|
|
# 提取choices[0].message.content的内容
|
|
|
|
|
if 'choices' in result and len(result['choices']) > 0:
|
|
|
|
|
choice = result['choices'][0]
|
|
|
|
|
if 'message' in choice and 'content' in choice['message']:
|
|
|
|
|
content = choice['message']['content']
|
|
|
|
|
print(content)
|
|
|
|
|
else:
|
|
|
|
|
print('响应中未找到message或content字段')
|
|
|
|
|
else:
|
|
|
|
|
print('响应中未找到choices字段或choices为空')
|
2025-08-20 10:10:28 +08:00
|
|
|
|
|
|
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
|
|
print(f'请求发生错误: {e}')
|
|
|
|
|
if hasattr(e, 'response') and e.response is not None:
|
|
|
|
|
print(f'错误响应状态码: {e.response.status_code}')
|
|
|
|
|
print(f'错误响应内容: {e.response.text}')
|
|
|
|
|
|
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
|
print('响应解析失败: 返回的内容不是有效的JSON格式')
|
|
|
|
|
print(f'响应内容: {response.text}')
|