diff --git a/AI/Config.py b/AI/Config.py index cf7f8124..bab28634 100644 --- a/AI/Config.py +++ b/AI/Config.py @@ -26,5 +26,5 @@ NEO4J_URI = "neo4j://10.10.21.20:7687" NEO4J_AUTH = ("neo4j", "DsideaL4r5t6y7u") # Dify -DIFY_API_KEY = "app-E0r9SOtMQ14P9OHrPCbIHvJ5" -DIFY_URL='http://10.10.14.207/v1' \ No newline at end of file +DIFY_API_KEY = "app-KiNbcuA361kgIzYoYZd43hNT" +DIFY_URL='http://10.10.14.208/v1' \ No newline at end of file diff --git a/AI/Dify/1_chat-messages.py b/AI/Dify/1_chat-messages.py index af652f59..d0cf8ffe 100644 --- a/AI/Dify/1_chat-messages.py +++ b/AI/Dify/1_chat-messages.py @@ -23,6 +23,7 @@ try: with requests.post(url, headers=headers, data=payload, stream=True) as response: response.raise_for_status() # 检查请求是否成功 + showed_task_id = False # 逐行处理流式响应 for line in response.iter_lines(): if line: # 过滤掉空行 @@ -34,6 +35,10 @@ try: try: # 解析 JSON 数据 json_data = json.loads(json_str) + # 首次显示task_id + if not showed_task_id: + print('task_id=' + json_data['task_id'] + '\n') + showed_task_id = True # 提取并输出流式内容 if "answer" in json_data: print(json_data["answer"], end="", flush=True) # 实时输出 diff --git a/AI/Dify/3_stop_chat.py b/AI/Dify/3_stop_chat.py new file mode 100644 index 00000000..89abeb42 --- /dev/null +++ b/AI/Dify/3_stop_chat.py @@ -0,0 +1,24 @@ +import requests +import json +from Config import * + +# 要停止的task_id 参数 +task_id = 'b67f5aae-140d-4198-94bb-5555bc1ac186' + +# Dify API 配置 +url = DIFY_URL + "/chat-messages" +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY, + 'Content-Type': 'application/json' +} + +url = url + '/' + task_id + "/stop" + +# 请求数据 +payload = json.dumps({ + "user": "abc-123" +}) + +response = requests.request("POST", url, headers=headers, data=payload) +json_data = json.loads(response.text) +print(json_data) diff --git a/AI/__pycache__/Config.cpython-310.pyc b/AI/__pycache__/Config.cpython-310.pyc index 561a5f8a..0815868b 100644 Binary files a/AI/__pycache__/Config.cpython-310.pyc and b/AI/__pycache__/Config.cpython-310.pyc differ