95 lines
2.9 KiB
Python
95 lines
2.9 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
初始化 AI 代理 - 创建默认的 AI 代理账号
|
||
|
|
"""
|
||
|
|
|
||
|
|
import os
|
||
|
|
import sys
|
||
|
|
import django
|
||
|
|
|
||
|
|
# 设置 Django 环境
|
||
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'city_manual.settings')
|
||
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
|
django.setup()
|
||
|
|
|
||
|
|
from agents.models import AIAgent
|
||
|
|
|
||
|
|
def create_default_agents():
|
||
|
|
"""创建默认的 AI 代理"""
|
||
|
|
|
||
|
|
agents = [
|
||
|
|
{
|
||
|
|
'agent_id': 'content-moderator-ai',
|
||
|
|
'name': '内容审核 AI',
|
||
|
|
'description': '负责审核用户提交的文章和服务内容',
|
||
|
|
'permissions': ['read', 'review', 'approve', 'write'],
|
||
|
|
'rate_limit': 1000,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
'agent_id': 'content-generator-ai',
|
||
|
|
'name': '内容生成 AI',
|
||
|
|
'description': '自动生成城市介绍、旅游攻略等内容',
|
||
|
|
'permissions': ['read', 'write'],
|
||
|
|
'rate_limit': 100,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
'agent_id': 'service-curator-ai',
|
||
|
|
'name': '服务推荐 AI',
|
||
|
|
'description': '自动发现和推荐本地特色服务',
|
||
|
|
'permissions': ['read', 'write'],
|
||
|
|
'rate_limit': 100,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
'agent_id': 'analytics-ai',
|
||
|
|
'name': '数据分析 AI',
|
||
|
|
'description': '分析用户行为和平台数据',
|
||
|
|
'permissions': ['read', 'analytics'],
|
||
|
|
'rate_limit': 500,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
'agent_id': 'admin-ai',
|
||
|
|
'name': '管理员 AI',
|
||
|
|
'description': '全自动管理员,拥有所有权限',
|
||
|
|
'permissions': ['read', 'write', 'review', 'delete', 'batch', 'analytics'],
|
||
|
|
'rate_limit': 10000,
|
||
|
|
},
|
||
|
|
]
|
||
|
|
|
||
|
|
import uuid
|
||
|
|
|
||
|
|
for agent_data in agents:
|
||
|
|
agent, created = AIAgent.objects.get_or_create(
|
||
|
|
agent_id=agent_data['agent_id'],
|
||
|
|
defaults={
|
||
|
|
'name': agent_data['name'],
|
||
|
|
'description': agent_data['description'],
|
||
|
|
'secret_key': uuid.uuid4().hex,
|
||
|
|
'permissions': agent_data['permissions'],
|
||
|
|
'rate_limit': agent_data['rate_limit'],
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
if created:
|
||
|
|
print(f"✅ 创建 AI 代理:{agent.name} ({agent.agent_id})")
|
||
|
|
print(f" 密钥:{agent.secret_key}")
|
||
|
|
print(f" 权限:{', '.join(agent.permissions)}")
|
||
|
|
print()
|
||
|
|
else:
|
||
|
|
print(f"⚠️ AI 代理已存在:{agent.name}")
|
||
|
|
print(f" 密钥:{agent.secret_key}")
|
||
|
|
print()
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
print("=" * 60)
|
||
|
|
print("🤖 初始化 AI 代理系统")
|
||
|
|
print("=" * 60)
|
||
|
|
print()
|
||
|
|
|
||
|
|
create_default_agents()
|
||
|
|
|
||
|
|
print("=" * 60)
|
||
|
|
print("✅ AI 代理初始化完成!")
|
||
|
|
print()
|
||
|
|
print("⚠️ 请妥善保管密钥,用于 AI 代理认证")
|
||
|
|
print("=" * 60)
|