'commit'
This commit is contained in:
58
dsLightRag/JiMeng/DoubaoShiTu.py
Normal file
58
dsLightRag/JiMeng/DoubaoShiTu.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import os
|
||||
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'
|
||||
},
|
||||
{
|
||||
'text': '图片主要讲了什么?',
|
||||
'type': 'text'
|
||||
}
|
||||
],
|
||||
'role': 'user'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=json.dumps(payload), timeout=30)
|
||||
|
||||
# 检查响应状态码
|
||||
response.raise_for_status()
|
||||
|
||||
# 解析响应数据
|
||||
result = response.json()
|
||||
print('请求成功:')
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
|
||||
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}')
|
Reference in New Issue
Block a user