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)
相关推荐
aramae2 分钟前
模拟实现strcmp()(C语言)
c语言·开发语言·后端
Madison-No719 分钟前
搭建项目测试环境
linux·运维·服务器·python
+VX:Fegn089533 分钟前
计算机毕业设计|基于springboot + vue蛋糕店管理系统(源码+数据库+文档)
前端·数据库·vue.js·spring boot·课程设计
计算机编程-吉哥1 小时前
YOLO26 vs YOLO11 vs YOLOv8:深度学习咖啡果实成熟度分割系统【计算机毕业设计选题推荐】
人工智能·python·深度学习·yolo·django·毕业设计
泡海椒1 小时前
PDF 表格样式优化:jquick-pdf 边框、圆角、背景色
java·开发语言·pdf
大衛說1 小时前
11 · 异常处理与日志
python
auto_go2 小时前
Python 实战指南(7)——账本动不动就崩?先把“魔法字符串”和“裸报错”干掉
python
Beyond_System|系统之外2 小时前
【学编程】Python基础编程题100道(21-60)
开发语言·python·算法
根目录下的猫2 小时前
RK3588适配的轻量级AI模型推荐
人工智能·后端·python·目标检测
景熙55232 小时前
15.Java 8 Stream 流入门到实战
java·开发语言·数据结构