dify API访问工作流/聊天

chatflow
python 复制代码
import requests
import json

# API 配置
api_key = "app-xxx"  # 替换为你的 API Key
base_url = "http://192.168.1.100:8080/v1"
endpoint = "/chat-messages"

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

# 请求体
data = {
    "inputs": {},
    "query": "What are the specs of the iPhone 13 Pro Max?",
    "response_mode": "streaming",
    "conversation_id": "",
    "user": "ywxx"
}

# 发送请求
response = requests.post(
    url=f"{base_url}{endpoint}",
    headers=headers,
    data=json.dumps(data),
    stream=True  # 启用流式响应
)

# 处理流式响应
if response.status_code == 200:
    for line in response.iter_lines():
        if line:
            line = line.decode('utf-8')
            if line.startswith('data: '):
                try:
                    data = json.loads(line[6:])  # 移除 'data: ' 前缀
                    print(data)
                except json.JSONDecodeError:
                    continue
else:
    print(f"Error: {response.status_code}")
    print(response.text)
工作流(workflows)
python 复制代码
import requests

# API 配置
api_key = "app-zzzz"
base_url = "http://192.168.1.110:8080/v1"

# 请求头
headers = {
    "Authorization": f"Bearer {api_key}"
}

# 发送请求
response = requests.get(
    url=f"{base_url}/workflows/logs",
    headers=headers
)

# response = requests.get(
#     url=f"{base_url}/info",
#     headers=headers
# )

# 检查响应
if response.status_code == 200:
    logs_data = response.json()
    print("工作流日志获取成功:")
    print(logs_data)
else:
    print(f"请求失败:{response.status_code}")
    print(response.text)
相关推荐
用户8356290780511 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng81 天前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi2 天前
Chapter 2 - Python中的变量和简单的数据类型
python
JordanHaidee2 天前
Python 中 `if x:` 到底在判断什么?
后端·python
ServBay2 天前
10分钟彻底终结冗长代码,Python f-string 让你重获编程自由
后端·python
闲云一鹤2 天前
Python 入门(二)- 使用 FastAPI 快速生成后端 API 接口
python·fastapi
Rockbean2 天前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
爱可生开源社区2 天前
2026 年,优秀的 DBA 需要具备哪些素质?
数据库·人工智能·dba
曲幽2 天前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
用户60648767188962 天前
国内开发者如何接入 Claude API?中转站方案实战指南(Python/Node.js 完整示例)
人工智能·python·api