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)
相关推荐
需要点灵感10 小时前
SQL Server 存储过程语法整理
数据库·sql
刘~浪地球10 小时前
数据库与缓存--分库分表实战指南
网络·数据库·缓存
蒙奇·D·路飞-10 小时前
大模型时代下 Java 后端开发的技术重构与工程实践
java·开发语言·重构
极光代码工作室10 小时前
基于NLP的智能客服系统设计与实现
python·深度学习·机器学习·ai·自然语言处理
wljy110 小时前
Qt入门(一)
开发语言·qt
Mr_Xuhhh10 小时前
深入Java多线程进阶:从锁策略到并发工具全解析
前端·数据库·python
数厘10 小时前
2.5可视化工具与 MySQL 连接配置及基础操作
数据库·mysql
ZK_H11 小时前
半导体工艺流程
java·c语言·开发语言·计算机网络·金融
沃尔威武11 小时前
性能调优实战:从火焰图定位到SQL优化的全流程
android·数据库·sql
apcipot_rain11 小时前
Python实战——蒙特卡洛模拟分析杀牌游戏技能收益
python·游戏·数学建模