import requests
import json

API_KEY = 'app-cHh2KfV8K7KrFOV197N9XJEj'
API_URL = 'http://localhost/v1/workflows/run'  # 云端请替换为实际地址

headers = {
    'Authorization': f'Bearer {API_KEY}',
    'Content-Type': 'application/json'
}

# 这里填写你的 workflow 输入变量，变量名和类型要和 workflow 定义一致
inputs = {
    "url": "https://blog.langchain.com/planning-for-agents/"
}

payload = {
    "inputs": inputs,
    "response_mode": "blocking",  # 或 "streaming"
    "user": "abc-123"             # 可选，用户ID
}

response = requests.post(API_URL, headers=headers, json=payload)

if response.status_code == 200:
    print("运行成功，原始返回内容如下：")
    try:
        data = response.json()
        print(json.dumps(data, ensure_ascii=False, indent=2))
    except Exception as e:
        print("返回内容不是合法的JSON，原始内容如下：")
        print(response.text)
else:
    print("运行失败，状态码：", response.status_code)
    print(response.text)