feature:全球政治经济新闻
This commit is contained in:
73
utils/ai/dify_news_analyze.py
Normal file
73
utils/ai/dify_news_analyze.py
Normal file
@@ -0,0 +1,73 @@
|
||||
#
|
||||
# curl -X POST 'http://192.168.2.240/v1/chat-messages' \
|
||||
# --header 'Authorization: Bearer {api_key}' \
|
||||
# --header 'Content-Type: application/json' \
|
||||
# --data-raw '{
|
||||
# "inputs": {},
|
||||
# "query": "What are the specs of the iPhone 13 Pro Max?",
|
||||
# "response_mode": "streaming",
|
||||
# "conversation_id": "",
|
||||
# "user": "abc-123",
|
||||
# "files": [
|
||||
# {
|
||||
# "type": "image",
|
||||
# "transfer_method": "remote_url",
|
||||
# "url": "https://cloud.dify.ai/logo/logo-site.png"
|
||||
# }
|
||||
# ]
|
||||
# }'
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def dify_news_title_analyze(content):
|
||||
# 设置Authorization和URL
|
||||
authorization = "Bearer app-rhhKkbvHd2IAQoGX7xTzXZJj" # 请替换为真实的Authorization token
|
||||
url = 'http://192.168.2.240/v1/chat-messages'
|
||||
|
||||
data = {
|
||||
"response_mode": "blocking",
|
||||
"conversation_id": "",
|
||||
"inputs": {},
|
||||
"query": content,
|
||||
"user": "a-bot"
|
||||
}
|
||||
|
||||
# 设置请求头
|
||||
headers = {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
"Authorization": authorization
|
||||
}
|
||||
|
||||
# 发送POST请求
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data), )
|
||||
response.encoding = 'utf-8'
|
||||
|
||||
# 输出响应内容
|
||||
print(response.status_code)
|
||||
print(response.json())
|
||||
return extract_content(response.json())
|
||||
|
||||
|
||||
def extract_content(data):
|
||||
"""解析API响应内容
|
||||
Args:
|
||||
data: API返回的响应数据,可以是字典或字符串
|
||||
Returns:
|
||||
str: 提取的answer内容
|
||||
"""
|
||||
try:
|
||||
# 如果是字符串,尝试解析为字典
|
||||
if isinstance(data, str):
|
||||
data = json.dumps(data)
|
||||
# 如果是字典,直接获取answer
|
||||
if isinstance(data, dict):
|
||||
answer = data.get('answer', '')
|
||||
if answer:
|
||||
return answer
|
||||
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"解析响应失败: {str(e)}")
|
||||
return None
|
||||
@@ -43,7 +43,8 @@ class Feature(Enum):
|
||||
GROUP_ADD = 16, "加群提醒功能"
|
||||
DOUYIN_PARSER = 17, "抖音链接转视频功能"
|
||||
GROUP_MEMBER_CHANGE = 18, "群成员变更提醒功能"
|
||||
KID_PHOTO_EXTRACT =19, "儿童照片提取转发功能" # 小朋友照片提取功能
|
||||
KID_PHOTO_EXTRACT = 19, "儿童照片提取转发功能" # 小朋友照片提取功能
|
||||
NEWS = 20, "全球政治经济新闻"
|
||||
|
||||
def __new__(cls, value, description):
|
||||
obj = object.__new__(cls)
|
||||
@@ -240,11 +241,11 @@ class GroupBotManager:
|
||||
str: 格式化的已启用功能列表字符串
|
||||
"""
|
||||
enabled_features = []
|
||||
|
||||
|
||||
# 检查群是否在列表中
|
||||
if group_id not in GroupBotManager.local_cache["group_list"]:
|
||||
return "该群未启用机器人功能"
|
||||
|
||||
|
||||
# 遍历所有功能,检查哪些已启用且包含指令
|
||||
for feature in Feature:
|
||||
status = GroupBotManager.get_group_permission(group_id, feature)
|
||||
@@ -255,18 +256,18 @@ class GroupBotManager:
|
||||
"name": feature.name,
|
||||
"description": feature.description
|
||||
})
|
||||
|
||||
|
||||
# 如果没有启用任何带指令的功能
|
||||
if not enabled_features:
|
||||
return "该群未启用任何带指令的功能"
|
||||
|
||||
|
||||
# 构建格式化的字符串
|
||||
result = f"群功能菜单:\n"
|
||||
for feature in enabled_features:
|
||||
result += f"{feature['id']}.{feature['description']}\n"
|
||||
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_group_list():
|
||||
"""返回所有启用了群机器人的群组清单,格式为集合"""
|
||||
|
||||
Reference in New Issue
Block a user