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)
相关推荐
金銀銅鐵9 小时前
[Python] 基于欧几里得算法,实现分数约分计算器
python·数学
Lyn_Li11 小时前
Kaggle Top 5 | 198只股票、200条数据的金融预测——BattleFin高分方案从零复现
python·kaggle·比赛复盘·金融预测
小九九的爸爸15 小时前
前端想要入门Agent开发,要具备哪些Python基础?
python·agent·ai编程
阿耶同学16 小时前
手把手教你用 LangGraph 搭建三层嵌套 Agent 架构
python·程序员
jiayou6417 小时前
KingbaseES 表级与列级加密完全指南
数据库·后端
花酒锄作田1 天前
Pydantic校验配置文件
python
hboot1 天前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
GBASE2 天前
G术时刻 |GBase 8s数据库事务并发控制之封锁技术介绍(下)
数据库
ZhengEnCi2 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi2 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab