From 8e335093b16fe5bc875f2e9f7837f11e7696afb4 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Mon, 10 Mar 2025 13:29:57 +0800 Subject: [PATCH] 'commit' --- AI/Dify/1_chat-messages.py | 3 ++- AI/Dify/4_feedbacks.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 AI/Dify/4_feedbacks.py diff --git a/AI/Dify/1_chat-messages.py b/AI/Dify/1_chat-messages.py index d0cf8ffe..bc873218 100644 --- a/AI/Dify/1_chat-messages.py +++ b/AI/Dify/1_chat-messages.py @@ -37,7 +37,8 @@ try: json_data = json.loads(json_str) # 首次显示task_id if not showed_task_id: - print('task_id=' + json_data['task_id'] + '\n') + print('task_id=' + json_data['task_id']) + print('message_id=' + json_data['message_id'] + '\n') showed_task_id = True # 提取并输出流式内容 if "answer" in json_data: diff --git a/AI/Dify/4_feedbacks.py b/AI/Dify/4_feedbacks.py new file mode 100644 index 00000000..f680fdd6 --- /dev/null +++ b/AI/Dify/4_feedbacks.py @@ -0,0 +1,29 @@ +import json +import requests +from Config import * + +# 消息ID +message_id = '18b68391-e4ae-4bfb-b141-bf84f108da30' + +# Dify API 配置 +url = DIFY_URL + "/messages/" + message_id + "/feedbacks" +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY, + 'Content-Type': 'application/json' +} + +# 请求数据 +payload = { + "rating": "like", + "user": "abc-123", + "content": "message feedback information" +} + +# 发送 POST 请求 +response = requests.post(url, headers=headers, data=json.dumps(payload)) +response.raise_for_status() # 检查请求是否成功 + +# 解析并打印响应 +json_data = response.json() +print(json.dumps(json_data, indent=2, ensure_ascii=False)) +