diff --git a/AI/Config.py b/AI/Config.py index bab28634..88d939b1 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-KiNbcuA361kgIzYoYZd43hNT" -DIFY_URL='http://10.10.14.208/v1' \ No newline at end of file +DIFY_API_KEY = "app-jdd8mRNx3IJqVTYhRhmRfxtl" +DIFY_URL='http://10.10.14.207/v1' \ No newline at end of file diff --git a/AI/Dify/10_audio-to-text.py b/AI/Dify/10_audio-to-text.py new file mode 100644 index 00000000..aa0c49f8 --- /dev/null +++ b/AI/Dify/10_audio-to-text.py @@ -0,0 +1,20 @@ +import json + +import requests + +from Config import * + +url = DIFY_URL + "/audio-to-text" + +payload = {'user': 'abc-123'} +files = [ + ('file', ('1.png', open(r'D:\KeCheng\片头曲\1_建工高启强_去片头_(人声).mp3', 'rb'), 'type=audio/[mp3|mp4|mpeg|mpga|m4a|wav|webm]')) +] +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY +} + +response = requests.request("POST", url, headers=headers, data=payload, files=files) + +json_data = json.loads(response.text) +print(json_data) diff --git a/AI/Dify/11_text-to-audio.py b/AI/Dify/11_text-to-audio.py new file mode 100644 index 00000000..503fa1da --- /dev/null +++ b/AI/Dify/11_text-to-audio.py @@ -0,0 +1 @@ +#TODO \ No newline at end of file diff --git a/AI/Dify/12_info.py b/AI/Dify/12_info.py new file mode 100644 index 00000000..589f1654 --- /dev/null +++ b/AI/Dify/12_info.py @@ -0,0 +1,21 @@ +import json +import requests +from Config import * + + + +# Dify API 配置 +url = DIFY_URL + "/info" +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY, + 'Content-Type': 'application/json' +} + +# 发送 POST 请求 +response = requests.get(url, headers=headers) + +# 解析并打印响应 +json_data = response.json() +print(json.dumps(json_data, indent=2, ensure_ascii=False)) + + diff --git a/AI/Dify/13_parameters.py b/AI/Dify/13_parameters.py new file mode 100644 index 00000000..7dfd1007 --- /dev/null +++ b/AI/Dify/13_parameters.py @@ -0,0 +1,21 @@ +import json +import requests +from Config import * + + + +# Dify API 配置 +url = DIFY_URL + "/parameters" +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY, + 'Content-Type': 'application/json' +} + +# 发送 POST 请求 +response = requests.get(url, headers=headers) + +# 解析并打印响应 +json_data = response.json() +print(json.dumps(json_data, indent=2, ensure_ascii=False)) + + diff --git a/AI/Dify/14_meta.py b/AI/Dify/14_meta.py new file mode 100644 index 00000000..0667c02b --- /dev/null +++ b/AI/Dify/14_meta.py @@ -0,0 +1,21 @@ +import json +import requests +from Config import * + + + +# Dify API 配置 +url = DIFY_URL + "/meta" +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY, + 'Content-Type': 'application/json' +} + +# 发送 POST 请求 +response = requests.get(url, headers=headers) + +# 解析并打印响应 +json_data = response.json() +print(json.dumps(json_data, indent=2, ensure_ascii=False)) + + diff --git a/AI/Dify/1_chat-messages.py b/AI/Dify/1_chat-messages.py index bc873218..7cc06229 100644 --- a/AI/Dify/1_chat-messages.py +++ b/AI/Dify/1_chat-messages.py @@ -38,7 +38,8 @@ try: # 首次显示task_id if not showed_task_id: print('task_id=' + json_data['task_id']) - print('message_id=' + json_data['message_id'] + '\n') + print('message_id=' + json_data['message_id'] ) + print('conversation_id=' + json_data['conversation_id'] + '\n') showed_task_id = True # 提取并输出流式内容 if "answer" in json_data: diff --git a/AI/Dify/5_suggested.py b/AI/Dify/5_suggested.py index ee9f6d93..a2cd9d9b 100644 --- a/AI/Dify/5_suggested.py +++ b/AI/Dify/5_suggested.py @@ -12,7 +12,7 @@ headers = { 'Content-Type': 'application/json' } -# 发送 POST 请求 +# 发送 get 请求 response = requests.get(url + '?user=abc-123', headers=headers) # 解析并打印响应 diff --git a/AI/Dify/6_messages.py b/AI/Dify/6_messages.py new file mode 100644 index 00000000..4c7662b2 --- /dev/null +++ b/AI/Dify/6_messages.py @@ -0,0 +1,23 @@ +import json +import requests +from Config import * + + +# 获取会话历史消息 +conversation_id = '37a742e4-013d-4466-8a5e-fe64bb3b4e1d' + +# Dify API 配置 +url = DIFY_URL + "/messages" +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY, + 'Content-Type': 'application/json' +} + +# 发送 POST 请求 +response = requests.get(url + '?user=abc-123&conversation_id='+conversation_id+"&first_id=&limit=10", headers=headers) + +# 解析并打印响应 +json_data = response.json() +print(json.dumps(json_data, indent=2, ensure_ascii=False)) + + diff --git a/AI/Dify/7_conversations.py b/AI/Dify/7_conversations.py new file mode 100644 index 00000000..7b85f29b --- /dev/null +++ b/AI/Dify/7_conversations.py @@ -0,0 +1,20 @@ +# 获取会话列表 +import json +import requests +from Config import * + +# Dify API 配置 +url = DIFY_URL + "/conversations" +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY, + 'Content-Type': 'application/json' +} + +# 发送 POST 请求 +response = requests.get(url + '?user=abc-123&limit=10', headers=headers) + +# 解析并打印响应 +json_data = response.json() +print(json.dumps(json_data, indent=2, ensure_ascii=False)) + + diff --git a/AI/Dify/8_delete_conversation_id.py b/AI/Dify/8_delete_conversation_id.py new file mode 100644 index 00000000..8670dfb9 --- /dev/null +++ b/AI/Dify/8_delete_conversation_id.py @@ -0,0 +1,26 @@ +import json +import requests +from Config import * + +# 会话ID +conversation_id = '37a742e4-013d-4466-8a5e-fe64bb3b4e1d' + +# Dify API 配置 +url = DIFY_URL + "/conversations/" + conversation_id +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY, + 'Content-Type': 'application/json' +} + +# 请求体数据 +data = { + 'user': 'abc-123' # 用户标识,需与发送消息接口保持一致 +} + +# 发送 DELETE 请求 +response = requests.delete(url, headers=headers, json=data) +response.raise_for_status() # 检查请求是否成功 + +# 解析并打印响应 +json_data = response.json() +print("删除会话成功:", json.dumps(json_data, indent=2, ensure_ascii=False)) \ No newline at end of file diff --git a/AI/Dify/9_conversations_change_name.py b/AI/Dify/9_conversations_change_name.py new file mode 100644 index 00000000..144a7fa8 --- /dev/null +++ b/AI/Dify/9_conversations_change_name.py @@ -0,0 +1,26 @@ +import requests +import json +from Config import * + +# 会话ID +conversation_id = '2a2cb0ad-fc02-449a-ada7-89087c6204e8' + + +# Dify API 配置 +url = DIFY_URL + "/conversations/"+conversation_id+"/name" +headers = { + 'Authorization': 'Bearer ' + DIFY_API_KEY, + 'Content-Type': 'application/json' +} + + +# 请求数据 +payload = json.dumps({ + 'name':'黄海的测试', + 'auto_generate':False, + "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 0815868b..30750e66 100644 Binary files a/AI/__pycache__/Config.cpython-310.pyc and b/AI/__pycache__/Config.cpython-310.pyc differ