豆包API

请求代码doubao-1.5-vision-pro

import requests

# API 地址
api_url = "https://ark.cn-beijing.volces.com/api/v3/chat/completions"

# API 密钥
api_key = ""

# 请求头
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"
}

# 请求数据
data = {
    "model": "doubao-1.5-vision-pro-32k-250115",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "图片主要讲了什么?"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://ark-project.tos-cn-beijing.volces.com/doc_image/ark_demo_img_1.png"
                    }
                }
            ]
        }
    ]
}

# Clash 代理设置
proxies = {
    "http": "http://127.0.0.1:7890",
    "https": "http://127.0.0.1:7890"
}

try:
    # 发送 POST 请求
    response = requests.post(api_url, headers=headers, json=data, proxies=proxies)
    # 检查响应状态码
    response.raise_for_status()
    # 解析响应的 JSON 数据
    result = response.json()
    print(result)
except requests.exceptions.HTTPError as http_err:
    print(f"HTTP 错误发生: {http_err}")
    print("响应文本:", response.text)
except requests.exceptions.RequestException as req_err:
    print(f"请求错误发生: {req_err}")
except ValueError as json_err:
    print(f"JSON 解析错误发生: {json_err}")
    

你可能感兴趣的:(python,开发语言)