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)
相关推荐
2501_94188248几秒前
在开普敦跨区域部署环境中构建高可靠分布式配置中心的设计思路与实现实践
开发语言·c#
一只小小Java1 分钟前
Java面试场景高频题
java·开发语言·面试
海棠AI实验室2 分钟前
第十七章 调试与排错:读懂 Traceback 的方法论
python·pandas·调试
Ljubim.te4 分钟前
inline介绍,宏定义的注意事项以及nullptr
c语言·开发语言·c++
BORN(^-^)5 分钟前
达梦数据库索引删除操作小记
数据库·达梦
亓才孓5 分钟前
多态:编译时看左边,运行时看右边
java·开发语言
小白探索世界欧耶!~5 分钟前
用iframe实现单个系统页面在多个系统中复用
开发语言·前端·javascript·vue.js·经验分享·笔记·iframe
2501_9418787410 分钟前
在奥克兰云原生实践中构建动态配置中心以支撑系统稳定演进的工程经验总结
开发语言·python
Rabbit_QL10 分钟前
【Pytorch使用】CUDA 显存管理与 OOM 排查实战:以 PyTorch 联邦学习训练为例
人工智能·pytorch·python
weixin_4432978810 分钟前
Python打卡训练营第31天
开发语言·python